Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: add --stub option to migration:make (#3316)
- Loading branch information
1 parent
a0e9be5
commit 2b63332
Showing
7 changed files
with
464 additions
and
214 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
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,56 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const { FileTestHelper } = require('cli-testlab'); | ||
|
||
function migrationStubOptionSetup(fileHelper) { | ||
const migrationGlobPath = 'test/jake-util/knexfile_migrations/*_somename.js'; | ||
|
||
fileHelper.registerGlobForCleanup(migrationGlobPath); | ||
fileHelper.createFile( | ||
process.cwd() + '/knexfile.js', | ||
` | ||
module.exports = { | ||
development: { | ||
client: 'sqlite3', | ||
connection: { | ||
filename: __dirname + '/test/jake-util/test.sqlite3', | ||
}, | ||
migrations: { | ||
directory: __dirname + '/test/jake-util/knexfile_migrations', | ||
}, | ||
} | ||
}; | ||
`, | ||
{ isPathAbsolute: true } | ||
); | ||
|
||
return { migrationGlobPath }; | ||
} | ||
|
||
function migrationMatchesStub(stubPath, migrationGlobPath, fileHelper) { | ||
// accepts full or relative stub path | ||
const relativeStubPath = stubPath.replace('test/jake-util/', ''); | ||
const stubContent = fileHelper.getFileTextContent(relativeStubPath); | ||
const [migrationContent] = fileHelper.getFileGlobTextContent( | ||
migrationGlobPath | ||
); | ||
|
||
return stubContent === migrationContent; | ||
} | ||
|
||
function setupFileHelper() { | ||
const fileHelper = new FileTestHelper( | ||
path.resolve(__dirname, '../jake-util') | ||
); | ||
fileHelper.deleteFile('test.sqlite3'); | ||
fileHelper.registerForCleanup('test.sqlite3'); | ||
|
||
return fileHelper; | ||
} | ||
|
||
module.exports = { | ||
migrationStubOptionSetup, | ||
migrationMatchesStub, | ||
setupFileHelper, | ||
}; |
Oops, something went wrong.