2017-07-24 14:19:17 +03:00
|
|
|
/*eslint no-var:0, indent:0, max-len:0 */
|
|
|
|
'use strict';
|
|
|
|
|
2020-03-08 19:48:23 -04:00
|
|
|
const { expect } = require('chai');
|
|
|
|
|
2019-06-17 02:14:17 +02:00
|
|
|
const mockFs = require('mock-fs');
|
|
|
|
const knex = require('../../../knex');
|
2017-07-24 14:19:17 +03:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('Seeder.loadExtensions', function () {
|
2019-06-17 02:14:17 +02:00
|
|
|
const config = {
|
2019-06-03 18:10:23 +02:00
|
|
|
client: 'postgres',
|
2017-07-24 14:19:17 +03:00
|
|
|
connection: {
|
|
|
|
user: 'postgres',
|
|
|
|
password: '',
|
|
|
|
host: '127.0.0.1',
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
2017-07-24 14:19:17 +03:00
|
|
|
},
|
|
|
|
seeds: {
|
2018-07-09 08:10:34 -04:00
|
|
|
directory: 'test/integration/seed/seeds',
|
|
|
|
},
|
2017-07-24 14:19:17 +03:00
|
|
|
};
|
2019-06-17 02:14:17 +02:00
|
|
|
let seeder;
|
2017-07-24 14:19:17 +03:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
before(function () {
|
2017-07-24 14:19:17 +03:00
|
|
|
mockFs({
|
|
|
|
'test/integration/seed/seeds': {
|
|
|
|
'co-seed.co': 'co seed content',
|
|
|
|
'coffee-seed.coffee': 'coffee seed content',
|
|
|
|
'eg-seed.eg': 'eg seed content',
|
|
|
|
'iced-seed.iced': 'iced seed content',
|
|
|
|
'js-seed.js': 'js seed content',
|
|
|
|
'litcoffee-seed.litcoffee': 'litcoffee seed content',
|
|
|
|
'ls-seed.ls': 'ls seed content',
|
|
|
|
'ts-seed.ts': 'ts seed content',
|
2018-07-09 08:10:34 -04:00
|
|
|
'useless.txt': 'i am not a seed',
|
2017-07-24 14:19:17 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
after(function () {
|
2017-07-24 14:19:17 +03:00
|
|
|
mockFs.restore();
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
beforeEach(function () {
|
2017-07-24 14:19:17 +03:00
|
|
|
seeder = knex(config).seed;
|
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('should include all supported extensions by default', function () {
|
|
|
|
return seeder._listAll().then(function (list) {
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(list).to.eql([
|
|
|
|
'co-seed.co',
|
|
|
|
'coffee-seed.coffee',
|
|
|
|
'eg-seed.eg',
|
|
|
|
'iced-seed.iced',
|
|
|
|
'js-seed.js',
|
|
|
|
'litcoffee-seed.litcoffee',
|
|
|
|
'ls-seed.ls',
|
|
|
|
'ts-seed.ts',
|
|
|
|
]);
|
|
|
|
});
|
2017-07-24 14:19:17 +03:00
|
|
|
});
|
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
it('should list only files with specified extensions', function () {
|
2018-07-09 08:10:34 -04:00
|
|
|
return seeder
|
|
|
|
._listAll({ loadExtensions: ['.ts', '.js'] })
|
2020-04-19 00:40:23 +02:00
|
|
|
.then(function (list) {
|
2018-07-09 08:10:34 -04:00
|
|
|
expect(list).to.eql(['js-seed.js', 'ts-seed.ts']);
|
|
|
|
});
|
2017-07-24 14:19:17 +03:00
|
|
|
});
|
|
|
|
});
|
2019-06-03 18:10:23 +02:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
describe('Seeder._waterfallBatch', function () {
|
2019-06-17 02:14:17 +02:00
|
|
|
const config = {
|
2019-06-03 18:10:23 +02:00
|
|
|
client: 'postgres',
|
|
|
|
connection: {
|
|
|
|
user: 'postgres',
|
|
|
|
password: '',
|
|
|
|
host: '127.0.0.1',
|
|
|
|
database: 'knex_test',
|
|
|
|
},
|
|
|
|
seeds: {
|
|
|
|
directory: 'test/unit/seed/test',
|
|
|
|
},
|
|
|
|
};
|
2019-06-17 02:14:17 +02:00
|
|
|
let seeder;
|
2019-06-03 18:10:23 +02:00
|
|
|
|
2020-04-19 00:40:23 +02:00
|
|
|
beforeEach(function () {
|
2019-06-03 18:10:23 +02:00
|
|
|
seeder = knex(config).seed;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error with correct file name', (done) => {
|
|
|
|
seeder._waterfallBatch(['1-first.js', '2-second.js']).catch((error) => {
|
|
|
|
expect(error.message).to.match(
|
2019-07-11 14:57:59 +02:00
|
|
|
/^Error while executing .*1-first.js" seed: throwing in first file$/
|
2019-06-03 18:10:23 +02:00
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|