Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor more tests to use cli-testlab (#3640)
- Loading branch information
Showing
8 changed files
with
132 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const sqlite3 = require('sqlite3'); | ||
const { expect } = require('chai'); | ||
const { execCommand } = require('cli-testlab'); | ||
const { getRootDir, setupFileHelper } = require('./cli-test-utils'); | ||
|
||
const KNEX = path.normalize(__dirname + '/../../bin/cli.js'); | ||
|
||
describe('migrate:latest', () => { | ||
before(() => { | ||
process.env.KNEX_PATH = '../knex.js'; | ||
}); | ||
|
||
let fileHelper; | ||
const rootDir = getRootDir(); | ||
const dbPath = path.resolve(rootDir, 'db'); | ||
beforeEach(() => { | ||
fileHelper = setupFileHelper(); | ||
fileHelper.registerForCleanup(dbPath); | ||
}); | ||
afterEach(() => { | ||
fileHelper.cleanup(); | ||
}); | ||
|
||
it('Run migrations', async () => { | ||
fileHelper.createFile( | ||
'migrations/000_create_rule_table.js', | ||
` | ||
exports.up = (knex)=> knex.schema.createTable('rules', (table)=> { | ||
table.string('name'); | ||
}); | ||
exports.down = (knex)=> knex.schema.dropTable('rules'); | ||
`, | ||
{ willBeCleanedUp: true, isPathAbsolute: false } | ||
); | ||
|
||
expect(fileHelper.fileExists(dbPath)).to.equal(false); | ||
await execCommand(`node ${KNEX} migrate:latest \ | ||
--client=sqlite3 --connection=${dbPath} \ | ||
--migrations-directory=${rootDir}/migrations \ | ||
create_rule_table`); | ||
expect(fileHelper.fileExists(dbPath)).to.equal(true); | ||
const db = await new sqlite3.Database(dbPath); | ||
|
||
const getPromise = new Promise((resolve, reject) => { | ||
db.get('SELECT name FROM knex_migrations', {}, (err, row) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
resolve(row); | ||
}); | ||
}); | ||
const row = await getPromise; | ||
expect(row.name).to.equal('000_create_rule_table.js'); | ||
db.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const { execCommand } = require('cli-testlab'); | ||
|
||
const KNEX = path.normalize(__dirname + '/../../bin/cli.js'); | ||
|
||
describe('seed:run', () => { | ||
before(() => { | ||
process.env.KNEX_PATH = '../knex.js'; | ||
}); | ||
|
||
it('prints non verbose logs', () => { | ||
return execCommand( | ||
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js`, | ||
{ | ||
expectedOutput: 'Ran 2 seed files', | ||
notExpectedOutput: ['first.js', 'second.js'], | ||
} | ||
); | ||
}); | ||
|
||
it('prints verbose logs', () => { | ||
return execCommand( | ||
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js --verbose`, | ||
{ | ||
expectedOutput: ['Ran 2 seed files', 'first.js', 'second.js'], | ||
} | ||
); | ||
}); | ||
|
||
it('runs specific file', () => { | ||
return execCommand( | ||
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-knexfile.js --specific=second.js`, | ||
{ | ||
expectedOutput: 'Ran 1 seed files', | ||
notExpectedOutput: ['first.js', 'second.js'], | ||
} | ||
); | ||
}); | ||
|
||
it('handles seeding errors correctly', () => { | ||
return execCommand( | ||
`node ${KNEX} seed:run --knexfile=test/jake-util/seeds-error-knexfile.js`, | ||
{ | ||
expectedErrorMessage: ['Error while executing', 'seeds.js', 'Boom'], | ||
} | ||
); | ||
}); | ||
|
||
it('seed:run runs "esm" files', () => { | ||
return execCommand( | ||
`node ${KNEX} --esm seed:run --knexfile=test/jake-util/knexfile-esm/knexfile.js`, | ||
{ | ||
expectedOutput: 'Ran 1 seed files', | ||
notExpectedOutput: ['first.js', 'second.js'], | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.