-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-esm-import-meta.mjs
More file actions
32 lines (26 loc) · 1.17 KB
/
test-esm-import-meta.mjs
File metadata and controls
32 lines (26 loc) · 1.17 KB
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
import '../common/index.mjs';
import assert from 'assert';
import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
assert.strictEqual(Object.getPrototypeOf(import.meta), null);
const keys = ['dirname', 'filename', 'main', 'resolve', 'url'];
assert.deepStrictEqual(Reflect.ownKeys(import.meta), keys);
const descriptors = Object.getOwnPropertyDescriptors(import.meta);
for (const descriptor of Object.values(descriptors)) {
delete descriptor.value; // Values are verified below.
assert.deepStrictEqual(descriptor, {
enumerable: true,
writable: true,
configurable: true,
});
}
const filePath = fileURLToPath(import.meta.url);
assert.ok(path.isAbsolute(filePath));
assert.strictEqual(import.meta.url, pathToFileURL(filePath).href);
const suffix = path.join('test', 'es-module', 'test-esm-import-meta.mjs');
assert.ok(filePath.endsWith(suffix));
assert.strictEqual(import.meta.filename, filePath);
assert.strictEqual(import.meta.dirname, path.dirname(filePath));
// Verify that `data:` imports do not behave like `file:` imports.
import dataDirname from 'data:text/javascript,export default "dirname" in import.meta';
assert.strictEqual(dataDirname, false);