/
test-esm-undefined-cjs-global-like-variables.js
42 lines (38 loc) · 1.3 KB
/
test-esm-undefined-cjs-global-like-variables.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
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { pathToFileURL } = require('url');
assert.rejects(
import('data:text/javascript,require;'),
/require is not defined in ES module scope, you can use import instead$/
).then(common.mustCall());
assert.rejects(
import('data:text/javascript,exports={};'),
/exports is not defined in ES module scope$/
).then(common.mustCall());
assert.rejects(
import('data:text/javascript,require_custom;'),
/^(?!in ES module scope)(?!use import instead).*$/
).then(common.mustCall());
const pkgUrl = pathToFileURL(fixtures.path('/es-modules/package-type-module/'));
assert.rejects(
import(new URL('./cjs.js', pkgUrl)),
/use the '\.cjs' file extension/
).then(common.mustCall());
assert.rejects(
import(new URL('./cjs.js#target', pkgUrl)),
/use the '\.cjs' file extension/
).then(common.mustCall());
assert.rejects(
import(new URL('./cjs.js?foo=bar', pkgUrl)),
/use the '\.cjs' file extension/
).then(common.mustCall());
assert.rejects(
import(new URL('./cjs.js?foo=bar#target', pkgUrl)),
/use the '\.cjs' file extension/
).then(common.mustCall());
assert.rejects(
import('data:text/javascript,require;//.js'),
/^(?!use the '\.cjs' file extension).*$/
).then(common.mustCall());