2020-01-28 02:28:40 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const { execCommand } = require('cli-testlab');
|
|
|
|
|
|
|
|
const KNEX = path.normalize(__dirname + '/../../bin/cli.js');
|
|
|
|
|
|
|
|
describe('seed:run', () => {
|
|
|
|
before(() => {
|
|
|
|
process.env.KNEX_PATH = '../knex.js';
|
|
|
|
});
|
|
|
|
|
|
|
|
it('prints non verbose logs', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js`,
|
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 2 seed files',
|
|
|
|
notExpectedOutput: ['first.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-08-10 15:10:37 +02:00
|
|
|
it('find files not recursively by default', () => {
|
2020-08-08 14:21:43 +02:00
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-directories.js`,
|
2020-08-10 15:10:37 +02:00
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 2 seed files',
|
|
|
|
notExpectedOutput: ['before-second.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('find files recursively if option is set', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-directories-recursive.js`,
|
2020-08-08 14:21:43 +02:00
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 3 seed files',
|
|
|
|
notExpectedOutput: ['first.js', 'second.js', 'before-second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-08-10 15:10:37 +02:00
|
|
|
it('find files not recursively by default and print verbose logs', () => {
|
2020-08-08 14:21:43 +02:00
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-directories.js --verbose`,
|
2020-08-10 15:10:37 +02:00
|
|
|
{
|
|
|
|
expectedOutput: ['Ran 2 seed files', 'before-second.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('find recursively files if option recursive is set and print verbose logs', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-directories-recursive.js --verbose`,
|
2020-08-08 14:21:43 +02:00
|
|
|
{
|
|
|
|
expectedOutput: [
|
|
|
|
'Ran 3 seed files',
|
|
|
|
'first.js',
|
|
|
|
'second.js',
|
|
|
|
'before-second.js',
|
|
|
|
],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-03-24 12:07:05 -04:00
|
|
|
it('supports async configuration', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-async.js`,
|
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 2 seed files',
|
|
|
|
notExpectedOutput: ['first.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-01-28 02:28:40 +01:00
|
|
|
it('prints verbose logs', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js --verbose`,
|
|
|
|
{
|
|
|
|
expectedOutput: ['Ran 2 seed files', 'first.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('runs specific file', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js --specific=second.js`,
|
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 1 seed files',
|
|
|
|
notExpectedOutput: ['first.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-09-04 08:48:18 +02:00
|
|
|
it('handles non existing specific seed file errors correctly', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js --specific=intentionally-non-existing-404-seed.js`,
|
|
|
|
{
|
|
|
|
expectedErrorMessage: ['Invalid argument provided', 'does not exist'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-08-08 14:21:43 +02:00
|
|
|
it('runs specific file in a recursive folder', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile-directories.js --specific=second.js`,
|
|
|
|
{
|
|
|
|
expectedOutput: 'Ran 1 seed files',
|
|
|
|
notExpectedOutput: ['first.js', 'second.js'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-01-28 02:28:40 +01:00
|
|
|
it('handles seeding errors correctly', () => {
|
|
|
|
return execCommand(
|
|
|
|
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-error-knexfile.js`,
|
|
|
|
{
|
|
|
|
expectedErrorMessage: ['Error while executing', 'seeds.js', 'Boom'],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2020-08-15 16:54:43 +02:00
|
|
|
});
|