Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations up/down commands: filename parameter #3416

Merged
merged 7 commits into from Oct 6, 2019

throw an error tests refactoring

  • Loading branch information
ivanovych666 committed Aug 27, 2019
commit 4c1135df06f4c814e55bba593ddb0306fd20560d
@@ -9,7 +9,10 @@ const rimrafSync = require('rimraf').sync;
const path = require('path');
const sqlite3 = require('sqlite3');
const { assert } = require('chai');
const { assertExec } = require('../../jake-util/helpers/migration-test-helper');
const {
assertExec,
assertExecError,
} = require('../../jake-util/helpers/migration-test-helper');
const knexfile = require('../../jake-util/knexfile/knexfile.js');

const KNEX = path.normalize(__dirname + '/../../../bin/cli.js');
@@ -462,17 +465,14 @@ test('migrate:up <name> throw an error', (temp) => {
const migrationsPath = `${temp}/migrations`;
const migrationFile1 = '001_one.js';

return assertExec(
return assertExecError(
`node ${KNEX} migrate:up ${migrationFile1} \
--client=sqlite3 \
--connection=${temp}/db \
--migrations-directory=${migrationsPath}`,
'run_migration_001'
).catch((error) => {
assert.include(
error.toString(),
`Migration "${migrationFile1}" not found.`
);
).catch(({ stderr }) => {
assert.include(stderr, `Migration "${migrationFile1}" not found.`);
});
});

@@ -629,17 +629,14 @@ test('migrate:down <name> throw an error', (temp) => {
const migrationsPath = `${temp}/migrations`;
const migrationFile1 = '001_one.js';

return assertExec(
return assertExecError(
`node ${KNEX} migrate:down ${migrationFile1} \

This comment has been minimized.

Copy link
@kibertoad

kibertoad Aug 27, 2019

Collaborator

assertExecError is a better way to test negative scenarios

This comment has been minimized.

Copy link
@ivanovych666

ivanovych666 Aug 27, 2019

Author Contributor

Thank you, you are right. Done.

--client=sqlite3 \
--connection=${temp}/db \
--migrations-directory=${migrationsPath}`,
'undo_migration_001'
).catch((error) => {
assert.include(
error.toString(),
`Migration "${migrationFile1}" was not run.`
);
).catch(({ stderr }) => {
assert.include(stderr, `Migration "${migrationFile1}" was not run.`);
});
});

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.