-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix knexfile resolution. Add missing test (#2923)
* Fix knexfile resolution. Add missing test * Try fixing Jake test execution * Avoid having non-test files in jake folder * Fix test compatibility with Node 6 * Fix the fix
- Loading branch information
Showing
6 changed files
with
102 additions
and
5 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,53 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable no-console */ | ||
|
||
const os = require('os'); | ||
const fs = require('fs'); | ||
const rimrafSync = require('rimraf').sync; | ||
|
||
function assertExec(cmd, desc) { | ||
desc = desc || 'Run ' + cmd; | ||
return new Promise((resolve, reject) => { | ||
let stderr = ''; | ||
console.log(`Executing: ${cmd}`); | ||
const bin = jake.createExec([cmd]); | ||
bin.addListener('error', (msg, code) => | ||
reject(Error(desc + ' FAIL. ' + stderr)) | ||
); | ||
bin.addListener('cmdEnd', resolve); | ||
bin.addListener('stderr', (data) => (stderr += data.toString())); | ||
bin.run(); | ||
}); | ||
} | ||
|
||
function test(taskList, description, func) { | ||
const tmpDirPath = os.tmpdir() + '/knex-test-'; | ||
rimrafSync(tmpDirPath); | ||
const tempFolder = fs.mkdtempSync(tmpDirPath); | ||
desc(description); | ||
const taskName = description.replace(/[^a-z0-9]/g, ''); | ||
taskList.push(taskName); | ||
task(taskName, { async: true }, () => { | ||
let itFails = false; | ||
func(tempFolder) | ||
.then(() => { | ||
console.log('☑ ' + description); | ||
}) | ||
.catch((err) => { | ||
console.log('☒ ' + err.message); | ||
itFails = true; | ||
}) | ||
.then(() => { | ||
rimrafSync(tmpDirPath); | ||
rimrafSync('test/jake/test.sqlite3'); | ||
if (itFails) { | ||
process.exit(1); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
assertExec, | ||
test, | ||
}; |
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,9 @@ | ||
module.exports = { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: __dirname + '/../test.sqlite3', | ||
}, | ||
migrations: { | ||
directory: __dirname + '/../knexfile_migrations', | ||
}, | ||
}; |
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,9 @@ | ||
exports.up = (knex) => { | ||
return knex.schema.createTable('rules', (table) => { | ||
table.string('name'); | ||
}); | ||
}; | ||
|
||
exports.down = (knex) => { | ||
return knex.schema.dropTable('rules'); | ||
}; |
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,23 @@ | ||
#!/usr/bin/env jake | ||
'use strict'; | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable no-console */ | ||
|
||
const path = require('path'); | ||
const { | ||
assertExec, | ||
test, | ||
} = require('../jake-util/helpers/migrationtesthelper'); | ||
|
||
const KNEX = path.normalize(__dirname + '/../../bin/cli.js'); | ||
|
||
const taskList = []; | ||
/* * * TESTS * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
|
||
test(taskList, 'Run migrations with knexfile passed', (temp) => { | ||
return assertExec( | ||
`node ${KNEX} migrate:latest --knexfile=../test/jake-util/knexfile/knexfile.js` | ||
); | ||
}); | ||
|
||
task('default', taskList); |
461868b
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.
I am having problems with knexfile with version "knex": "^0.16.0-next5"
In version 0.15.2 I just ran "npx knex migrate:latest" inside folder containing knexfile and everything works like a charm. But now, the same command tells that I need to pass knexfile argument, and when I did it, tells me that could't find that "require".
So I debugged and I find out that knexfile is resolving inside node_modules directory.
I am running on Windows 10.
This is my lauch.json I used with VS Code to debugging
@kibertoad can you help?
461868b
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.
@joselcvarela Thank you for reproduction. This is a regression in next5, I hope to fix it tonight and then we will be able to release stable 0.16.0 soon.
461868b
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.
@joselcvarela Could you try with the code from #2935 ? I hope I fixed the issue, would appreciate if you could test it.
461868b
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.
@joselcvarela Please try 0.16.1-next1 - should resolve the issue.