-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
esm-utils.spec.js
46 lines (39 loc) · 1.08 KB
/
esm-utils.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const esmUtils = require('../../lib/nodejs/esm-utils');
const sinon = require('sinon');
const url = require('url');
describe('esm-utils', function () {
beforeEach(function () {
sinon.stub(esmUtils, 'doImport').resolves({});
});
afterEach(function () {
sinon.restore();
});
describe('loadFilesAsync()', function () {
it('should not decorate imported module if no decorator passed', async function () {
await esmUtils.loadFilesAsync(
['/foo/bar.mjs'],
() => {},
() => {}
);
expect(
esmUtils.doImport.firstCall.args[0].toString(),
'to be',
url.pathToFileURL('/foo/bar.mjs').toString()
);
});
it('should decorate imported module with passed decorator', async function () {
await esmUtils.loadFilesAsync(
['/foo/bar.mjs'],
() => {},
() => {},
x => `${x}?foo=bar`
);
expect(
esmUtils.doImport.firstCall.args[0].toString(),
'to be',
`${url.pathToFileURL('/foo/bar.mjs').toString()}?foo=bar`
);
});
});
});