Skip to content

Commit

Permalink
update migration template test
Browse files Browse the repository at this point in the history
  • Loading branch information
okv committed Jan 23, 2020
1 parent 67f889d commit 97ce9a2
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions test/lib/migrationTemplates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ const promisify = require('es6-promisify').promisify;
const test = testUtils.test;

test('migrationTemplates', (assert) => {
const migrationTemplatesPath = pathUtils.resolve(
const templatesPath = pathUtils.resolve(
__dirname,
'../../lib/migrationTemplates'
);
const tryMigrationTemplate = (filename) => {
return Promise.resolve()
// eslint-disable-next-line import/no-dynamic-require
.then(() => require(pathUtils.join(migrationTemplatesPath, filename)))
.then((migration) => {
return Promise.all([
migration.migrate({}),
migration.rollback({})
]);
});
const templatePath = pathUtils.join(templatesPath, filename);
let migration;
assert.doesNotThrow(
() => {
// eslint-disable-next-line import/no-dynamic-require
migration = require(templatePath);
},
`${filename} template should be requireble`
);

assert.equal(
Array.isArray(migration.tags),
true,
`${filename} template tags should be an array`
);

return Promise.all([
migration.migrate({}),
migration.rollback({})
]);
};
const readdir = promisify(fs.readdir);
const nodeMajor = Number(process.versions.node.split('.')[0]);

return Promise.resolve()
.then(() => readdir(migrationTemplatesPath))
.then(() => readdir(templatesPath))
.then((filenames) => {
assert.equal(
filenames.indexOf('promises.js') !== -1,
Expand Down Expand Up @@ -55,14 +66,5 @@ test('migrationTemplates', (assert) => {
tryMigrationTemplate('promises.js')
]);
}
})
.then(() => {
if (nodeMajor >= 8) {
assert.pass('promises template should be requireble');
assert.pass('async template should be requireble');
} else {
assert.pass('promises template should be requireble');
assert.skip('do not require async template on nodejs < 8');
}
});
});

0 comments on commit 97ce9a2

Please sign in to comment.