mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
3daa0a6c04
PR-URL: https://github.com/nodejs/node/pull/48740 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
import '../common/index.mjs';
|
|
import assert from 'assert';
|
|
|
|
assert.strictEqual(Object.getPrototypeOf(import.meta), null);
|
|
|
|
const keys = ['dirname', 'filename', '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 urlReg = /^file:\/\/\/.*\/test\/es-module\/test-esm-import-meta\.mjs$/;
|
|
assert(import.meta.url.match(urlReg));
|
|
|
|
// Match *nix paths: `/some/path/test/es-module`
|
|
// Match Windows paths: `d:\\some\\path\\test\\es-module`
|
|
const dirReg = /^(\/|\w:\\).*(\/|\\)test(\/|\\)es-module$/;
|
|
assert.match(import.meta.dirname, dirReg);
|
|
|
|
// Match *nix paths: `/some/path/test/es-module/test-esm-import-meta.mjs`
|
|
// Match Windows paths: `d:\\some\\path\\test\\es-module\\test-esm-import-meta.js`
|
|
const fileReg = /^(\/|\w:\\).*(\/|\\)test(\/|\\)es-module(\/|\\)test-esm-import-meta\.mjs$/;
|
|
assert.match(import.meta.filename, fileReg);
|
|
|
|
// 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);
|