Skip to content

Commit

Permalink
Merge dc7067a into 6dbd396
Browse files Browse the repository at this point in the history
  • Loading branch information
depfu[bot] committed Nov 13, 2018
2 parents 6dbd396 + dc7067a commit 03167aa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
50 changes: 33 additions & 17 deletions lib/unexpected-knex.js
@@ -1,24 +1,39 @@
var util = require('util');
var path = require('path');
var Knex = require('knex');
var KnexMigrator = require('knex/lib/migrate');
var proxyquire = require('proxyquire');
var QueryBuilder = require('knex/lib/query/builder');
var knexMigrationListResolver = require('knex/lib/migrate/migration-list-resolver');

function UnexpectedKnexMigrator(knex, filename) {
this.unexpectedKnexFilename = filename;
KnexMigrator.call(this, knex);
}
util.inherits(UnexpectedKnexMigrator, KnexMigrator);

UnexpectedKnexMigrator.prototype._listAll = function() {
return KnexMigrator.prototype._listAll.call(this, arguments).then(
function(filenames) {
filenames = filenames || [];
var filenameIndex = filenames.indexOf(this.unexpectedKnexFilename);
return filenames.slice(0, filenameIndex + 1);
}.bind(this)
);
var unexpectedKnexMigratorFilename;
var getUnexpectedKnexMigratorFilenames = function(filenames) {
filenames = filenames || [];
var filenameIndex = filenames.indexOf(unexpectedKnexMigratorFilename);
return filenames.slice(0, filenameIndex + 1);
};
var unexpectedKnexMigrationListResolver = Object.assign(
{},
knexMigrationListResolver,
{
listAll(absoluteConfigDir, loadExtensions) {
return knexMigrationListResolver
.listAll(absoluteConfigDir, loadExtensions)
.then(function(filenames) {
return getUnexpectedKnexMigratorFilenames(filenames);
});
},
listAllAndCompleted(config, trxOrKnex, absoluteConfigDir) {
return knexMigrationListResolver
.listAllAndCompleted(config, trxOrKnex, absoluteConfigDir)
.then(function([filenames, completed]) {
return [getUnexpectedKnexMigratorFilenames(filenames), completed];
});
}
}
);

var UnexpectedKnexMigrator = proxyquire('knex/lib/migrate', {
'./migration-list-resolver': unexpectedKnexMigrationListResolver
});

function MigrationTest(knex, expect) {
this.knex = knex;
Expand Down Expand Up @@ -232,7 +247,8 @@ function init(expect) {
});
}

var migrator = new UnexpectedKnexMigrator(knex, filename);
unexpectedKnexMigratorFilename = filename;
var migrator = new UnexpectedKnexMigrator(knex);
var migration;
try {
var directory = migrator._absoluteConfigDir();
Expand Down
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -23,7 +23,7 @@
"author": "Joel Mukuthu <joelmukuthu@gmail.com>",
"license": "MIT",
"peerDependencies": {
"knex": "^0.13.0",
"knex": "^0.15.2",
"unexpected": "^10.27.0"
},
"devDependencies": {
Expand All @@ -34,7 +34,7 @@
"eslint-config-pretty-standard": "2.0.0",
"eslint-plugin-mocha": "5.2.0",
"eslint-plugin-prettier": "3.0.0",
"knex": "0.13.0",
"knex": "0.15.2",
"mocha": "5.2.0",
"npm-run-all": "4.1.3",
"nyc": "13.1.0",
Expand All @@ -60,5 +60,8 @@
"bugs": {
"url": "https://github.com/unexpectedjs/unexpected-knex/issues"
},
"homepage": "https://github.com/unexpectedjs/unexpected-knex#readme"
"homepage": "https://github.com/unexpectedjs/unexpected-knex#readme",
"dependencies": {
"proxyquire": "2.1.0"
}
}
35 changes: 18 additions & 17 deletions test/unexpected-knex.spec.js
Expand Up @@ -560,7 +560,7 @@ describe('unexpected-knex', function() {
'when passed as parameter to',
query => query.toQuery(),
'to be',
'select * from "foo"'
'select * from `foo`'
);
});

Expand All @@ -573,7 +573,7 @@ describe('unexpected-knex', function() {
'when passed as parameter to',
query => query.toQuery(),
'to be',
'select * from "foo"'
'select * from `foo`'
);
});

Expand All @@ -582,7 +582,7 @@ describe('unexpected-knex', function() {
() => expect(knex, 'with table', 'foo', 'to equal', 'foo'),
'to error with',
dontIndent`
expected 'select * from "foo"' to equal 'foo'
expected 'select * from \`foo\`' to equal 'foo'
`
);
});
Expand Down Expand Up @@ -653,7 +653,7 @@ describe('unexpected-knex', function() {
]),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have rows satisfying [ { bar: 'foobar1' }, { bar: 'foobar20' } ]
[
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('unexpected-knex', function() {
expect(knex('foo'), 'to have rows satisfying', []),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' to have rows satisfying []
expected 'select * from \`foo\`' to have rows satisfying []
[
{ bar: 'foobar1' }, // should be removed
Expand Down Expand Up @@ -713,7 +713,7 @@ describe('unexpected-knex', function() {
]),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have rows exhaustively satisfying [ { bar: 'bar1' }, { bar: 'bar2' } ]
[
Expand Down Expand Up @@ -781,7 +781,7 @@ describe('unexpected-knex', function() {
expect(knex('foo'), 'to be empty'),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' to be empty`
expected 'select * from \`foo\`' to be empty`
)
);
});
Expand Down Expand Up @@ -810,7 +810,7 @@ describe('unexpected-knex', function() {
expect(knex('foo'), 'not to be empty'),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' not to be empty`
expected 'select * from \`foo\`' not to be empty`
)
);
});
Expand Down Expand Up @@ -890,7 +890,7 @@ describe('unexpected-knex', function() {
),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have rows satisfying expect.it('to equal', [ { bar: 'foobar1' }, { bar: 'foobar20' } ])
expected [ { bar: 'foobar1' }, { bar: 'foobar2' } ]
Expand Down Expand Up @@ -926,7 +926,7 @@ describe('unexpected-knex', function() {
),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' to have rows satisfying expect.it('to equal', [])
expected 'select * from \`foo\`' to have rows satisfying expect.it('to equal', [])
expected [ { bar: 'foobar1' }, { bar: 'foobar2' } ] to equal []
Expand Down Expand Up @@ -1007,7 +1007,7 @@ describe('unexpected-knex', function() {
),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have rows satisfying function ( /*...*/ ) { /*...*/ }
[
Expand Down Expand Up @@ -1038,7 +1038,7 @@ describe('unexpected-knex', function() {
),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have rows satisfying function ( /*...*/ ) { /*...*/ }
[
Expand Down Expand Up @@ -1094,7 +1094,7 @@ describe('unexpected-knex', function() {
() => expect(knex('foo'), 'to have a row satisfying', {}),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' to have a row satisfying {}
expected 'select * from \`foo\`' to have a row satisfying {}
cannot assert that a row has no columns or fields`
)
);
Expand All @@ -1115,7 +1115,7 @@ describe('unexpected-knex', function() {
}),
'to be rejected with',
dontIndent`
expected 'select * from "foo"' to have a row satisfying { bar: 'foobar20' }
expected 'select * from \`foo\`' to have a row satisfying { bar: 'foobar20' }
expected array to have an item satisfying { bar: 'foobar20' }
`
Expand Down Expand Up @@ -1143,7 +1143,7 @@ describe('unexpected-knex', function() {
}),
'to be rejected with',
dontIndent`
expected 'select * from "foo"'
expected 'select * from \`foo\`'
to have a row exhaustively satisfying { bar: 'bar1' }
expected array to have an item exhaustively satisfying { bar: 'bar1' }`
Expand Down Expand Up @@ -2486,7 +2486,7 @@ describe('unexpected-knex', function() {
});

describe('with multiple migration files', function() {
it('run all migrations before the provided filename', function() {
it('runs all migrations before the provided filename', function() {
return expect(
knex,
'with the migrations directory containing',
Expand Down Expand Up @@ -2514,7 +2514,7 @@ describe('unexpected-knex', function() {
).then(() => expect(knex, 'to have column', { foo: 'bar' }));
});

it('run all migrations before the provided filename after sorting', function() {
it('runs all migrations before the provided filename after sorting', function() {
return expect(
knex,
'with the migrations directory containing',
Expand Down Expand Up @@ -2567,6 +2567,7 @@ describe('unexpected-knex', function() {
'3-foo.js': {
up: knex =>
knex.schema.createTable('bar', table => {
// if this migration were to run it would trigger an error
table.dropColumn('baz');
}),
down: knex => knex.schema.dropTable('bar')
Expand Down

0 comments on commit 03167aa

Please sign in to comment.