-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ZYSzys
authored
Jun 21, 2020
1 parent
b7d8c97
commit bbcde76
Showing
4 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ coverage | |
npm-debug.log | ||
.idea | ||
*.iml | ||
dist |
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,36 @@ | ||
const assert = require('assert'); | ||
|
||
let importESM = () => {}; | ||
|
||
describe('Load with esm', () => { | ||
before(function(){ | ||
// ESM support is flagged on v12.x. | ||
const majorVersion = +process.version.split('.')[0].slice(1); | ||
if (majorVersion < 12) { | ||
this.skip(); | ||
} else { | ||
// eslint-disable-next-line no-eval | ||
importESM = eval('(specifier) => import(specifier)'); | ||
} | ||
}); | ||
|
||
it('should default export koa', async() => { | ||
const exported = await importESM('koa'); | ||
const required = require('../'); | ||
assert.strictEqual(exported.default, required); | ||
}); | ||
|
||
it('should match exports own property names', async() => { | ||
const exported = new Set(Object.getOwnPropertyNames(await importESM('koa'))); | ||
const required = new Set(Object.getOwnPropertyNames(require('../'))); | ||
|
||
// Remove constructor properties + default export. | ||
for (const k of ['prototype', 'length', 'name']) { | ||
required.delete(k); | ||
} | ||
exported.delete('default'); | ||
|
||
assert.strictEqual(exported.size, required.size); | ||
assert.strictEqual([...exported].every(property => required.has(property)), true); | ||
}); | ||
}); |