From 049641171d5352341cbf260925c4530eec90e44e Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Sat, 7 Oct 2017 16:19:34 +0200 Subject: [PATCH] fix(seed): seed only js files (#186) --- commands/Seed.js | 4 +-- test/functional/seed-database.spec.js | 41 ++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/commands/Seed.js b/commands/Seed.js index 33ad34a9..bf75f65a 100644 --- a/commands/Seed.js +++ b/commands/Seed.js @@ -44,11 +44,11 @@ class SeedDatabase extends Command { _getSeedFiles (selectedFiles) { return requireAll({ dirname: this._seedsPath, - filters: /(.*)\.js$/, filter: (fileName) => { - if (!selectedFiles) { + if (!selectedFiles && fileName.match(/(.*)\.js$/)) { return fileName } + return _.find(selectedFiles, (file) => file.trim().endsWith(fileName)) } }) diff --git a/test/functional/seed-database.spec.js b/test/functional/seed-database.spec.js index de2b3782..61cde11f 100644 --- a/test/functional/seed-database.spec.js +++ b/test/functional/seed-database.spec.js @@ -49,6 +49,14 @@ test.group('Seed Database', (group) => { group.afterEach(async () => { ace.commands = {} + + try { + await fs.remove(path.join(__dirname, 'database')) + } catch (error) { + if (process.platform !== 'win32' || error.code !== 'EBUSY') { + throw error + } + } }) group.after(async () => { @@ -57,7 +65,6 @@ test.group('Seed Database', (group) => { try { await fs.remove(path.join(__dirname, '../unit/tmp')) - await fs.remove(path.join(__dirname, 'database')) } catch (error) { if (process.platform !== 'win32' || error.code !== 'EBUSY') { throw error @@ -134,4 +141,36 @@ test.group('Seed Database', (group) => { await ace.call('seed', {}, { files: 'foo.js' }) assert.deepEqual(global.stack, ['foo']) }) + + test('run only js files', async (assert) => { + ace.addCommand(Seed) + const g = global || GLOBAL + g.stack = [] + + await fs.outputFile(path.join(__dirname, 'database/seeds/bar.js'), ` + class Seed { + run () { + return new Promise((resolve) => { + setTimeout(() => { + (global || GLOBAL).stack.push('bar') + resolve() + }, 10) + }) + } + } + module.exports = Seed + `) + + await fs.outputFile(path.join(__dirname, 'database/seeds/.bar.js.swp'), ` + class Seed { + run () { + (global || GLOBAL).stack.push('foo') + } + } + module.exports = Seed + `) + + await ace.call('seed') + assert.deepEqual(global.stack, ['bar']) + }) })