2019-07-04 20:08:01 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const { FileTestHelper } = require('cli-testlab');
|
2019-07-10 22:45:47 +03:00
|
|
|
const { expect } = require('chai');
|
2019-07-04 20:08:01 +00:00
|
|
|
|
|
|
|
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 };
|
|
|
|
}
|
|
|
|
|
2019-07-10 22:45:47 +03:00
|
|
|
function expectMigrationMatchesStub(stubPath, migrationGlobPath, fileHelper) {
|
2019-07-04 20:08:01 +00:00
|
|
|
// accepts full or relative stub path
|
|
|
|
const relativeStubPath = stubPath.replace('test/jake-util/', '');
|
|
|
|
const stubContent = fileHelper.getFileTextContent(relativeStubPath);
|
|
|
|
const [migrationContent] = fileHelper.getFileGlobTextContent(
|
|
|
|
migrationGlobPath
|
|
|
|
);
|
|
|
|
|
2019-07-10 22:45:47 +03:00
|
|
|
expect(migrationContent).equals(stubContent);
|
2019-07-04 20:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupFileHelper() {
|
|
|
|
const fileHelper = new FileTestHelper(
|
|
|
|
path.resolve(__dirname, '../jake-util')
|
|
|
|
);
|
|
|
|
fileHelper.deleteFile('test.sqlite3');
|
|
|
|
fileHelper.registerForCleanup('test.sqlite3');
|
|
|
|
|
|
|
|
return fileHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2019-07-10 22:45:47 +03:00
|
|
|
expectMigrationMatchesStub,
|
2019-07-04 20:08:01 +00:00
|
|
|
migrationStubOptionSetup,
|
|
|
|
setupFileHelper,
|
|
|
|
};
|