GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: deflake `test-esm-loader-resolve-type` · nodejs/node@19d3ce2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/fixtures/es-module-loaders
    • hook-resolve-type-loader.mjs
    • hook-resolve-type.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/fixtures/es-module-loaders/hook-resolve-type-loader.mjs‎

Copy file name to clipboardExpand all lines: test/fixtures/es-module-loaders/hook-resolve-type-loader.mjs
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
/** @type {MessagePort} */
2-
let port;
3-
export function initialize(data) {
4-
port = data.port;
1+
/** @type {Uint8Array} */
2+
let data;
3+
/** @type {number} */
4+
let ESM_MODULE_INDEX;
5+
/** @type {number} */
6+
let CJS_MODULE_INDEX;
7+
8+
export function initialize({ sab, ESM_MODULE_INDEX:e, CJS_MODULE_INDEX:c }) {
9+
data = new Uint8Array(sab);
10+
ESM_MODULE_INDEX = e;
11+
CJS_MODULE_INDEX = c;
512
}
613

714
export async function resolve(specifier, context, next) {
815
const nextResult = await next(specifier, context);
916
const { format } = nextResult;
1017

1118
if (format === 'module' || specifier.endsWith('.mjs')) {
12-
port.postMessage({ type: 'module' });
19+
Atomics.add(data, ESM_MODULE_INDEX, 1);
1320
} else if (format == null || format === 'commonjs') {
14-
port.postMessage({ type: 'commonjs' });
21+
Atomics.add(data, CJS_MODULE_INDEX, 1);
1522
}
1623

1724
return nextResult;
Collapse file

‎test/fixtures/es-module-loaders/hook-resolve-type.mjs‎

Copy file name to clipboard
+10-22Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
11
import * as fixtures from '../../common/fixtures.mjs';
22
import { register } from 'node:module';
3-
import { MessageChannel } from 'node:worker_threads';
43

5-
let importedESM = 0;
6-
let importedCJS = 0;
4+
const sab = new SharedArrayBuffer(2);
5+
const data = new Uint8Array(sab);
6+
7+
const ESM_MODULE_INDEX = 0
8+
const CJS_MODULE_INDEX = 1
9+
710
export function getModuleTypeStats() {
11+
const importedESM = Atomics.load(data, ESM_MODULE_INDEX);
12+
const importedCJS = Atomics.load(data, CJS_MODULE_INDEX);
813
return { importedESM, importedCJS };
9-
};
10-
11-
const { port1, port2 } = new MessageChannel();
14+
}
1215

1316
register(fixtures.fileURL('es-module-loaders/hook-resolve-type-loader.mjs'), {
14-
data: { port: port2 },
15-
transferList: [port2],
17+
data: { sab, ESM_MODULE_INDEX, CJS_MODULE_INDEX },
1618
});
17-
18-
port1.on('message', ({ type }) => {
19-
switch (type) {
20-
case 'module':
21-
importedESM++;
22-
break;
23-
case 'commonjs':
24-
importedCJS++;
25-
break;
26-
}
27-
});
28-
29-
port1.unref();
30-
port2.unref();

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.