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-10-13 16:49:53 +05:30
|
|
|
function seedStubOptionSetup(fileHelper) {
|
|
|
|
const seedGlobPath = 'test/jake-util/knexfile_seeds/*.js';
|
|
|
|
|
|
|
|
fileHelper.registerGlobForCleanup(seedGlobPath);
|
|
|
|
fileHelper.createFile(
|
|
|
|
process.cwd() + '/knexfile.js',
|
|
|
|
`
|
|
|
|
module.exports = {
|
|
|
|
development: {
|
|
|
|
client: 'sqlite3',
|
|
|
|
connection: {
|
|
|
|
filename: __dirname + '/test/jake-util/test.sqlite3',
|
|
|
|
},
|
|
|
|
seeds: {
|
|
|
|
directory: __dirname + '/test/jake-util/knexfile_seeds',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
{ isPathAbsolute: true }
|
|
|
|
);
|
|
|
|
|
|
|
|
return { seedGlobPath };
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectContentMatchesStub(stubPath, globPath, 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);
|
2019-10-25 20:17:26 +02:00
|
|
|
const [content] = fileHelper.getFileGlobTextContent(globPath);
|
2019-07-04 20:08:01 +00:00
|
|
|
|
2019-10-13 16:49:53 +05:30
|
|
|
expect(content).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-10-13 16:49:53 +05:30
|
|
|
expectContentMatchesStub,
|
2019-07-04 20:08:01 +00:00
|
|
|
migrationStubOptionSetup,
|
2019-10-13 16:49:53 +05:30
|
|
|
seedStubOptionSetup,
|
2019-07-04 20:08:01 +00:00
|
|
|
setupFileHelper,
|
|
|
|
};
|