-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
142 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const _ = require('underscore'); | ||
|
||
module.exports = function _loadModule(path) { | ||
const {esModules} = this.params; | ||
|
||
return Promise.resolve() | ||
.then(() => esModules ? import(path) : require(path)) | ||
.then((loadedModule) => { | ||
let result = loadedModule.default || loadedModule; | ||
|
||
if (_(result).isObject() && !_(result).isFunction()) { | ||
result = _({}).extend(result); | ||
} | ||
|
||
return result; | ||
}) | ||
.catch((err) => { | ||
throw new Error( | ||
`Error loading module "${path}":\n ${err.stack || err.message}` | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const tap = require('tap'); | ||
const expect = require('expect.js'); | ||
const fs = require('fs'); | ||
const pathUtils = require('path'); | ||
const testUtils = require('../../../testUtils'); | ||
|
||
tap.mochaGlobals(); | ||
|
||
describe('migrator _loadConfig with invalid cjs module', () => { | ||
let migrator; | ||
let testEnv; | ||
let configPath; | ||
|
||
before(() => { | ||
return Promise.resolve() | ||
.then(() => { | ||
return testUtils.createEnv({migratorParams: {init: false}}); | ||
}) | ||
.then((createdTestEnv) => { | ||
testEnv = createdTestEnv; | ||
migrator = testEnv.migrator; | ||
}); | ||
}); | ||
|
||
before(() => { | ||
return Promise.resolve() | ||
.then(() => { | ||
// could be placed to any other dir | ||
configPath = pathUtils.join(testEnv.dir, 'config.js'); | ||
return fs.promises.writeFile( | ||
configPath, | ||
'notValid.exports = 1', | ||
'utf-8' | ||
); | ||
}); | ||
}); | ||
|
||
after(() => fs.promises.unlink(configPath)); | ||
|
||
after(() => testUtils.destroyEnv(testEnv)); | ||
|
||
it('should be called with error', () => { | ||
return Promise.resolve() | ||
.then(() => migrator._loadConfig({path: configPath, defaultPath: ''})) | ||
.then((result) => { | ||
throw new Error(`Error expected, but got result: ${result}`); | ||
}) | ||
.catch((err) => { | ||
expect(err).ok(); | ||
expect(err).an(Error); | ||
expect(err.message).match(new RegExp( | ||
`Error while loading config "${configPath}" as json:` | ||
)); | ||
expect(err.message).match(new RegExp( | ||
'and as module:' | ||
)); expect(err.message).match(new RegExp( | ||
`Error loading module "${configPath}":` | ||
)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.