diff options
author | Thomas <hakerh403@gmail.com> | 2019-09-16 10:45:05 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-10-03 20:46:53 -0700 |
commit | 6265e4166aa7a7a7697d52f3a528f3372226b0c9 (patch) | |
tree | d7c380ef8c07002fd5412072881b8678d9d8c114 /test/es-module | |
parent | 1e1285926f35558f8ad1dad5fad2040ce576f46e (diff) | |
download | node-new-6265e4166aa7a7a7697d52f3a528f3372226b0c9.tar.gz |
src: fix ESM path resolution on Windows
Windows has some reserved file names such as "con", "prn",
"nul", etc. Such files can be accessed only if the path is
prefixed with "\\.\"
PR-URL: https://github.com/nodejs/node/pull/29574
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Diffstat (limited to 'test/es-module')
-rw-r--r-- | test/es-module/test-esm-windows.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/es-module/test-esm-windows.js b/test/es-module/test-esm-windows.js new file mode 100644 index 0000000000..64ba1249a7 --- /dev/null +++ b/test/es-module/test-esm-windows.js @@ -0,0 +1,49 @@ +'use strict'; + +// Flags: --experimental-modules +// This test ensures that JavaScript file that includes +// a reserved Windows word can be loaded as ESM module + +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const assert = require('assert'); +const fs = require('fs').promises; +const path = require('path'); + +const imp = (file) => { + return import(path.relative(__dirname, file).replace(/\\/g, '/')); +}; + +(async () => { + const tmp = tmpdir.path; + await fs.mkdir(tmp).catch(() => {}); + const rel = (file) => path.join(tmp, file); + + { // Load a single script + const file = rel('con.mjs'); + await fs.writeFile(file, 'export default "ok"'); + assert.strictEqual((await imp(file)).default, 'ok'); + await fs.unlink(file); + } + + { // Load a module + const entry = rel('entry.mjs'); + const nmDir = rel('node_modules'); + const mDir = rel('node_modules/con'); + const pkg = rel('node_modules/con/package.json'); + const script = rel('node_modules/con/index.mjs'); + + await fs.writeFile(entry, 'export {default} from "con"'); + await fs.mkdir(nmDir); + await fs.mkdir(mDir); + await fs.writeFile(pkg, '{"main":"index.mjs"}'); + await fs.writeFile(script, 'export default "ok"'); + + assert.strictEqual((await imp(entry)).default, 'ok'); + await fs.unlink(script); + await fs.unlink(pkg); + await fs.rmdir(mDir); + await fs.rmdir(nmDir); + await fs.unlink(entry); + } +})().then(common.mustCall()); |