Skip to content

Commit

Permalink
Make test more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Jan 23, 2024
1 parent 5567dda commit 549528a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions __tests__/__snapshots__/migrate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

exports[`handles errors during migration gracefully 1`] = `[error: division by zero]`;

exports[`handles errors during migration gracefully 2`] = `
"
🛑 Error occurred whilst processing migration
error: division by zero
at ~/node_modules/pg/lib/client.js:[LINE]:[COL]
at processTicksAndRejections (node:internal/process/task_queues:[LINE]:[COL])
at runQueryWithErrorInstrumentation (~/src/instrumentation.ts:[LINE]:[COL])
at ~/src/migration.ts:[LINE]:[COL]
at withAdvisoryLock (~/src/pgReal.ts:[LINE]:[COL])
at runCommittedMigration (~/src/migration.ts:[LINE]:[COL])
at ~/src/commands/migrate.ts:[LINE]:[COL]
at withAdvisoryLock (~/src/pgReal.ts:[LINE]:[COL])
at ~/src/commands/migrate.ts:[LINE]:[COL]
at withClient (~/src/pgReal.ts:[LINE]:[COL])
at _migrate (~/src/commands/migrate.ts:[LINE]:[COL])
at Object.<anonymous> (~/__tests__/migrate.test.ts:[LINE]:[COL])
Severity: ERROR
Code: 22012
,[object Object]"
`;
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`] = `
Expand Down
6 changes: 5 additions & 1 deletion __tests__/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,9 @@ comment on table frogs is 'Ribbit';
logDbError(parsedSettings, err);
expect(mock).toHaveBeenCalledTimes(1);
const call = mock.mock.calls[0];
expect(call).toMatchSnapshot();
expect(
String(call)
.replaceAll(process.cwd(), "~")
.replace(/:[0-9]+:[0-9]+($|\))/gm, ":[LINE]:[COL]$1"),
).toMatchSnapshot();
});

0 comments on commit 549528a

Please sign in to comment.