Skip to content

Commit 918888b

Browse files
committed
Fix tests
1 parent da1ed44 commit 918888b

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

__tests__/helpers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,16 @@ export const makeMigrations = (commitMessage?: string) => {
266266
commitMessage ? `\n--! Message: ${commitMessage}` : ``
267267
}\n\n${MIGRATION_NOTRX_TEXT.trim()}\n`;
268268

269+
const MIGRATION_INCLUDED_FIXTURE = "select 42;\n";
270+
269271
const MIGRATION_INCLUDE_TEXT = `--!include foo.sql`;
270-
const MIGRATION_INCLUDE_COMPILED = `${MIGRATION_INCLUDE_TEXT}\n${MIGRATION_1_TEXT}\n${MIGRATION_INCLUDE_TEXT}`;
272+
const MIGRATION_INCLUDE_COMPILED = `--! Included foo.sql\n${MIGRATION_INCLUDED_FIXTURE.trim()}\n--! EndIncluded foo.sql\n`;
271273
const MIGRATION_INCLUDE_HASH = createHash("sha1")
272274
.update(`${MIGRATION_INCLUDE_COMPILED.trim()}` + "\n")
273275
.digest("hex");
274276
const MIGRATION_INCLUDE_COMMITTED = `--! Previous: -\n--! Hash: sha1:${MIGRATION_INCLUDE_HASH}${
275277
commitMessage ? `\n--! Message: ${commitMessage}` : ``
276-
}\n\n${MIGRATION_INCLUDE_COMPILED}\n`;
278+
}\n\n${MIGRATION_INCLUDE_COMPILED.trim()}\n`;
277279

278280
const MIGRATION_MULTIFILE_FILES = {
279281
"migrations/links/two.sql": "select 2;",
@@ -320,6 +322,7 @@ select 3;
320322
MIGRATION_INCLUDE_TEXT,
321323
MIGRATION_INCLUDE_HASH,
322324
MIGRATION_INCLUDE_COMMITTED,
325+
MIGRATION_INCLUDED_FIXTURE,
323326
MIGRATION_MULTIFILE_TEXT,
324327
MIGRATION_MULTIFILE_HASH,
325328
MIGRATION_MULTIFILE_COMMITTED,

__tests__/uncommit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe.each([[undefined], ["My Commit Message"]])(
5959
MIGRATION_INCLUDE_COMMITTED,
6060
MIGRATION_MULTIFILE_COMMITTED,
6161
MIGRATION_MULTIFILE_FILES,
62+
MIGRATION_INCLUDED_FIXTURE,
6263
} = makeMigrations(commitMessage);
6364

6465
it("rolls back migration", async () => {
@@ -95,7 +96,7 @@ describe.each([[undefined], ["My Commit Message"]])(
9596
[`migrations/committed/000001${commitMessageSlug}.sql`]:
9697
MIGRATION_INCLUDE_COMMITTED,
9798
"migrations/current.sql": "-- JUST A COMMENT\n",
98-
"migrations/fixtures/foo.sql": MIGRATION_1_TEXT,
99+
"migrations/fixtures/foo.sql": MIGRATION_INCLUDED_FIXTURE,
99100
});
100101
await migrate(settings);
101102
await uncommit(settings);

src/commands/uncommit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export async function _uncommit(parsedSettings: ParsedSettings): Promise<void> {
4242
const contents = await fsp.readFile(lastMigrationFilepath, "utf8");
4343
const { headers, body } = parseMigrationText(lastMigrationFilepath, contents);
4444

45-
// Replace included migrations with their `--! include` equivalent
45+
// Replace included migrations with their `--!include` equivalent
4646
const decompiledBody = body.replace(
4747
/^--! Included (?<filename>\S+)$[\s\S]*?^--! EndIncluded \k<filename>$/gm,
48-
(_, filename) => `--! include ${filename}`,
48+
(_, filename) => `--!include ${filename}`,
4949
);
5050

5151
// Drop Hash, Previous and AllowInvalidHash from headers; then write out

0 commit comments

Comments
 (0)