Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(seed): seed only js files #186

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
})
})