Skip to content

Commit

Permalink
fix(seed): seed only js files (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz authored and thetutlage committed Oct 7, 2017
1 parent 0db2a23 commit 0496411
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
4 changes: 2 additions & 2 deletions commands/Seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})
Expand Down
41 changes: 40 additions & 1 deletion test/functional/seed-database.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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
Expand Down Expand Up @@ -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'])
})
})

0 comments on commit 0496411

Please sign in to comment.