@@ -15,6 +15,7 @@ const args = minimist(process.argv.slice(2), {
1515const BASE = path . resolve ( __dirname , '../..' ) ;
1616
1717const ROOT_PACKAGE_JSON = path . resolve ( BASE , 'package.json' ) ;
18+ const OUT_PACKAGE_JSON = path . resolve ( path . dirname ( utils . getAbsoluteElectronExec ( ) ) , 'package.json' ) ;
1819const NODE_DIR = path . resolve ( BASE , 'third_party' , 'electron_node' ) ;
1920const JUNIT_DIR = args . jUnitDir ? path . resolve ( args . jUnitDir ) : null ;
2021const TAP_FILE_NAME = 'test.tap' ;
@@ -39,36 +40,41 @@ const defaultOptions = [
3940 '-J'
4041] ;
4142
42- // The upstream Node.js test suite assumes there is no package.json above the
43- // test tree. In Electron, third_party/electron_node lives under Chromium's
44- // src/, whose package.json ( "type": "module") is always an ancestor. That
45- // changes how Node resolves the module type of test files and fixtures: it
46- // disables module-syntax detection (breaking e.g.
47- // test-compile-cache-typescript-esm) and emits MODULE_TYPELESS_PACKAGE_JSON
43+ // The upstream Node.js test suite assumes there is no package.json above its
44+ // test files or virtual files rooted at process.execPath. Electron has
45+ // "type": "module" package files at both Chromium's src/ root and in the
46+ // selected output directory. They change how Node resolves the module type of
47+ // test files and fixtures: they disable module-syntax detection (breaking e.g.
48+ // test-compile-cache-typescript-esm) and emit MODULE_TYPELESS_PACKAGE_JSON
4849// warnings that break tests asserting clean stderr (e.g. test-esm-detect-
49- // ambiguous, test-esm-import-meta-main-eval, test-output-coverage-with-mock).
50+ // ambiguous, test-esm-import-meta-main-eval, test-output-coverage-with-mock),
51+ // and make virtual CommonJS files under process.execPath load as ESM.
5052//
51- // While the suite runs we move src/package.json aside so the environment
52- // matches upstream exactly, then restore it when done. The original contents
53- // are kept in a sibling backup file so an interrupted/killed run self-heals on
54- // the next invocation rather than leaving src/package.json missing.
55- const ROOT_PACKAGE_JSON_BACKUP = `${ ROOT_PACKAGE_JSON } .spec-runner-backup` ;
53+ // While the suite runs we move both package files aside so the environment
54+ // matches upstream exactly, then restore them when done. Original contents are
55+ // kept in sibling backup files so an interrupted run self-heals next time.
56+ const PACKAGE_JSON_PATHS = [ ROOT_PACKAGE_JSON , OUT_PACKAGE_JSON ] ;
5657
5758const stashPackageJson = ( ) => {
58- // This won't always exist in CI.
59- if ( ! fs . existsSync ( ROOT_PACKAGE_JSON ) ) {
60- return ;
59+ for ( const packageJson of PACKAGE_JSON_PATHS ) {
60+ // These won't always exist in CI.
61+ if ( ! fs . existsSync ( packageJson ) ) {
62+ continue ;
63+ }
64+ fs . copyFileSync ( packageJson , `${ packageJson } .spec-runner-backup` ) ;
65+ fs . rmSync ( packageJson ) ;
6166 }
62- fs . copyFileSync ( ROOT_PACKAGE_JSON , ROOT_PACKAGE_JSON_BACKUP ) ;
63- fs . rmSync ( ROOT_PACKAGE_JSON ) ;
6467} ;
6568
6669const restorePackageJson = ( ) => {
67- if ( ! fs . existsSync ( ROOT_PACKAGE_JSON_BACKUP ) ) {
68- return ;
70+ for ( const packageJson of PACKAGE_JSON_PATHS ) {
71+ const backup = `${ packageJson } .spec-runner-backup` ;
72+ if ( ! fs . existsSync ( backup ) ) {
73+ continue ;
74+ }
75+ fs . copyFileSync ( backup , packageJson ) ;
76+ fs . rmSync ( backup ) ;
6977 }
70- fs . copyFileSync ( ROOT_PACKAGE_JSON_BACKUP , ROOT_PACKAGE_JSON ) ;
71- fs . rmSync ( ROOT_PACKAGE_JSON_BACKUP ) ;
7278} ;
7379
7480const getCustomOptions = ( ) => {
0 commit comments