Skip to content

Commit

Permalink
Move to external snapshots due to bug with inline
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jan 18, 2024
1 parent 71f883b commit 9841561
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 90 deletions.
97 changes: 97 additions & 0 deletions __tests__/__snapshots__/migrate.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`refuses to run migration with invalid hash 1`] = `"Hash for 000002.sql does not match - sha1:cbed240dda7dfa510ff785783bbe6af7743b3a11 !== sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b; has the file been tampered with?"`;

exports[`runs migrations 1`] = `
[
{
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
{
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
]
`;

exports[`runs migrations 2`] = `
[
"foo",
]
`;

exports[`runs migrations 3`] = `
[
{
"typname": "user_role",
"value_count": "1",
},
]
`;

exports[`runs migrations 4`] = `
[
{
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
{
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
{
"filename": "000003.sql",
"hash": "sha1:2d248344ac299ebbad2aeba5bfec2ae3c3cb0a4f",
"previous_hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
},
]
`;

exports[`runs migrations 5`] = `
[
"foo",
]
`;

exports[`runs migrations 6`] = `
[
{
"typname": "user_role",
"value_count": "2",
},
]
`;

exports[`will run a migration with invalid hash if told to do so 1`] = `
[
{
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
{
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
{
"filename": "000003.sql",
"hash": "sha1:2d248344ac299ebbad2aeba5bfec2ae3c3cb0a4f",
"previous_hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
},
]
`;

exports[`will run a migration with invalid hash if told to do so 2`] = `
[
{
"typname": "user_role",
"value_count": "2",
},
]
`;
101 changes: 12 additions & 89 deletions __tests__/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,11 @@ it("runs migrations", async () => {
const { migrations, tables, enums } = await getStuff(parsedSettings);

expect(migrations).toHaveLength(2);
expect(migrations.map(({ date, ...rest }) => rest)).toMatchInlineSnapshot(`
Array [
Object {
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
Object {
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
]
`);
expect(migrations.map(({ date, ...rest }) => rest)).toMatchSnapshot();
expect(tables).toHaveLength(1);
expect(tables.map((t) => t.relname)).toMatchInlineSnapshot(`
Array [
"foo",
]
`);
expect(tables.map((t) => t.relname)).toMatchSnapshot();
expect(enums).toHaveLength(1);
expect(enums).toMatchInlineSnapshot(`
Array [
Object {
"typname": "user_role",
"value_count": "1",
},
]
`);
expect(enums).toMatchSnapshot();
}

mockFs({
Expand All @@ -113,40 +89,13 @@ Array [
const { migrations, tables, enums } = await getStuff(parsedSettings);

expect(migrations).toHaveLength(3);
expect(migrations.map(({ date, ...rest }) => rest)).toMatchInlineSnapshot(`
Array [
Object {
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
Object {
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
Object {
"filename": "000003.sql",
"hash": "sha1:2d248344ac299ebbad2aeba5bfec2ae3c3cb0a4f",
"previous_hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
},
]
`);
const mappedMigrations = migrations.map(({ date, ...rest }) => rest);
expect(mappedMigrations).toMatchSnapshot();
expect(tables).toHaveLength(1);
expect(tables.map((t) => t.relname)).toMatchInlineSnapshot(`
Array [
"foo",
]
`);
const mappedTables = tables.map((t) => t.relname);
expect(mappedTables).toMatchSnapshot();
expect(enums).toHaveLength(1);
expect(enums).toMatchInlineSnapshot(`
Array [
Object {
"typname": "user_role",
"value_count": "2",
},
]
`);
expect(enums).toMatchSnapshot();
}
});

Expand All @@ -160,9 +109,7 @@ it("refuses to run migration with invalid hash", async () => {
"migrations/current.sql": "",
});

await expect(migrate(settings)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Hash for 000002.sql does not match - sha1:cbed240dda7dfa510ff785783bbe6af7743b3a11 !== sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b; has the file been tampered with?"`,
);
await expect(migrate(settings)).rejects.toThrowErrorMatchingSnapshot();
});

it("will run a migration with invalid hash if told to do so", async () => {
Expand All @@ -184,33 +131,9 @@ it("will run a migration with invalid hash if told to do so", async () => {
const { migrations, enums } = await getStuff(parsedSettings);

expect(migrations).toHaveLength(3);
expect(migrations.map(({ date, ...rest }) => rest)).toMatchInlineSnapshot(`
Array [
Object {
"filename": "000001.sql",
"hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
"previous_hash": null,
},
Object {
"filename": "000002.sql",
"hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
"previous_hash": "sha1:e00ec93314a423ee5cc68d1182ad52f16442d7df",
},
Object {
"filename": "000003.sql",
"hash": "sha1:2d248344ac299ebbad2aeba5bfec2ae3c3cb0a4f",
"previous_hash": "sha1:bddc1ead3310dc1c42cdc7f63537ebdff2e9fd7b",
},
]
`);
const mappedMigrations = migrations.map(({ date, ...rest }) => rest);
expect(mappedMigrations).toMatchSnapshot();
expect(enums).toHaveLength(1);
expect(enums).toMatchInlineSnapshot(`
Array [
Object {
"typname": "user_role",
"value_count": "2",
},
]
`);
expect(enums).toMatchSnapshot();
}
});
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"noUnusedParameters": false,
"noUnusedLocals": false,
"preserveWatchOutput": true,
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["**/__mocks__/*"],
"exclude": ["**/__mocks__/*"]
}

0 comments on commit 9841561

Please sign in to comment.