Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
],
"ignore": [
"src/assets"
]
],
"overrides": [{
"test": "./src/helpers/import-helper.js",
Comment thread
WikiRik marked this conversation as resolved.
"presets": [
["@babel/env", {
"exclude": ["proposal-dynamic-import"],
}]
],
}]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"pg": "latest",
"pg-hstore": "latest",
"prettier": "^2.4.1",
"semver": "^7.3.5",
"sequelize": "^6.9.0",
"sqlite3": "latest",
"through2": "^4.0.2"
Expand Down
20 changes: 11 additions & 9 deletions src/helpers/config-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from 'lodash';
import { promisify } from 'util';
import helpers from './index';
import getYArgs from '../core/yargs';
import importHelper from './import-helper';

const args = getYArgs().argv;

Expand All @@ -15,18 +16,19 @@ const api = {
init() {
return Promise.resolve()
.then(() => {
let config;

if (args.url) {
config = api.parseDbUrl(args.url);
return api.parseDbUrl(args.url);
} else {
try {
config = require(api.getConfigFile());
} catch (e) {
api.error = e;
}
return importHelper.importModule(api.getConfigFile());
}
})
.then((module) => module.default)
.catch(() => {
try {
return require(api.getConfigFile());
} catch (e) {
api.error = e;
}
return config;
})
.then((config) => {
if (typeof config === 'object' || config === undefined) {
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/import-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
importModule: function (module) {
return import(module);
},
};
57 changes: 57 additions & 0 deletions test/db/migrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const expect = require('expect.js');
const Support = require(__dirname + '/../support');
const helpers = require(__dirname + '/../support/helpers');
const gulp = require('gulp');
const semver = require('semver');
const _ = require('lodash');

[
Expand Down Expand Up @@ -293,6 +294,54 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
});
});

describeOnlyForESM(Support.getTestDialectTeaser('db:migrate'), () => {
describe('with config.mjs', () => {
const prepare = function (callback) {
const config = helpers.getTestConfig();
const configContent = 'export default ' + JSON.stringify(config);
let result = '';

return gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli('init'))
.pipe(helpers.removeFile('config/config.json'))
.pipe(helpers.copyMigration('createPerson.js'))
.pipe(helpers.overwriteFile(configContent, 'config/config.mjs'))
.pipe(helpers.runCli('db:migrate --config config/config.mjs'))
.on('error', (e) => {
callback(e);
})
.on('data', (data) => {
result += data.toString();
})
.on('end', () => {
callback(null, result);
});
};

it('creates a SequelizeMeta table', function (done) {
prepare(() => {
helpers.readTables(this.sequelize, (tables) => {
expect(tables).to.have.length(2);
expect(tables).to.contain('SequelizeMeta');
done();
});
});
});

it('creates the respective table', function (done) {
prepare(() => {
helpers.readTables(this.sequelize, (tables) => {
expect(tables).to.have.length(2);
expect(tables).to.contain('Person');
done();
});
});
});
});
});

describe(Support.getTestDialectTeaser('db:migrate'), () => {
describe('with config.json and url option', () => {
const prepare = function (callback) {
Expand Down Expand Up @@ -525,3 +574,11 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
});
});
});

function describeOnlyForESM(title, fn) {
if (semver.satisfies(process.version, '^12.20.0 || ^14.13.1 || >=16.0.0')) {
describe(title, fn);
} else {
describe.skip(title, fn);
}
}