11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test ensures that JavaScript file that includes 41cb0ef41Sopenharmony_ci// a reserved Windows word can be loaded as ESM module 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst fs = require('fs').promises; 101cb0ef41Sopenharmony_ciconst path = require('path'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst imp = (file) => { 131cb0ef41Sopenharmony_ci return import(path.relative(__dirname, file).replace(/\\/g, '/')); 141cb0ef41Sopenharmony_ci}; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci(async () => { 171cb0ef41Sopenharmony_ci tmpdir.refresh(); 181cb0ef41Sopenharmony_ci const rel = (file) => path.join(tmpdir.path, file); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci { // Load a single script 211cb0ef41Sopenharmony_ci const file = rel('con.mjs'); 221cb0ef41Sopenharmony_ci await fs.writeFile(file, 'export default "ok"'); 231cb0ef41Sopenharmony_ci assert.strictEqual((await imp(file)).default, 'ok'); 241cb0ef41Sopenharmony_ci await fs.unlink(file); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci { // Load a module 281cb0ef41Sopenharmony_ci const entry = rel('entry.mjs'); 291cb0ef41Sopenharmony_ci const nmDir = rel('node_modules'); 301cb0ef41Sopenharmony_ci const mDir = rel('node_modules/con'); 311cb0ef41Sopenharmony_ci const pkg = rel('node_modules/con/package.json'); 321cb0ef41Sopenharmony_ci const script = rel('node_modules/con/index.mjs'); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci await fs.writeFile(entry, 'export {default} from "con"'); 351cb0ef41Sopenharmony_ci await fs.mkdir(nmDir); 361cb0ef41Sopenharmony_ci await fs.mkdir(mDir); 371cb0ef41Sopenharmony_ci await fs.writeFile(pkg, '{"main":"index.mjs"}'); 381cb0ef41Sopenharmony_ci await fs.writeFile(script, 'export default "ok"'); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci assert.strictEqual((await imp(entry)).default, 'ok'); 411cb0ef41Sopenharmony_ci await fs.unlink(script); 421cb0ef41Sopenharmony_ci await fs.unlink(pkg); 431cb0ef41Sopenharmony_ci await fs.rmdir(mDir); 441cb0ef41Sopenharmony_ci await fs.rmdir(nmDir); 451cb0ef41Sopenharmony_ci await fs.unlink(entry); 461cb0ef41Sopenharmony_ci } 471cb0ef41Sopenharmony_ci})().then(common.mustCall()); 48