diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f480586..648ffbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: lint: @@ -14,10 +14,10 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Use Node.js 12.x + - name: Use Node.js 18.x uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 18.x - name: Use npm cache uses: actions/cache@v1 @@ -38,7 +38,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x] + node-version: [12.x, 14.x, 16.x, 18.x] services: postgres9: @@ -80,7 +80,7 @@ jobs: PGPORT: 5432 - name: Send coverage to coveralls - if: matrix.node-version == '12.x' + if: matrix.node-version == '18.x' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.npmrc b/.npmrc index a41c857..0bc9f30 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,3 @@ package-lock = false save-exact = false +legacy-peer-deps = true diff --git a/.nvmrc b/.nvmrc index 48082f7..3c03207 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -12 +18 diff --git a/README.md b/README.md index 8070e2a..30f6c53 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ describe('migrations', function () { return expect(knex, 'to have table', 'user').and('to have columns', { user: ['id', 'first_name', 'last_name'], }); - } + }, ); }); }); @@ -173,7 +173,7 @@ exports.up = function (knex) { return knex('user') .where('id', '=', user.id) .update('name', user.first_name + ' ' + user.last_name); - }) + }), ); }); }) @@ -202,7 +202,7 @@ exports.down = function (knex) { first_name: names[0], last_name: names[1], }); - }) + }), ); }); }) diff --git a/lib/unexpected-knex.js b/lib/unexpected-knex.js index cc45462..063fe8e 100644 --- a/lib/unexpected-knex.js +++ b/lib/unexpected-knex.js @@ -1,17 +1,17 @@ -var util = require('util'); -var Knex = require('knex'); -var proxyquire = require('proxyquire'); -var QueryBuilder = require('knex/lib/query/builder'); -var knexMigrationListResolver = require('knex/lib/migrate/migration-list-resolver'); - -var unexpectedKnexMigratorFilename; -var getUnexpectedKnexMigratorFilenames = function (sources) { - var filenameIndex = sources.findIndex(function (source) { +const util = require('util'); +const Knex = require('knex'); +const proxyquire = require('proxyquire'); +const QueryBuilder = require('knex/lib/query/builder'); +const knexMigrationListResolver = require('knex/lib/migrate/migration-list-resolver'); + +let unexpectedKnexMigratorFilename; +const getUnexpectedKnexMigratorFilenames = function (sources) { + const filenameIndex = sources.findIndex(function (source) { return source.file === unexpectedKnexMigratorFilename; }); return sources.slice(0, filenameIndex + 1); }; -var unexpectedKnexMigrationListResolver = Object.assign( +const unexpectedKnexMigrationListResolver = Object.assign( {}, knexMigrationListResolver, { @@ -22,10 +22,10 @@ var unexpectedKnexMigrationListResolver = Object.assign( return [getUnexpectedKnexMigratorFilenames(sources), completed]; }); }, - } + }, ); -var UnexpectedKnexMigrator = proxyquire('knex/lib/migrate/Migrator', { +const UnexpectedKnexMigrator = proxyquire('knex/lib/migrate/Migrator', { './migration-list-resolver': unexpectedKnexMigrationListResolver, }).Migrator; @@ -59,7 +59,7 @@ MigrationTest.prototype._runHook = function (name) { if (this._hasHook(name)) { return this._getHook(name).call(this, this.knex, this.expect); } - }.bind(this) + }.bind(this), ); }; @@ -120,69 +120,66 @@ function init(expect) { }; } - expect.addAssertion(' [not] to have table ', function ( - expect, - knex, - tableName - ) { - const { schema, table } = getSchemaFromTable(knex, tableName); - - return expect( - schema.hasTable(table), - 'to be fulfilled with', - !expect.flags.not - ); - }); - - expect.addAssertion(' [not] to have column ', function ( - expect, - knex, - columnDefinition - ) { - var valueType = expect.argTypes[0]; - var tableNames = valueType.getKeys(columnDefinition); + expect.addAssertion( + ' [not] to have table ', + function (expect, knex, tableName) { + const { schema, table } = getSchemaFromTable(knex, tableName); - if (tableNames.length > 1) { - expect.errorMode = 'nested'; - return expect.fail( - 'Provide a single column in the form: { tableName: columnName }' + return expect( + schema.hasTable(table), + 'to be fulfilled with', + !expect.flags.not, ); - } + }, + ); - var tableName = tableNames[0]; - var columnName = columnDefinition[tableName]; + expect.addAssertion( + ' [not] to have column ', + function (expect, knex, columnDefinition) { + const valueType = expect.argTypes[0]; + const tableNames = valueType.getKeys(columnDefinition); + + if (tableNames.length > 1) { + expect.errorMode = 'nested'; + return expect.fail( + 'Provide a single column in the form: { tableName: columnName }', + ); + } - const { schema, table } = getSchemaFromTable(knex, tableName); + const tableName = tableNames[0]; + const columnName = columnDefinition[tableName]; - return expect( - schema.hasColumn(table, columnName), - 'to be fulfilled with', - !expect.flags.not - ); - }); + const { schema, table } = getSchemaFromTable(knex, tableName); - expect.addAssertion(' [not] to have columns ', function ( - expect, - knex, - columnDefinition - ) { - expect.errorMode = 'nested'; - var tableNames = Object.keys(columnDefinition); - var assertions = tableNames.reduce(function (assertions, tableName) { - var columnNames = columnDefinition[tableName]; - if (!Array.isArray(columnNames)) { - columnNames = [columnNames]; - } - return assertions.concat( - columnNames.map(function (columnName) { - var column = {}; - column[tableName] = columnName; - return expect(knex, '[not] to have column', column); - }) + return expect( + schema.hasColumn(table, columnName), + 'to be fulfilled with', + !expect.flags.not, ); - }, []); - return expect.promise.all(assertions); - }); + }, + ); + + expect.addAssertion( + ' [not] to have columns ', + function (expect, knex, columnDefinition) { + expect.errorMode = 'nested'; + const tableNames = Object.keys(columnDefinition); + const assertions = tableNames.reduce(function (assertions, tableName) { + let columnNames = columnDefinition[tableName]; + if (!Array.isArray(columnNames)) { + columnNames = [columnNames]; + } + return assertions.concat( + columnNames.map(function (columnName) { + const column = {}; + column[tableName] = columnName; + return expect(knex, '[not] to have column', column); + }), + ); + }, []); + return expect.promise.all(assertions); + }, + ); expect.addType({ name: 'knexQuery', @@ -201,18 +198,17 @@ function init(expect) { expect.errorMode = 'bubble'; return expect.shift(knex.from(table)); - } + }, ); - expect.addAssertion(' with schema ', function ( - expect, - knex, - schema - ) { - expect.errorMode = 'bubble'; + expect.addAssertion( + ' with schema ', + function (expect, knex, schema) { + expect.errorMode = 'bubble'; - return expect.shift(knex.withSchema(schema)); - }); + return expect.shift(knex.withSchema(schema)); + }, + ); expect.addAssertion( [ @@ -224,22 +220,22 @@ function init(expect) { return expect( query.select(), 'to be fulfilled with value [exhaustively] satisfying', - value + value, ); - } + }, ); - expect.addAssertion(' [not] to be empty', function ( - expect, - query - ) { - expect.errorMode = 'defaultOrNested'; - return expect( - query, - 'to have rows satisfying', - expect.it('[not] to be empty') - ); - }); + expect.addAssertion( + ' [not] to be empty', + function (expect, query) { + expect.errorMode = 'defaultOrNested'; + return expect( + query, + 'to have rows satisfying', + expect.it('[not] to be empty'), + ); + }, + ); expect.addAssertion( ' to have a row [exhaustively] satisfying ', @@ -251,9 +247,9 @@ function init(expect) { return expect( query, 'to have rows satisfying', - expect.it('to have an item [exhaustively] satisfying', value) + expect.it('to have an item [exhaustively] satisfying', value), ); - } + }, ); function ascendingOrder(a, b) { @@ -271,10 +267,10 @@ function init(expect) { 'sorted by', ascendingOrder, 'to [exhaustively] satisfy', - value - ) + value, + ), ); - } + }, ); expect.addAssertion( @@ -288,113 +284,112 @@ function init(expect) { 'sorted by', ascendingOrder, 'to [exhaustively] satisfy', - value - ) + value, + ), ); - } + }, ); - expect.addAssertion(' to apply migration ', async function ( - expect, - knex, - filename - ) { - expect.errorMode = 'nested'; - - if (!filename) { - return expect.fail('the filename cannot be an empty string'); - } - - function fail(message, error) { - return expect.fail({ - output: function (output) { - output.error(message).error(': ').appendErrorMessage(error); - }, - originalError: error, - }); - } + expect.addAssertion( + ' to apply migration ', + async function (expect, knex, filename) { + expect.errorMode = 'nested'; - unexpectedKnexMigratorFilename = filename; + if (!filename) { + return expect.fail('the filename cannot be an empty string'); + } - var migrator = new UnexpectedKnexMigrator(knex); - var test = new MigrationTest(knex, expect); - var migration; + function fail(message, error) { + return expect.fail({ + output: function (output) { + output.error(message).error(': ').appendErrorMessage(error); + }, + originalError: error, + }); + } - function getMigration() { - return migrator.config.migrationSource - .getMigrations() - .then(function (sources) { - const source = sources.find(function (migration) { - return migration.file === filename; + unexpectedKnexMigratorFilename = filename; + + const migrator = new UnexpectedKnexMigrator(knex); + const test = new MigrationTest(knex, expect); + let migration; + + function getMigration() { + return migrator.config.migrationSource + .getMigrations() + .then(function (sources) { + const source = sources.find(function (migration) { + return migration.file === filename; + }); + if (!source) { + throw new Error(`migration ${util.inspect(filename)} not found`); + } + return migrator.config.migrationSource.getMigration(source); }); - if (!source) { - throw new Error(`migration ${util.inspect(filename)} not found`); - } - return migrator.config.migrationSource.getMigration(source); - }); - } + } - function migrateUp() { - return migrator.latest(); - } + function migrateUp() { + return migrator.latest(); + } - function migrateDown() { - return migrator.rollback(); - } + function migrateDown() { + return migrator.rollback(); + } - return getMigration() - .then(function (_migration) { - migration = _migration; - }) - .catch(function (e) { - return fail('cannot load migration', e); - }) - .then(function () { - if (typeof migration.test === 'function') { - migration.test.call(test); - } - }) - .then(function () { - return test._runHook('beforeUp').catch(function (e) { - return fail('beforeUp failed with', e); - }); - }) - .then(function () { - return migrateUp().catch(function (e) { - return fail('up migration failed with', e); - }); - }) - .then(function () { - return test._runHook('testUp').catch(function (e) { - return fail('testUp failed with', e); - }); - }) - .then(function () { - return test._runHook('beforeDown').catch(function (e) { - return fail('beforeDown failed with', e); - }); - }) - .then(function () { - return migrateDown().catch(function (e) { - return fail('down migration failed with', e); - }); - }) - .then(function () { - return test._runHook('testDown').catch(function (e) { - return fail('testDown failed with', e); - }); - }) - .then(function () { - return migrateUp().catch(function (e) { - return fail('up migration after down migration failed with', e); - }); - }) - .then(function () { - return test._runHook('after').catch(function (e) { - return fail('after failed with', e); + return getMigration() + .then(function (_migration) { + migration = _migration; + }) + .catch(function (e) { + return fail('cannot load migration', e); + }) + .then(function () { + if (typeof migration.test === 'function') { + migration.test.call(test); + } + }) + .then(function () { + return test._runHook('beforeUp').catch(function (e) { + return fail('beforeUp failed with', e); + }); + }) + .then(function () { + return migrateUp().catch(function (e) { + return fail('up migration failed with', e); + }); + }) + .then(function () { + return test._runHook('testUp').catch(function (e) { + return fail('testUp failed with', e); + }); + }) + .then(function () { + return test._runHook('beforeDown').catch(function (e) { + return fail('beforeDown failed with', e); + }); + }) + .then(function () { + return migrateDown().catch(function (e) { + return fail('down migration failed with', e); + }); + }) + .then(function () { + return test._runHook('testDown').catch(function (e) { + return fail('testDown failed with', e); + }); + }) + .then(function () { + return migrateUp().catch(function (e) { + return fail('up migration after down migration failed with', e); + }); + }) + .then(function () { + return test._runHook('after').catch(function (e) { + return fail('after failed with', e); + }); }); - }); - }); + }, + ); } module.exports = { diff --git a/package.json b/package.json index 466fa8f..0d99741 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lint": "eslint . && prettier --check '**/*.{js,md}'", "lint:fix": "eslint --fix . && prettier --write '**/*.{js,md}'", "test:mocha": "mocha --exit", - "test": "docker-compose run --rm unexpected-knex", + "test": "docker compose run --rm unexpected-knex", "coverage": "ASSERT_ERROR_OUTPUT=false nyc mocha" }, "keywords": [ @@ -27,22 +27,20 @@ }, "devDependencies": { "dedent-js": "^1.0.1", - "eslint": "^7.0.0", - "eslint-config-prettier": "^8.2.0", - "eslint-config-pretty-standard": "^3.0.1", - "eslint-config-standard": "^14.1.1", - "eslint-plugin-import": "^2.20.2", - "eslint-plugin-mocha": "^7.0.0", + "eslint": "^8.49.0", + "eslint-config-prettier": "^9.0.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.28.1", + "eslint-plugin-mocha": "^10.1.0", + "eslint-plugin-n": "^16.1.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-standard": "^4.0.1", + "eslint-plugin-promise": "^6.1.1", "knex": "^0.21.0", - "mocha": "^7.1.1", - "mock-fs": "^4.11.0", - "npm-run-all": "^4.1.5", + "mocha": "^10.2.0", + "mock-fs": "^5.2.0", "nyc": "^15.0.1", "pg": "^8.0.2", - "prettier": "~2.1.2", + "prettier": "^3.0.3", "unexpected": "^12.0.0", "unexpected-require": "^2.1.0" }, diff --git a/test/unexpected-knex.spec.js b/test/unexpected-knex.spec.js index 9d3e65e..dd97eae 100644 --- a/test/unexpected-knex.spec.js +++ b/test/unexpected-knex.spec.js @@ -7,6 +7,26 @@ const unexpectedRequire = require('unexpected-require'); const unexpectedKnex = require('../lib/unexpected-knex'); const dontIndent = require('dedent-js'); const assertErrorOuput = process.env.ASSERT_ERROR_OUTPUT !== 'false'; +const packageJsonPath = path.resolve(__dirname, '../package.json') +// const packageJson = require('../package.json') +const packageJson = require('fs') + .readFileSync(packageJsonPath) + .toString(); + +console.log({ + npm_package_type: process.env.npm_package_type, + npm_package_json: process.env.npm_package_json, + packageJsonPath, +}) + +if (process.env.npm_package_json) delete process.env.npm_package_json +if (process.env.npm_package_type) delete process.env.npm_package_type + +// This file is `require`d here so that it's cached by Node.js before we go +// ahead and mock out `require`, since knex's migrator require's it while doing +// its job. +require('knex/lib/util/import-file.js'); +// require('../package.json'); describe('unexpected-knex', function () { const host = process.env.PGHOST || 'localhost'; @@ -39,23 +59,22 @@ describe('unexpected-knex', function () { .clone() .use(unexpectedRequire) .use(unexpectedKnex) - .addAssertion(' with fs mocked out ', function ( - expect, - subject, - mocks - ) { - expect.errorMode = 'bubble'; - mockFs(mocks); - return expect - .shift() - .then(function () { - mockFs.restore(); - }) - .catch(function (e) { - mockFs.restore(); - throw e; - }); - }) + .addAssertion( + ' with fs mocked out ', + function (expect, subject, mocks) { + expect.errorMode = 'bubble'; + mockFs(mocks); + return expect + .shift() + .then(function () { + mockFs.restore(); + }) + .catch(function (e) { + mockFs.restore(); + throw e; + }); + }, + ) .addAssertion( ' with the migrations directory containing ', function (expect, subject, migrations, ...rest) { @@ -67,7 +86,9 @@ describe('unexpected-knex', function () { // matters is the require() context context[filename] = ''; return context; - }, {}), + }, { + [packageJsonPath]: packageJson + }), }; const requireContext = filenames.reduce((context, filename) => { const absolutePath = path.resolve(migrationsDirectory, filename); @@ -82,16 +103,20 @@ describe('unexpected-knex', function () { requireContext, ...rest, ]); - } + }, + ) + .addAssertion( + ' with no migrations directory ', + function (expect, subject, ...rest) { + expect.errorMode = 'bubble'; + return expect.apply(expect, [ + subject, + 'with fs mocked out', + {}, + ...rest, + ]); + }, ) - .addAssertion(' with no migrations directory ', function ( - expect, - subject, - ...rest - ) { - expect.errorMode = 'bubble'; - return expect.apply(expect, [subject, 'with fs mocked out', {}, ...rest]); - }) .addAssertion( ' with an empty migrations directory ', function (expect, subject, ...rest) { @@ -104,7 +129,7 @@ describe('unexpected-knex', function () { }, ...rest, ]); - } + }, ); afterEach(function () { @@ -133,7 +158,7 @@ describe('unexpected-knex', function () { table.timestamps(); }) .then(() => - expect(expect(knex, 'to have table', 'foo'), 'to be fulfilled') + expect(expect(knex, 'to have table', 'foo'), 'to be fulfilled'), ); }); @@ -141,7 +166,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have table', 'foo'), 'to be rejected with', - /to have table 'foo'/ + /to have table 'foo'/, ); }); @@ -165,7 +190,7 @@ describe('unexpected-knex', function () { table.timestamps(); }) .then(() => - expect(expect(knex, 'to have table', 'foo.foo'), 'to be fulfilled') + expect(expect(knex, 'to have table', 'foo.foo'), 'to be fulfilled'), ); }); @@ -179,8 +204,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'to have table', 'foo.foo'), 'to be rejected with', - /to have table 'foo.foo'/ - ) + /to have table 'foo.foo'/, + ), ); }); @@ -188,7 +213,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have table', 'foo.foo'), 'to be rejected with', - /to have table 'foo.foo'/ + /to have table 'foo.foo'/, ); }); }); @@ -198,7 +223,7 @@ describe('unexpected-knex', function () { it('fulfils if the table does not exist', function () { return expect( expect(knex, 'not to have table', 'foo'), - 'to be fulfilled' + 'to be fulfilled', ); }); @@ -211,8 +236,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have table', 'foo'), 'to be rejected with', - /not to have table 'foo'/ - ) + /not to have table 'foo'/, + ), ); }); @@ -234,13 +259,13 @@ describe('unexpected-knex', function () { .raw( ` DROP SCHEMA IF EXISTS foo CASCADE; - ` + `, ) .then(() => expect( expect(knex, 'not to have table', 'foo.foo'), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -253,8 +278,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'not to have table', 'foo.foo'), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -268,8 +293,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have table', 'foo.foo'), 'to be rejected with', - /not to have table 'foo.foo'/ - ) + /not to have table 'foo.foo'/, + ), ); }); }); @@ -286,7 +311,7 @@ describe('unexpected-knex', function () { 'when passed as parameter to', (query) => query.toQuery(), 'to be', - 'select * from "foo"."bar"' + 'select * from "foo"."bar"', ); }); @@ -295,7 +320,9 @@ describe('unexpected-knex', function () { expect(knex, 'with schema', 'foo'), 'to be rejected with error satisfying', // unexpected auto-runs the query since it's a thenable - { message: 'select * - SELECT * with no tables specified is not valid' } + { + message: 'select * - SELECT * with no tables specified is not valid', + }, ); }); @@ -305,7 +332,7 @@ describe('unexpected-knex', function () { 'to error with', dontIndent` expected 'select *' to equal 'foo' - ` + `, ); }); }); @@ -319,8 +346,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'to have column', { foo: 'bar' }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -333,8 +360,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'to have column', { foo: 'baz' }), 'to be rejected with', - /to have column { foo: 'baz' }/ - ) + /to have column { foo: 'baz' }/, + ), ); }); @@ -342,7 +369,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have column', { foo: 'bar' }), 'to be rejected with', - /to have column { foo: 'bar' }/ + /to have column { foo: 'bar' }/, ); }); @@ -350,7 +377,7 @@ describe('unexpected-knex', function () { return expect( () => expect(knex, 'to have column', { foo: 'bar', bar: 'baz' }), 'to error with', - /Provide a single column in the form: { tableName: columnName }/ + /Provide a single column in the form: { tableName: columnName }/, ); }); @@ -364,8 +391,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'to have column', { 'other.other_foo': 'bar' }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -373,7 +400,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have column', { 'test.foo': 'baz' }), 'to be rejected with', - /to have column { 'test.foo': 'baz' }/ + /to have column { 'test.foo': 'baz' }/, ); }); @@ -381,7 +408,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have column', { 'other.lame': 'baz' }), 'to be rejected with', - /to have column { 'other.lame': 'baz' }/ + /to have column { 'other.lame': 'baz' }/, ); }); @@ -389,7 +416,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have column', { 'foo.bar': 'baz' }), 'to be rejected with', - /to have column { 'foo.bar': 'baz' }/ + /to have column { 'foo.bar': 'baz' }/, ); }); }); @@ -404,8 +431,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'not to have column', { foo: 'baz' }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -418,15 +445,15 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have column', { foo: 'bar' }), 'to be rejected with', - /not to have column { foo: 'bar' }/ - ) + /not to have column { foo: 'bar' }/, + ), ); }); it('fulfils if the table itself does not exist', function () { return expect( expect(knex, 'not to have column', { foo: 'bar' }), - 'to be fulfilled' + 'to be fulfilled', ); }); @@ -434,7 +461,7 @@ describe('unexpected-knex', function () { return expect( () => expect(knex, 'not to have column', { foo: 'bar', bar: 'baz' }), 'to error with', - /Provide a single column in the form: { tableName: columnName }/ + /Provide a single column in the form: { tableName: columnName }/, ); }); @@ -442,21 +469,21 @@ describe('unexpected-knex', function () { it('fulfils if the column does not exist', function () { return expect( expect(knex, 'not to have column', { 'other.other_foo': 'bar' }), - 'to be fulfilled' + 'to be fulfilled', ); }); it('fulfils if the table does not exist', function () { return expect( expect(knex, 'not to have column', { 'lame.lame': 'baz' }), - 'to be fulfilled' + 'to be fulfilled', ); }); it('fulfils if the schema does not exist', function () { return expect( expect(knex, 'not to have column', { 'bar.foo': 'baz' }), - 'to be fulfilled' + 'to be fulfilled', ); }); @@ -470,8 +497,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have column', { 'other.foo': 'bar' }), 'to be rejected with', - /not to have column { 'other.foo': 'bar' }/ - ) + /not to have column { 'other.foo': 'bar' }/, + ), ); }); }); @@ -487,8 +514,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'to have columns', { foo: ['bar', 'baz'] }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -501,8 +528,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'to have columns', { foo: ['bar', 'baz'] }), 'to be rejected with error satisfying', - /expected knex to have column { foo: 'baz' }/ - ) + /expected knex to have column { foo: 'baz' }/, + ), ); }); @@ -515,8 +542,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'to have columns', { foo: ['baz', 'quux'] }), 'to be rejected with error satisfying', - /expected knex to have column { foo: '(baz|quux)' }/ - ) + /expected knex to have column { foo: '(baz|quux)' }/, + ), ); }); @@ -524,7 +551,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have columns', { foo: ['baz', 'quux'] }), 'to be rejected with', - /expected knex to have column { foo: '(baz|quux)' }/ + /expected knex to have column { foo: '(baz|quux)' }/, ); }); @@ -537,7 +564,7 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( @@ -545,8 +572,8 @@ describe('unexpected-knex', function () { foo: ['bar', 'baz'], bar: 'baz', }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -558,7 +585,7 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( @@ -567,8 +594,8 @@ describe('unexpected-knex', function () { bar: 'baz', }), 'to be rejected with', - /expected knex to have column { (foo|bar): '(bar|baz)' }/ - ) + /expected knex to have column { (foo|bar): '(bar|baz)' }/, + ), ); }); @@ -580,14 +607,14 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( expect(knex, 'to have columns', { foo: 'quux', bar: 'quux' }), 'to be rejected with', - /expected knex to have column { (foo|bar): 'quux' }/ - ) + /expected knex to have column { (foo|bar): 'quux' }/, + ), ); }); @@ -600,8 +627,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'to have columns', { foo: 'bar', bar: 'quux' }), 'to be rejected with', - /expected knex to have column { bar: 'quux' }/ - ) + /expected knex to have column { bar: 'quux' }/, + ), ); }); @@ -609,7 +636,7 @@ describe('unexpected-knex', function () { return expect( expect(knex, 'to have columns', { foo: 'bar', bar: 'quux' }), 'to be rejected with', - /expected knex to have column { (foo|bar): '(bar|quux)' }/ + /expected knex to have column { (foo|bar): '(bar|quux)' }/, ); }); }); @@ -624,8 +651,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex, 'not to have columns', { foo: ['quux1', 'quux2'] }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -638,8 +665,8 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have columns', { foo: ['bar', 'baz'] }), 'to be rejected with', - /expected knex not to have column { foo: 'bar' }/ - ) + /expected knex not to have column { foo: 'bar' }/, + ), ); }); @@ -653,15 +680,15 @@ describe('unexpected-knex', function () { expect( expect(knex, 'not to have columns', { foo: ['bar', 'baz'] }), 'to be rejected with', - /expected knex not to have column { foo: '(bar|baz)' }/ - ) + /expected knex not to have column { foo: '(bar|baz)' }/, + ), ); }); it('fulfils if the table itself does not exist', function () { return expect( expect(knex, 'not to have columns', { foo: ['baz', 'quux'] }), - 'to be fulfilled' + 'to be fulfilled', ); }); @@ -673,7 +700,7 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( @@ -681,8 +708,8 @@ describe('unexpected-knex', function () { foo: ['quux1', 'quux2'], bar: 'quux1', }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -694,7 +721,7 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( @@ -703,8 +730,8 @@ describe('unexpected-knex', function () { bar: 'quux', }), 'to be rejected with', - /expected knex not to have column { foo: 'bar' }/ - ) + /expected knex not to have column { foo: 'bar' }/, + ), ); }); @@ -716,21 +743,21 @@ describe('unexpected-knex', function () { .then(() => knex.schema.createTable('bar', (table) => { table.string('baz'); - }) + }), ) .then(() => expect( expect(knex, 'not to have columns', { foo: 'bar', bar: 'baz' }), 'to be rejected with', - /expected knex not to have column { (foo|bar): '(bar|baz)' }/ - ) + /expected knex not to have column { (foo|bar): '(bar|baz)' }/, + ), ); }); it('fulfils if the tables themselves do not exist', function () { return expect( expect(knex, 'not to have columns', { foo: 'bar', bar: 'quux' }), - 'to be fulfilled' + 'to be fulfilled', ); }); }); @@ -748,7 +775,7 @@ describe('unexpected-knex', function () { 'when passed as parameter to', (query) => query.toQuery(), 'to be', - 'select * from "foo"' + 'select * from "foo"', ); }); @@ -757,7 +784,7 @@ describe('unexpected-knex', function () { expect(knex, 'with table', 'foo'), 'to be rejected with error satisfying', // unexpected auto-runs the query since it's a thenable - { message: 'select * from "foo" - relation "foo" does not exist' } + { message: 'select * from "foo" - relation "foo" does not exist' }, ); }); @@ -767,7 +794,7 @@ describe('unexpected-knex', function () { 'to error with', dontIndent` expected 'select * from "foo"' to equal 'foo' - ` + `, ); }); }); @@ -779,7 +806,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -787,8 +814,8 @@ describe('unexpected-knex', function () { { bar: 'foobar1' }, { bar: 'foobar2' }, ]), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -803,8 +830,8 @@ describe('unexpected-knex', function () { expect(knex('foo'), 'to have rows satisfying', [ { bar: 'foobar1' }, ]), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -816,8 +843,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex('foo'), 'to have rows satisfying', []), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -827,7 +854,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -848,8 +875,8 @@ describe('unexpected-knex', function () { // -foobar2 // +foobar20 } - ]` - ) + ]`, + ), ); }); @@ -859,7 +886,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -871,8 +898,8 @@ describe('unexpected-knex', function () { [ { bar: 'foobar1' }, // should be removed { bar: 'foobar2' } // should be removed - ]` - ) + ]`, + ), ); }); @@ -900,7 +927,7 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, ]), - ...assertion + ...assertion, ); }); @@ -915,7 +942,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { bar: 'bar1', baz: 'baz1' }, { bar: 'bar2', baz: 'baz2' }, - ]) + ]), ) .then(() => expect( @@ -937,8 +964,8 @@ describe('unexpected-knex', function () { bar: 'bar2', baz: 'baz2' // should be removed } - ]` - ) + ]`, + ), ); }); }); @@ -954,7 +981,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { bar: 'bar1', baz: 'baz1' }, { bar: 'bar2', baz: 'baz2' }, - ]) + ]), ) .then(() => expect( @@ -962,8 +989,8 @@ describe('unexpected-knex', function () { { bar: 'bar1' }, { bar: 'bar2' }, ]), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); }); @@ -980,7 +1007,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { id: 2, bar: 'foobar2' }, { id: 1, bar: 'foobar1' }, - ]) + ]), ) .then(() => expect( @@ -988,8 +1015,8 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, ]), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1003,7 +1030,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, - ]) + ]), ) .then(() => { const errorOutput = dontIndent` @@ -1039,7 +1066,7 @@ describe('unexpected-knex', function () { { id: 2, bar: 'foobar2' }, { id: 1, bar: 'foobar1' }, ]), - ...assertion + ...assertion, ); }); }); @@ -1074,7 +1101,7 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, ]), - ...assertion + ...assertion, ); }); @@ -1089,7 +1116,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, - ]) + ]), ) .then(() => { const errorOutput = dontIndent` @@ -1115,9 +1142,9 @@ describe('unexpected-knex', function () { expect( knex('foo'), 'to have sorted rows exhaustively satisfying', - [{ id: 1, bar: 'foobar1' }, { id: 2 }] + [{ id: 1, bar: 'foobar1' }, { id: 2 }], ), - ...assertion + ...assertion, ); }); }); @@ -1134,7 +1161,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, - ]) + ]), ) .then(() => expect( @@ -1142,8 +1169,8 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, { id: 2 }, ]), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); }); @@ -1161,9 +1188,9 @@ describe('unexpected-knex', function () { [ { id: 1, bar: 'foobar1' }, { id: 2, bar: 'foobar2' }, - ] + ], ), - 'to be fulfilled' + 'to be fulfilled', ); }); @@ -1207,9 +1234,9 @@ describe('unexpected-knex', function () { [ { id: 2, bar: 'foobar2' }, { id: 1, bar: 'foobar1' }, - ] + ], ), - ...assertion + ...assertion, ); }); @@ -1230,9 +1257,9 @@ describe('unexpected-knex', function () { expect( Promise.reject(new Error('foo')), 'to be fulfilled with sorted rows satisfying', - ['foo', 'bar'] + ['foo', 'bar'], ), - ...assertion + ...assertion, ); }); @@ -1264,9 +1291,9 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, ]), 'to be fulfilled with sorted rows exhaustively satisfying', - [{ id: 1, bar: 'foobar1' }, { id: 2 }] + [{ id: 1, bar: 'foobar1' }, { id: 2 }], ), - ...assertion + ...assertion, ); }); }); @@ -1280,9 +1307,9 @@ describe('unexpected-knex', function () { { id: 1, bar: 'foobar1' }, ]), 'to be fulfilled with sorted rows satisfying', - [{ id: 1, bar: 'foobar1' }, { id: 2 }] + [{ id: 1, bar: 'foobar1' }, { id: 2 }], ), - 'to be fulfilled' + 'to be fulfilled', ); }); }); @@ -1295,7 +1322,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - expect(expect(knex('foo'), 'to be empty'), 'to be fulfilled') + expect(expect(knex('foo'), 'to be empty'), 'to be fulfilled'), ); }); @@ -1305,7 +1332,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -1314,8 +1341,8 @@ describe('unexpected-knex', function () { dontIndent` expected 'select * from "foo"' to be empty - expected [ { bar: 'foobar1' }, { bar: 'foobar2' } ] to be empty` - ) + expected [ { bar: 'foobar1' }, { bar: 'foobar2' } ] to be empty`, + ), ); }); @@ -1349,10 +1376,10 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => - expect(expect(knex('foo'), 'not to be empty'), 'to be fulfilled') + expect(expect(knex('foo'), 'not to be empty'), 'to be fulfilled'), ); }); @@ -1368,8 +1395,8 @@ describe('unexpected-knex', function () { dontIndent` expected 'select * from "foo"' not to be empty - expected [] not to be empty` - ) + expected [] not to be empty`, + ), ); }); }); @@ -1382,17 +1409,17 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( expect( knex('foo'), 'to have rows satisfying', - expect.it('to equal', [{ bar: 'foobar1' }, { bar: 'foobar2' }]) + expect.it('to equal', [{ bar: 'foobar1' }, { bar: 'foobar2' }]), ), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1407,10 +1434,10 @@ describe('unexpected-knex', function () { expect( knex('foo'), 'to have rows satisfying', - expect.it('to equal', [{ bar: 'foobar1' }]) + expect.it('to equal', [{ bar: 'foobar1' }]), ), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1424,10 +1451,10 @@ describe('unexpected-knex', function () { expect( knex('foo'), 'to have rows satisfying', - expect.it('to equal', []) + expect.it('to equal', []), ), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1437,14 +1464,14 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( expect( knex('foo'), 'to have rows satisfying', - expect.it('to equal', [{ bar: 'foobar1' }, { bar: 'foobar20' }]) + expect.it('to equal', [{ bar: 'foobar1' }, { bar: 'foobar20' }]), ), 'to be rejected with', dontIndent` @@ -1462,8 +1489,8 @@ describe('unexpected-knex', function () { // -foobar2 // +foobar20 } - ]` - ) + ]`, + ), ); }); @@ -1473,14 +1500,14 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( expect( knex('foo'), 'to have rows satisfying', - expect.it('to equal', []) + expect.it('to equal', []), ), 'to be rejected with', dontIndent` @@ -1491,8 +1518,8 @@ describe('unexpected-knex', function () { [ { bar: 'foobar1' }, // should be removed { bar: 'foobar2' } // should be removed - ]` - ) + ]`, + ), ); }); }); @@ -1507,8 +1534,8 @@ describe('unexpected-knex', function () { .then(() => expect( expect(knex('foo'), 'to have a row satisfying', { bar: 'foobar1' }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1518,13 +1545,13 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( expect(knex('foo'), 'to have a row satisfying', { bar: 'foobar2' }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); @@ -1534,7 +1561,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -1542,8 +1569,8 @@ describe('unexpected-knex', function () { 'to be rejected with', dontIndent` expected 'select * from "foo"' to have a row satisfying {} - cannot assert that a row has no columns or fields` - ) + cannot assert that a row has no columns or fields`, + ), ); }); @@ -1553,7 +1580,7 @@ describe('unexpected-knex', function () { table.string('bar'); }) .then(() => - knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]) + knex('foo').insert([{ bar: 'foobar1' }, { bar: 'foobar2' }]), ) .then(() => expect( @@ -1566,8 +1593,8 @@ describe('unexpected-knex', function () { expected [ { bar: 'foobar1' }, { bar: 'foobar2' } ] to have an item satisfying { bar: 'foobar20' } - ` - ) + `, + ), ); }); @@ -1582,7 +1609,7 @@ describe('unexpected-knex', function () { knex('foo').insert([ { bar: 'bar1', baz: 'baz1' }, { bar: 'bar2', baz: 'baz2' }, - ]) + ]), ) .then(() => expect( @@ -1595,8 +1622,8 @@ describe('unexpected-knex', function () { to have a row exhaustively satisfying { bar: 'bar1' } expected [ { bar: 'bar1', baz: 'baz1' }, { bar: 'bar2', baz: 'baz2' } ] - to have an item exhaustively satisfying { bar: 'bar1' }` - ) + to have an item exhaustively satisfying { bar: 'bar1' }`, + ), ); }); }); @@ -1612,22 +1639,22 @@ describe('unexpected-knex', function () { knex('foo').insert([ { bar: 'bar1', baz: 'baz1' }, { bar: 'bar2', baz: 'baz2' }, - ]) + ]), ) .then(() => expect( expect(knex('foo'), 'to have a row satisfying', { bar: 'bar1', }), - 'to be fulfilled' - ) + 'to be fulfilled', + ), ); }); }); }); describe(' to apply migration ', function () { - it('applies a migration', function () { + it.only('applies a migration', function () { return expect( knex, 'with the migrations directory containing', @@ -1641,12 +1668,12 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ).then(() => expect(knex, 'to have table', 'foo')); }); it('migrates up, down, then up again to ensure the down migration is tested', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -1663,13 +1690,13 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ).then(() => expect(callOrder, 'to equal', [ 'up migration', 'down migration', 'up migration', - ]) + ]), ); }); @@ -1682,7 +1709,7 @@ describe('unexpected-knex', function () { expected ${knexOutputBlock} to apply migration '' - the filename cannot be an empty string` + the filename cannot be an empty string`, ); }); @@ -1693,7 +1720,7 @@ describe('unexpected-knex', function () { knex, 'with no migrations directory', 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', expect.it( @@ -1702,8 +1729,8 @@ describe('unexpected-knex', function () { return error.message; }, 'to contain', - 'ENOENT' - ) + 'ENOENT', + ), ); }); @@ -1714,14 +1741,14 @@ describe('unexpected-knex', function () { knex, 'with an empty migrations directory', 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - cannot load migration: Error('migration \\'1-foo.js\\' not found')` + cannot load migration: Error('migration \\'1-foo.js\\' not found')`, ); }); @@ -1741,14 +1768,14 @@ describe('unexpected-knex', function () { [migrationsDirectory]: {}, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - cannot load migration: Error('migration \\'1-foo.js\\' not found')` + cannot load migration: Error('migration \\'1-foo.js\\' not found')`, ); }); }); @@ -1772,7 +1799,7 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ); }); @@ -1792,14 +1819,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - the beforeUp hook must be a function` + the beforeUp hook must be a function`, ); }); @@ -1820,14 +1847,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - a beforeUp hook has already been registered` + a beforeUp hook has already been registered`, ); }); @@ -1851,14 +1878,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), - 'not to error' + 'not to error', ); }); it('calls the hook before running the up migration', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -1880,14 +1907,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', 'up migration', 'down migration', 'up migration', - ]) + ]), ); }); @@ -1909,14 +1936,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - beforeUp failed with: Error('beforeUp error')` + beforeUp failed with: Error('beforeUp error')`, ); }); @@ -1938,14 +1965,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - beforeUp failed with: Error('beforeUp error')` + beforeUp failed with: Error('beforeUp error')`, ); }); }); @@ -1970,14 +1997,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), - 'not to error' + 'not to error', ); }); it('calls the hook after running the up migration', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -1999,14 +2026,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'up migration', 'testUp hook', 'down migration', 'up migration', - ]) + ]), ); }); @@ -2028,14 +2055,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - testUp failed with: Error('testUp error')` + testUp failed with: Error('testUp error')`, ); }); @@ -2057,14 +2084,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - testUp failed with: Error('testUp error')` + testUp failed with: Error('testUp error')`, ); }); }); @@ -2089,14 +2116,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), - 'not to error' + 'not to error', ); }); it('calls the hook before running the down migration', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -2118,14 +2145,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'up migration', 'beforeDown hook', 'down migration', 'up migration', - ]) + ]), ); }); @@ -2147,14 +2174,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - beforeDown failed with: Error('beforeDown error')` + beforeDown failed with: Error('beforeDown error')`, ); }); @@ -2176,14 +2203,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - beforeDown failed with: Error('beforeDown error')` + beforeDown failed with: Error('beforeDown error')`, ); }); }); @@ -2208,14 +2235,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), - 'not to error' + 'not to error', ); }); it('calls the hook after running the down migration', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -2237,14 +2264,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'up migration', 'down migration', 'testDown hook', 'up migration', - ]) + ]), ); }); @@ -2266,14 +2293,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - testDown failed with: Error('testDown error')` + testDown failed with: Error('testDown error')`, ); }); @@ -2295,14 +2322,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - testDown failed with: Error('testDown error')` + testDown failed with: Error('testDown error')`, ); }); }); @@ -2327,14 +2354,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), - 'not to error' + 'not to error', ); }); it('calls the hook after running the down migration', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -2356,14 +2383,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'up migration', 'down migration', 'up migration', 'after hook', - ]) + ]), ); }); @@ -2385,14 +2412,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - after failed with: Error('after error')` + after failed with: Error('after error')`, ); }); @@ -2414,21 +2441,21 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '1-foo.js' + '1-foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration '1-foo.js' - after failed with: Error('after error')` + after failed with: Error('after error')`, ); }); }); describe('with all hooks', function () { it('calls beforeUp, up migration, testUp, beforeDown, down migration, testDown, up migration, after', function () { - var callOrder = []; + const callOrder = []; return expect( knex, 'with the migrations directory containing', @@ -2462,7 +2489,7 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', @@ -2473,12 +2500,12 @@ describe('unexpected-knex', function () { 'testDown hook', 'up migration', 'after hook', - ]) + ]), ); }); it('halts at beforeUp if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2515,19 +2542,19 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - beforeUp failed with: Error('beforeUp error')` + beforeUp failed with: Error('beforeUp error')`, ).then(() => expect(callOrder, 'to equal', ['beforeUp hook'])); }); it('halts at up migration if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2563,21 +2590,21 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - up migration failed with: Error('up migration error')` + up migration failed with: Error('up migration error')`, ).then(() => - expect(callOrder, 'to equal', ['beforeUp hook', 'up migration']) + expect(callOrder, 'to equal', ['beforeUp hook', 'up migration']), ); }); it('halts at testUp if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2614,25 +2641,25 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - testUp failed with: Error('testUp error')` + testUp failed with: Error('testUp error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', 'up migration', 'testUp hook', - ]) + ]), ); }); it('halts at beforeDown if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2669,26 +2696,26 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - beforeDown failed with: Error('beforeDown error')` + beforeDown failed with: Error('beforeDown error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', 'up migration', 'testUp hook', 'beforeDown hook', - ]) + ]), ); }); it('halts at down migration if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2724,14 +2751,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - down migration failed with: Error('down migration error')` + down migration failed with: Error('down migration error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', @@ -2739,12 +2766,12 @@ describe('unexpected-knex', function () { 'testUp hook', 'beforeDown hook', 'down migration', - ]) + ]), ); }); it('halts at testDown if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2781,14 +2808,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - testDown failed with: Error('testDown error')` + testDown failed with: Error('testDown error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', @@ -2797,13 +2824,13 @@ describe('unexpected-knex', function () { 'beforeDown hook', 'down migration', 'testDown hook', - ]) + ]), ); }); it('halts at the second up migration if it fails on the second run', function () { - var callOrder = []; - var firstRun = true; + const callOrder = []; + let firstRun = true; return expect( () => expect( @@ -2818,7 +2845,7 @@ describe('unexpected-knex', function () { return Promise.resolve(); } return Promise.reject( - new Error('second up migration error') + new Error('second up migration error'), ); }, down: () => { @@ -2845,14 +2872,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - up migration after down migration failed with: Error('second up migration error')` + up migration after down migration failed with: Error('second up migration error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', @@ -2862,12 +2889,12 @@ describe('unexpected-knex', function () { 'down migration', 'testDown hook', 'up migration', - ]) + ]), ); }); it('halts at after if it fails', function () { - var callOrder = []; + const callOrder = []; return expect( () => expect( @@ -2904,14 +2931,14 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - 'foo.js' + 'foo.js', ), 'to error with', dontIndent` expected ${knexOutputBlock} to apply migration 'foo.js' - after failed with: Error('after error')` + after failed with: Error('after error')`, ).then(() => expect(callOrder, 'to equal', [ 'beforeUp hook', @@ -2922,7 +2949,7 @@ describe('unexpected-knex', function () { 'testDown hook', 'up migration', 'after hook', - ]) + ]), ); }); }); @@ -2953,7 +2980,7 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '2-foo.js' + '2-foo.js', ).then(() => expect(knex, 'to have column', { foo: 'bar' })); }); @@ -2981,7 +3008,7 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '2-foo.js' + '2-foo.js', ).then(() => expect(knex, 'to have column', { foo: 'bar' })); }); @@ -3017,7 +3044,7 @@ describe('unexpected-knex', function () { }, }, 'to apply migration', - '2-foo.js' + '2-foo.js', ) .then(() => expect(knex, 'to have column', { foo: 'bar' })) .then(() => expect(knex, 'not to have table', 'bar'));