Skip to content

Commit

Permalink
fix vanilla-esm example + snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Nov 6, 2023
1 parent 991ea48 commit d046d56
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { promises as fs } from 'fs';

/** @type {typeof import('../migrate.mjs').migrator['_types']['migration']} */
exports.up = async ({ context }) => {
export const up = async ({ context }) => {
await fs.mkdir(context.directory, { recursive: true });
await fs.writeFile(context.directory + '/users.json', JSON.stringify([], null, 2));
};

/** @type {typeof import('../migrate.mjs').migrator['_types']['migration']} */
exports.down = async ({ context }) => {
export const down = async ({ context }) => {
await fs.unlink(context.directory + '/users.json');
};
65 changes: 65 additions & 0 deletions test/__snapshots__/examples.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`example 0.5-vanilla-esm 1`] = `
"\`node migrate.mjs --help\` output:
...
\`node migrate.mjs up\` output:
{ event: 'migrating', name: '<<timestamp>>.users-table.mjs' }
{
event: 'migrated',
name: '<<timestamp>>.users-table.mjs',
durationSeconds: ???
}
{ event: 'up', message: 'applied 1 migrations.' }
\`node migrate.mjs down\` output:
{ event: 'reverting', name: '<<timestamp>>.users-table.mjs' }
{
event: 'reverted',
name: '<<timestamp>>.users-table.mjs',
durationSeconds: ???
}
{ event: 'down', message: 'reverted 1 migrations.' }
\`node migrate.mjs create --name new-migration.js\` output:
{
event: 'created',
path: '<<cwd>>/examples/0.5-vanilla-esm/migrations/<<timestamp>>.new-migration.js'
}
\`node migrate.mjs up\` output:
{ event: 'migrating', name: '<<timestamp>>.users-table.mjs' }
{
event: 'migrated',
name: '<<timestamp>>.users-table.mjs',
durationSeconds: ???
}
{ event: 'migrating', name: '<<timestamp>>.new-migration.js' }
{
event: 'migrated',
name: '<<timestamp>>.new-migration.js',
durationSeconds: ???
}
{ event: 'up', message: 'applied 2 migrations.' }
\`node migrate.mjs down --to 0\` output:
{ event: 'reverting', name: '<<timestamp>>.new-migration.js' }
{
event: 'reverted',
name: '<<timestamp>>.new-migration.js',
durationSeconds: ???
}
{ event: 'reverting', name: '<<timestamp>>.users-table.mjs' }
{
event: 'reverted',
name: '<<timestamp>>.users-table.mjs',
durationSeconds: ???
}
{ event: 'down', message: 'reverted 2 migrations.' }"
`;
exports[`example 0-vanilla 1`] = `
"\`node migrate --help\` output:
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('create migration file', () => {
`);

await expect(runCLI(['create', '--name', 'm4.txt'])).rejects.toThrowErrorMatchingInlineSnapshot(
`"Extension .txt not allowed. Allowed extensions are .js, .cjs, .mjs, .ts, .cts, .mts, .sql. See help for --allow-extension to avoid this error."`
'"Extension .txt not allowed. Allowed extensions are .js, .cjs, .mjs, .ts, .cts, .mts, .sql. See help for --allow-extension to avoid this error."'
);

await expect(runCLI(['create', '--name', 'm4.txt', '--allow-extension', '.txt'])).rejects.toThrow(
Expand Down
6 changes: 5 additions & 1 deletion test/examples.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as fs from 'fs';
import * as path from 'path';
import stripAnsi from 'strip-ansi';
import execa from 'execa';
import { test, expect } from 'vitest';
import { test, expect, beforeAll } from 'vitest';

beforeAll(async () => {
await execa('npm', ['run', 'compile']);
});

const examplesDir = path.join(__dirname, '../examples');
const examples = fs.readdirSync(examplesDir).filter(ex => /^\d/.exec(ex));
Expand Down

0 comments on commit d046d56

Please sign in to comment.