mirror of
https://github.com/knex/knex.git
synced 2025-06-26 22:00:25 +00:00
Display name of a failed seed (#2973)
This commit is contained in:
parent
0b26935273
commit
9daf7f3d09
12
package.json
12
package.json
@ -8,7 +8,7 @@
|
||||
"node": ">=6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/polyfill": "^7.0.0",
|
||||
"@babel/polyfill": "^7.2.5",
|
||||
"@types/bluebird": "^3.5.25",
|
||||
"bluebird": "^3.5.3",
|
||||
"chalk": "2.4.1",
|
||||
@ -24,7 +24,7 @@
|
||||
"tarn": "^1.1.4",
|
||||
"tildify": "1.2.0",
|
||||
"uuid": "^3.3.2",
|
||||
"v8flags": "^3.1.1"
|
||||
"v8flags": "^3.1.2"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,json}": [
|
||||
@ -33,9 +33,9 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.0",
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "^7.2.2",
|
||||
"@babel/preset-env": "^7.2.0",
|
||||
"@babel/preset-env": "^7.2.3",
|
||||
"@types/node": "*",
|
||||
"JSONStream": "^1.3.5",
|
||||
"async": "^2.6.1",
|
||||
@ -124,9 +124,9 @@
|
||||
"web": "https://github.com/tgriesser"
|
||||
},
|
||||
"browser": {
|
||||
"./lib/migrate/index.js": "./lib/util/noop.js",
|
||||
"./lib/migrate/Migrator.js": "./lib/util/noop.js",
|
||||
"./lib/bin/cli.js": "./lib/util/noop.js",
|
||||
"./lib/seed/index.js": "./lib/util/noop.js",
|
||||
"./lib/seed/Seeder.js": "./lib/util/noop.js",
|
||||
"mssql": false,
|
||||
"mssql/lib/base": false,
|
||||
"tedious": false,
|
||||
|
@ -128,6 +128,20 @@ Seeder.prototype._waterfallBatch = function(seeds) {
|
||||
.then(() => seed.seed(knex, Promise))
|
||||
.then(() => {
|
||||
log.push(name);
|
||||
})
|
||||
.catch((originalError) => {
|
||||
const error = new Error(
|
||||
`Error while executing "${name}" seed: ${originalError.message}`
|
||||
);
|
||||
error.original = originalError;
|
||||
error.stack =
|
||||
error.stack
|
||||
.split('\n')
|
||||
.slice(0, 2)
|
||||
.join('\n') +
|
||||
'\n' +
|
||||
originalError.stack;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import Migrator from '../migrate/Migrator';
|
||||
import Seeder from '../seed';
|
||||
import Seeder from '../seed/Seeder';
|
||||
import FunctionHelper from '../functionhelper';
|
||||
import QueryInterface from '../query/methods';
|
||||
import { assign } from 'lodash';
|
||||
|
9
test/jake-util/seeds-error-knexfile.js
Normal file
9
test/jake-util/seeds-error-knexfile.js
Normal file
@ -0,0 +1,9 @@
|
||||
module.exports = {
|
||||
client: 'sqlite3',
|
||||
connection: {
|
||||
filename: __dirname + '/../test.sqlite3',
|
||||
},
|
||||
seeds: {
|
||||
directory: __dirname + '/seeds-error',
|
||||
},
|
||||
};
|
3
test/jake-util/seeds-error/seeds.js
Normal file
3
test/jake-util/seeds-error/seeds.js
Normal file
@ -0,0 +1,3 @@
|
||||
exports.seed = (knex, Promise) => {
|
||||
throw new Error('Boom');
|
||||
};
|
@ -5,10 +5,12 @@
|
||||
|
||||
const knexfileTests = require('./jakelib/knexfile-test').taskList;
|
||||
const migrateTests = require('./jakelib/migrate-test').taskList;
|
||||
const seedTests = require('./jakelib/seed-test').taskList;
|
||||
|
||||
const tests = [
|
||||
...knexfileTests,
|
||||
...migrateTests,
|
||||
...seedTests
|
||||
];
|
||||
|
||||
task('default', tests, () => {
|
||||
|
29
test/jake/jakelib/seed-test.js
Normal file
29
test/jake/jakelib/seed-test.js
Normal file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env jake
|
||||
'use strict';
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
const path = require('path');
|
||||
const {
|
||||
assertExecError,
|
||||
test,
|
||||
} = require('../../jake-util/helpers/migration-test-helper');
|
||||
const { assert } = require('chai');
|
||||
|
||||
const KNEX = path.normalize(__dirname + '/../../../bin/cli.js');
|
||||
|
||||
const taskList = [];
|
||||
/* * * TESTS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
test(taskList, 'Handles seeding errors correctly', (temp) => {
|
||||
return assertExecError(
|
||||
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-error-knexfile.js --knexpath=../knex.js`
|
||||
).then((err) => {
|
||||
assert.include(err, 'Error while executing');
|
||||
assert.include(err, 'seeds.js');
|
||||
assert.include(err, 'Boom');
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
taskList,
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const tape = require('tape');
|
||||
const Seed = require('../../lib/seed/index.js');
|
||||
const Seed = require('../../lib/seed/Seeder');
|
||||
|
||||
tape('checks config.seeds for seed config', function(t) {
|
||||
t.plan(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user