1'use strict'; 2 3// This test ensures that JavaScript file that includes 4// a reserved Windows word can be loaded as ESM module 5 6const common = require('../common'); 7const tmpdir = require('../common/tmpdir'); 8const assert = require('assert'); 9const fs = require('fs').promises; 10const path = require('path'); 11 12const imp = (file) => { 13 return import(path.relative(__dirname, file).replace(/\\/g, '/')); 14}; 15 16(async () => { 17 tmpdir.refresh(); 18 const rel = (file) => path.join(tmpdir.path, file); 19 20 { // Load a single script 21 const file = rel('con.mjs'); 22 await fs.writeFile(file, 'export default "ok"'); 23 assert.strictEqual((await imp(file)).default, 'ok'); 24 await fs.unlink(file); 25 } 26 27 { // Load a module 28 const entry = rel('entry.mjs'); 29 const nmDir = rel('node_modules'); 30 const mDir = rel('node_modules/con'); 31 const pkg = rel('node_modules/con/package.json'); 32 const script = rel('node_modules/con/index.mjs'); 33 34 await fs.writeFile(entry, 'export {default} from "con"'); 35 await fs.mkdir(nmDir); 36 await fs.mkdir(mDir); 37 await fs.writeFile(pkg, '{"main":"index.mjs"}'); 38 await fs.writeFile(script, 'export default "ok"'); 39 40 assert.strictEqual((await imp(entry)).default, 'ok'); 41 await fs.unlink(script); 42 await fs.unlink(pkg); 43 await fs.rmdir(mDir); 44 await fs.rmdir(nmDir); 45 await fs.unlink(entry); 46 } 47})().then(common.mustCall()); 48