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
Refactor more tests to use cli-testlab #3640
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original implementation didn't support sqlite paths to begin with drive letter, e. g. "c:/knex/migrations"