Skip to content

Commit

Permalink
Added test case for the ordering warning
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Oct 3, 2017
1 parent 237785e commit fb4b993
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.migrate
*.db
migrations/
test/fixtures/tmp
57 changes: 57 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* global describe, it, beforeEach */
const path = require('path')
const assert = require('assert')
const rimraf = require('rimraf')
const mkdirp = require('mkdirp')
const run = require('./util/run')

// Paths
const TMP_DIR = path.join(__dirname, 'fixtures', 'tmp')

function reset () {
rimraf.sync(TMP_DIR)
mkdirp.sync(TMP_DIR)
}

describe('integration tests', function () {
beforeEach(reset)

it('should warn when the migrations are run out of order', function (done) {
run.init(TMP_DIR, [], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

run.create(TMP_DIR, ['1-one', '-d', 'W'], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

run.create(TMP_DIR, ['3-three', '-d', 'W'], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

run.up(TMP_DIR, [], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

run.create(TMP_DIR, ['2-two', '-d', 'W'], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

run.up(TMP_DIR, [], function (err, out, code) {
assert(!err)
assert.equal(code, 0)

// A warning should log, and the process not exit with 0
// because migration 2 should come before migration 3,
// but migration 3 was already run from the previous
// state
assert(out.indexOf('warn') !== -1)
done()
})
})
})
})
})
})
})
})
13 changes: 9 additions & 4 deletions test/util/run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'
const path = require('path')
const spawn = require('child_process').spawn

module.exports = function run (cmd, dir, args, done) {
var run = module.exports = function run (cmd, dir, args, done) {
var p = spawn(cmd, ['-c', dir, ...args])
var out = ''
p.stdout.on('data', function (d) {
Expand All @@ -12,9 +13,13 @@ module.exports = function run (cmd, dir, args, done) {
})
p.on('error', done)
p.on('close', function (code) {
if (code !== 0) {
console.error(out)
}
done(null, out, code)
})
}

// Run specific commands
module.exports.up = run.bind(null, path.join(__dirname, '..', '..', 'bin', 'migrate-up'))
module.exports.down = run.bind(null, path.join(__dirname, '..', '..', 'bin', 'migrate-down'))
module.exports.create = run.bind(null, path.join(__dirname, '..', '..', 'bin', 'migrate-create'))
module.exports.init = run.bind(null, path.join(__dirname, '..', '..', 'bin', 'migrate-init'))
module.exports.list = run.bind(null, path.join(__dirname, '..', '..', 'bin', 'migrate-list'))

0 comments on commit fb4b993

Please sign in to comment.