Skip to content

Commit 9c0fd37

Browse files
committed
refine runner files
1 parent 9a027c1 commit 9c0fd37

File tree

1 file changed

+6
-63
lines changed

1 file changed

+6
-63
lines changed

ci/compose_test.js

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ function references262(filePath) {
4141
return /\$262\b/.test(src);
4242
}
4343

44-
function definesAssertInFile(filePath) {
45-
if (!fs.existsSync(filePath)) return false;
46-
const src = fs.readFileSync(filePath, 'utf8');
47-
const defines = parseList(extractMeta(filePath), 'defines');
48-
return /function\s+assert\b|var\s+assert\b|assert\._isSameValue/.test(src) || defines.includes('assert');
49-
}
50-
5144
function ensureArrayDistinct(arr) {
5245
const seen = new Set();
5346
const out = [];
@@ -87,7 +80,7 @@ function mirrorSiblingModuleFiles(testPath, targetDir) {
8780
}
8881
}
8982

90-
const realmFeatureName = ['cross', 'realm'].join('-');
83+
const realmFeatureName = 'cross-realm';
9184
const realmMarker = '// Inject: unified $262 shim - idempotent';
9285
function get262StubLines() {
9386
// Minimal, idempotent $262 shim with createRealm support
@@ -254,8 +247,8 @@ function get262StubLines() {
254247
];
255248
}
256249

257-
function inject262Shim(outLines, testPath, meta, prependFiles = []) {
258-
let need262Shim = references262(testPath) || hasFeature(meta, realmFeatureName);
250+
function inject262Shim(outLines, testPath, meta, prependFiles = [], needsAgent = false) {
251+
let need262Shim = references262(testPath) || hasFeature(meta, realmFeatureName) || needsAgent;
259252
if (!need262Shim) {
260253
for (const p of prependFiles) {
261254
if (p && fs.existsSync(p) && references262(p)) {
@@ -368,10 +361,12 @@ function composeTest({testPath, repoDir, harnessIndex, prependFiles = [], needSt
368361
// Write unique prepends
369362
PREPEND_FILES = ensureArrayDistinct(PREPEND_FILES);
370363

364+
const meta = extractMeta(testPath);
365+
inject262Shim(outLines, testPath, meta, PREPEND_FILES, needsAgent);
366+
371367
// Inject $262.agent shim BEFORE harness files (atomicsHelper.js extends $262.agent)
372368
if (needsAgent) {
373369
outLines.push('// Inject: $262.agent shim for multi-agent tests');
374-
outLines.push('if (typeof $262 === "undefined") { var $262 = {}; }');
375370
outLines.push('if (!$262.agent) { $262.agent = {}; }');
376371
outLines.push('$262.agent.start = function(script) { __agent_start(script); };');
377372
outLines.push('$262.agent.broadcast = function(sab) {');
@@ -417,9 +412,6 @@ function composeTest({testPath, repoDir, harnessIndex, prependFiles = [], needSt
417412
outLines.push('}');
418413
outLines.push('');
419414

420-
const meta = extractMeta(testPath);
421-
inject262Shim(outLines, testPath, meta, PREPEND_FILES);
422-
423415
// Ensure dynamic import resolves relative to the original test file path,
424416
// not the composed file path. Only inject when the test actually
425417
// contains an import (either a static `import` declaration or dynamic
@@ -446,55 +438,6 @@ function composeTest({testPath, repoDir, harnessIndex, prependFiles = [], needSt
446438
fs.writeFileSync(tmpName, outLines.join('\n'));
447439
mirrorSiblingModuleFiles(testPath, composed.tmpDir);
448440

449-
// verify assert was injected if test references assert
450-
if (referencesAssert(testPath) && !definesAssertInFile(tmpName)) {
451-
// rebuild ensuring sta/assert at top while preserving other PREPEND_FILES
452-
const fixedComposed = createComposedTarget(testPath);
453-
const fixedTmp = fixedComposed.tmpPath;
454-
const lines2 = [];
455-
if (needStrict) {
456-
lines2.push('"use strict";');
457-
lines2.push('');
458-
}
459-
const assertPath = harnessIndex['assert.js'];
460-
const staPath = harnessIndex['sta.js'];
461-
const fixedPrepend = [];
462-
if (staPath) fixedPrepend.push(staPath);
463-
if (assertPath) fixedPrepend.push(assertPath);
464-
for (const p of PREPEND_FILES) {
465-
if (!p) continue;
466-
const b = path.basename(p);
467-
if (!fixedPrepend.some(q => path.basename(q) === b)) fixedPrepend.push(p);
468-
}
469-
const fixedUnique = ensureArrayDistinct(fixedPrepend);
470-
for (const p of fixedUnique) {
471-
if (!p) continue;
472-
const absP = path.resolve(p);
473-
lines2.push(`// Inject: ${absP}`);
474-
lines2.push(fs.readFileSync(p, 'utf8'));
475-
lines2.push('');
476-
}
477-
478-
lines2.push('// Inject: expose common harness helpers on globalThis for imported modules');
479-
lines2.push('if (typeof globalThis !== "undefined") {');
480-
lines2.push(' if (typeof assert !== "undefined" && typeof globalThis.assert === "undefined") globalThis.assert = assert;');
481-
lines2.push(' if (typeof Test262Error !== "undefined" && typeof globalThis.Test262Error === "undefined") globalThis.Test262Error = Test262Error;');
482-
lines2.push(' if (typeof $DONE !== "undefined" && typeof globalThis.$DONE === "undefined") globalThis.$DONE = $DONE;');
483-
lines2.push('}');
484-
lines2.push('');
485-
486-
// Inject unified $262 shim into the rebuilt file when required by test/meta
487-
const metaFixed = extractMeta(testPath);
488-
inject262Shim(lines2, testPath, metaFixed, [], needsAgent);
489-
490-
const absTest = path.resolve(testPath);
491-
lines2.push(`// Inject: ${absTest}`);
492-
lines2.push(fs.readFileSync(testPath, 'utf8'));
493-
fs.writeFileSync(fixedTmp, lines2.join('\n'));
494-
mirrorSiblingModuleFiles(testPath, fixedComposed.tmpDir);
495-
return {testToRun: fixedTmp, tmpPath: fixedTmp, cleanupTmp: true};
496-
}
497-
498441
return {testToRun: tmpName, tmpPath: tmpName, cleanupTmp: true};
499442
}
500443

0 commit comments

Comments
 (0)