@@ -3,6 +3,7 @@ const expect = require('expect.js');
33const Support = require ( __dirname + '/../support' ) ;
44const helpers = require ( __dirname + '/../support/helpers' ) ;
55const gulp = require ( 'gulp' ) ;
6+ const semver = require ( 'semver' ) ;
67const _ = require ( 'lodash' ) ;
78
89[
@@ -25,7 +26,7 @@ const _ = require('lodash');
2526 let configPath = 'config/' ;
2627 let migrationFile = options . migrationFile || 'createPerson' ;
2728 const config = _ . assign ( { } , helpers . getTestConfig ( ) , options . config ) ;
28- let configContent = JSON . stringify ( config ) ;
29+ let configContent = JSON . stringify ( config , null , 2 ) ;
2930
3031 if ( ! migrationFile . match ( / \. ( c j s | t s ) $ / ) ) {
3132 migrationFile = migrationFile + '.js' ;
@@ -70,7 +71,11 @@ const _ = require('lodash');
7071 it ( 'creates a SequelizeMeta table' , function ( done ) {
7172 const self = this ;
7273
73- prepare ( ( ) => {
74+ prepare ( ( e ) => {
75+ if ( e ) {
76+ return done ( e ) ;
77+ }
78+
7479 helpers . readTables ( self . sequelize , ( tables ) => {
7580 expect ( tables ) . to . have . length ( 2 ) ;
7681 expect ( tables ) . to . contain ( 'SequelizeMeta' ) ;
@@ -293,6 +298,58 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
293298 } ) ;
294299} ) ;
295300
301+ describeOnlyForESM ( Support . getTestDialectTeaser ( 'db:migrate' ) , ( ) => {
302+ describe ( 'with config.mjs' , ( ) => {
303+ const prepare = function ( callback ) {
304+ const config = helpers . getTestConfig ( ) ;
305+ const configContent = 'export default ' + JSON . stringify ( config ) ;
306+ let result = '' ;
307+
308+ return gulp
309+ . src ( Support . resolveSupportPath ( 'tmp' ) )
310+ . pipe ( helpers . clearDirectory ( ) )
311+ . pipe ( helpers . runCli ( 'init' ) )
312+ . pipe ( helpers . removeFile ( 'config/config.json' ) )
313+ . pipe ( helpers . copyMigration ( 'createPerson.js' ) )
314+ . pipe ( helpers . overwriteFile ( configContent , 'config/config.mjs' ) )
315+ . pipe ( helpers . runCli ( 'db:migrate --config config/config.mjs' ) )
316+ . on ( 'error' , ( e ) => {
317+ callback ( e ) ;
318+ } )
319+ . on ( 'data' , ( data ) => {
320+ result += data . toString ( ) ;
321+ } )
322+ . on ( 'end' , ( ) => {
323+ callback ( null , result ) ;
324+ } ) ;
325+ } ;
326+
327+ it ( 'creates a SequelizeMeta table' , function ( done ) {
328+ prepare ( ( e ) => {
329+ if ( e ) {
330+ return done ( e ) ;
331+ }
332+
333+ helpers . readTables ( this . sequelize , ( tables ) => {
334+ expect ( tables ) . to . have . length ( 2 ) ;
335+ expect ( tables ) . to . contain ( 'SequelizeMeta' ) ;
336+ done ( ) ;
337+ } ) ;
338+ } ) ;
339+ } ) ;
340+
341+ it ( 'creates the respective table' , function ( done ) {
342+ prepare ( ( ) => {
343+ helpers . readTables ( this . sequelize , ( tables ) => {
344+ expect ( tables ) . to . have . length ( 2 ) ;
345+ expect ( tables ) . to . contain ( 'Person' ) ;
346+ done ( ) ;
347+ } ) ;
348+ } ) ;
349+ } ) ;
350+ } ) ;
351+ } ) ;
352+
296353describe ( Support . getTestDialectTeaser ( 'db:migrate' ) , ( ) => {
297354 describe ( 'with config.json and url option' , ( ) => {
298355 const prepare = function ( callback ) {
@@ -525,3 +582,11 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
525582 } ) ;
526583 } ) ;
527584} ) ;
585+
586+ function describeOnlyForESM ( title , fn ) {
587+ if ( semver . satisfies ( process . version , '^12.20.0 || ^14.13.1 || >=16.0.0' ) ) {
588+ describe ( title , fn ) ;
589+ } else {
590+ describe . skip ( title , fn ) ;
591+ }
592+ }
0 commit comments