-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathwatch.test.ts
More file actions
124 lines (111 loc) · 2.84 KB
/
watch.test.ts
File metadata and controls
124 lines (111 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
jest.mock("child_process");
import "./helpers"; // Has side-effects; must come first
import * as mockFs from "mock-fs";
import { _makeCurrentMigrationRunner, _watch } from "../src/commands/watch";
import { parseSettings } from "../src/settings";
import { makeMigrations } from "./helpers";
import {
makeActionSpies,
mockCurrentSqlContentOnce,
resetDb,
setup,
TEST_DATABASE_URL,
} from "./helpers";
beforeEach(resetDb);
const { MIGRATION_MULTIFILE_FILES } = makeMigrations();
it("doesn't run current.sql if it's already up to date", async () => {
const { settings, getActionCalls } = makeActionSpies();
const parsedSettings = await parseSettings({
connectionString: TEST_DATABASE_URL,
...settings,
});
await setup(parsedSettings);
const migrationRunner = _makeCurrentMigrationRunner(
parsedSettings,
false,
false,
false,
);
expect(getActionCalls()).toEqual([]);
mockCurrentSqlContentOnce(
parsedSettings,
`\
-- First migration
SELECT ':DATABASE_NAME';
`,
);
await migrationRunner();
expect(getActionCalls()).toEqual(["beforeCurrent", "afterCurrent"]);
// This one is identical
mockCurrentSqlContentOnce(
parsedSettings,
`\
-- Second migration; identical except for this comment
SELECT ':DATABASE_NAME';
`,
);
await migrationRunner();
expect(getActionCalls()).toEqual(["beforeCurrent", "afterCurrent"]);
mockCurrentSqlContentOnce(
parsedSettings,
`\
-- Third migration; DIFFERENT!
SELECT ':DATABASE_NAME', 2 * 2;
`,
);
await migrationRunner();
expect(getActionCalls()).toEqual([
"beforeCurrent",
"afterCurrent",
"beforeCurrent",
"afterCurrent",
]);
});
it("watches symlinked files", async () => {
const { settings, getActionCalls } = makeActionSpies();
const parsedSettings = await parseSettings({
connectionString: TEST_DATABASE_URL,
...settings,
});
await setup(parsedSettings);
const migrationRunner = _makeCurrentMigrationRunner(
parsedSettings,
false,
false,
false,
);
expect(getActionCalls()).toEqual([]);
mockFs({
...MIGRATION_MULTIFILE_FILES,
"migrations/links/two.sql": `\
-- First migration
SELECT ':DATABASE_NAME';
`,
});
await migrationRunner();
expect(getActionCalls()).toEqual(["beforeCurrent", "afterCurrent"]);
// This one is identical
mockFs({
...MIGRATION_MULTIFILE_FILES,
"migrations/links/two.sql": `\
-- Second migration; identical except for this comment
SELECT ':DATABASE_NAME';
`,
});
await migrationRunner();
expect(getActionCalls()).toEqual(["beforeCurrent", "afterCurrent"]);
mockFs({
...MIGRATION_MULTIFILE_FILES,
"migrations/links/two.sql": `\
-- Third migration; DIFFERENT!
SELECT ':DATABASE_NAME', 2 * 2;
`,
});
await migrationRunner();
expect(getActionCalls()).toEqual([
"beforeCurrent",
"afterCurrent",
"beforeCurrent",
"afterCurrent",
]);
});