-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
esm.spec.js
105 lines (90 loc) · 3.09 KB
/
esm.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'use strict';
var path = require('path');
const {runMochaJSON: run, runMochaAsync} = require('./helpers');
var args = [];
describe('esm', function () {
it('should pass a passing esm test that uses esm', function (done) {
var fixture = 'esm/esm-success.fixture.mjs';
run(fixture, args, function (err, result) {
if (err) {
done(err);
return;
}
expect(result, 'to have passed test count', 1);
done();
});
});
it('should fail a failing esm test that uses esm', function (done) {
var fixture = 'esm/esm-failure.fixture.mjs';
run(fixture, args, function (err, result) {
if (err) {
done(err);
return;
}
expect(result, 'to have failed test count', 1).and(
'to have failed test',
'should use a function from an esm, and fail'
);
done();
});
});
it('should show file location when there is a syntax error in the test', async function () {
var fixture = 'esm/syntax-error/esm-syntax-error.fixture.mjs';
const err = await runMochaAsync(fixture, args, {stdio: 'pipe'}).catch(
err => err
);
expect(err.output, 'to contain', 'SyntaxError').and(
'to contain',
'esm-syntax-error.fixture.mjs'
);
});
it('should recognize esm files ending with .js due to package.json type flag', function (done) {
var fixture = 'esm/js-folder/esm-in-js.fixture.js';
run(fixture, args, function (err, result) {
if (err) {
done(err);
return;
}
expect(result, 'to have passed test count', 1);
done();
});
});
it('should enable requiring/loading a cjs module with "dir" as filename', async function () {
var fixture = 'esm/test-that-uses-dir-cjs-require.fixture.js';
const result = await runMochaAsync(
fixture,
['--require', path.resolve(__dirname, './fixtures/esm/dir-cjs-require')],
{stdio: 'pipe'}
);
expect(result, 'to have passed test count', 1);
});
it('should throw an ERR_MODULE_NOT_FOUND and not ERR_REQUIRE_ESM if file imports a non-existing module', async function () {
const fixture =
'esm/type-module/test-that-imports-non-existing-module.fixture.js';
const err = await runMochaAsync(fixture, ['--unhandled-rejections=warn'], {
stdio: 'pipe'
}).catch(err => err);
expect(err.output, 'to contain', 'ERR_MODULE_NOT_FOUND').and(
'to contain',
'test-that-imports-non-existing-module'
);
});
it('should throw an ERR_MODULE_NOT_FOUND and not ERR_REQUIRE_ESM if file imports a non-existing module with a loader', async function () {
const fixture =
'esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts';
const err = await runMochaAsync(
fixture,
[
'--unhandled-rejections=warn',
'--loader=./test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.mjs'
],
{
stdio: 'pipe'
}
).catch(err => err);
expect(err.output, 'to contain', 'ERR_MODULE_NOT_FOUND').and(
'to contain',
'non-existent-package'
);
});
});