1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-30 02:59:11 -05:00
denoland-deno/tests/node_compat/test/es-module/test-esm-windows.js
Yoshiya Hinosawa fb24fd37c9
test: add node compat test cases (#27134)
This PR enables node compat test cases found passing by using the tool
added in #27122

The percentage of passing test case increases from 16.16% to 30.43% by
this change.
2024-12-04 11:37:20 +09:00

54 lines
1.6 KiB
JavaScript

// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
// 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 () => {
tmpdir.refresh();
const rel = (file) => tmpdir.resolve(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());