Skip to content

Commit c6f86f3

Browse files
committed
Port experimental-specifier-resolution tests from Node codebase
1 parent fea414b commit c6f86f3

File tree

16 files changed

+233
-1
lines changed

16 files changed

+233
-1
lines changed

commonjs-extension-resolution-loader/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "./loader.js",
77
"scripts": {
88
"start": "npm test",
9-
"test": "node test/basic.js"
9+
"test": "node test/basic.js && node test/test-esm-specifiers.js && node test/test-esm-specifiers-symlink.js"
1010
},
1111
"author": "Geoffrey Booth <[email protected]>",
1212
"license": "MIT",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Ported from https://github.com/nodejs/node/blob/45f2258f74117e27ffced434a98ad6babc14f7fa/test/common/index.js
2+
3+
import { spawn } from 'node:child_process';
4+
5+
6+
export function spawnPromisified(...args) {
7+
let stderr = '';
8+
let stdout = '';
9+
10+
const child = spawn(...args);
11+
child.stderr.setEncoding('utf8');
12+
child.stderr.on('data', (data) => { stderr += data; });
13+
child.stdout.setEncoding('utf8');
14+
child.stdout.on('data', (data) => { stdout += data; });
15+
16+
return new Promise((resolve, reject) => {
17+
child.on('close', (code, signal) => {
18+
resolve({
19+
code,
20+
signal,
21+
stderr,
22+
stdout,
23+
});
24+
});
25+
child.on('error', (code, signal) => {
26+
reject({
27+
code,
28+
signal,
29+
stderr,
30+
stdout,
31+
});
32+
});
33+
});
34+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import explicit from 'explicit-main';
2+
import implicit from 'implicit-main';
3+
import implicitModule from 'implicit-main-type-module';
4+
import noMain from 'no-main-field';
5+
6+
function getImplicitCommonjs () {
7+
return import('implicit-main-type-commonjs');
8+
}
9+
10+
export {explicit, implicit, implicitModule, getImplicitCommonjs, noMain};
11+
export default 'success';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'a';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const b = 'b';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
one: 1,
3+
two: 2,
4+
three: 3
5+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// js file that is common.js
2+
import a from './a.js';
3+
// ESM with named export
4+
import {b} from './b.mjs';
5+
// import 'c.cjs';
6+
import cjs from './c.cjs';
7+
// proves cross boundary fun bits
8+
import jsAsEsm from '../package-type-module/a.js';
9+
10+
// named export from core
11+
import {strictEqual, deepStrictEqual} from 'assert';
12+
13+
strictEqual(a, jsAsEsm);
14+
strictEqual(b, 'b');
15+
deepStrictEqual(cjs, {
16+
one: 1,
17+
two: 2,
18+
three: 3
19+
});
20+
21+
export default 'commonjs';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'a'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const b = 'b';

0 commit comments

Comments
 (0)