Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

databaseMigrationLog.test.ts

43 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 databaseMigrationProgress,
5 DATABASE_MIGRATION_PROGRESS_MESSAGE as STEP,
6 DATABASE_MIGRATIONS_STARTED_MESSAGE as START,
7 DATABASE_MIGRATIONS_FINISHED_MESSAGE as FINISH,
8} from "./databaseMigrationLog.ts";
9​
10describe("databaseMigrationProgress", () => {
11 it.each([
12 ["", null],
13 [START, null],
14 [`${STEP} (2 of 7)\n progress: 2 of 7\n`, { current: 2, total: 7 }],
15 [`${STEP} (2 of 7`, null],
16 [`${STEP} (8 of 7)\n`, null],
17 [`${STEP} progress="1 of 7"\n${STEP} progress="2 of 7"`, { current: 2, total: 7 }],
18 [`${STEP} migration=<script>alert(1)</script> progress="2 of 7"`, { current: 2, total: 7 }],
19 [`{"message":"${STEP}","progress":"3 of 7"}`, { current: 3, total: 7 }],
20 [`${STEP} progress="2 of 7`, null],
21 [`${STEP} progress="0 of 7"`, null],
22 [`${STEP} progress="8 of 7"`, null],
23 [`${STEP} progress="1 of 99999999999999999999"`, null],
24 [`${STEP} progress="2 of 7"\n${FINISH}`, null],
25 [`${STEP} progress="2 of 7"\n${START}`, null],
26 [`${FINISH}\n${START}\n${STEP} progress="1 of 5"`, { current: 1, total: 5 }],
27 ])("reads the current complete progress from %s", (output, expected) => {
28 expect(databaseMigrationProgress(output)).toEqual(expected);
29 });
30​
31 it("keeps the last step until the next step is complete", () => {
32 const previous = { current: 2, total: 7 };
33 expect(databaseMigrationProgress(`${STEP} (3 of`, previous)).toEqual(previous);
34 expect(databaseMigrationProgress(`${STEP}\nunrelated progress="5 of 7"`, previous)).toEqual(
35 previous,
36 );
37 expect(databaseMigrationProgress(`${STEP} (3 of 7)`, previous)).toEqual({
38 current: 3,
39 total: 7,
40 });
41 expect(databaseMigrationProgress(START, previous)).toBeNull();
42 });
43});