Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix npm scripts on windows #5219

Merged
merged 8 commits into from
Oct 2, 2024
Merged

Conversation

mark-wiemer
Copy link
Contributor

@mark-wiemer mark-wiemer commented Sep 29, 2024

Closes #5220

Single quotes weren't resolved correctly on Windows. The single quotes don't seem necessary on any OS as they were never wrapping a space character.

Knip also reported prettier as unused, so I've added prettier to Knip's ignore list.

npm test is now passing on a clean install from on Windows, where it was failing before.

Ref https://github.com/mark-wiemer/mocha/pull/1 for status checks

@voxpelli
Copy link
Member

This is a bit unintuitive to me – my impression is that the quotes should be there so that the js-based glob resolves rather than the shell glob 🤔

@mark-wiemer
Copy link
Contributor Author

mark-wiemer commented Sep 29, 2024

@voxpelli I'm not a glob expert, in my book if it works it works, but obviously if you don't feel comfortable merging that's fine. I'll dig deeper as obviously the tests are now failing on other operating* systems

@mark-wiemer mark-wiemer changed the title Fix npm scripts on Windows fix: npm scripts on Windows Sep 29, 2024
@mark-wiemer
Copy link
Contributor Author

mark-wiemer commented Sep 29, 2024

2 checks failed image

Investigating remaining issues now, ref https://github.com/mark-wiemer/mocha/pull/1:

@mark-wiemer
Copy link
Contributor Author

I'm able to reproduce this issue locally with Node 22 on Windows, looks like the same err message. Going to see if different versions of 22.x work:

Full output
~/repos/mocha (mark-wiemer/lint)
$ fnm use 22
2024-09-29 10:35:59
Using Node v22.9.0
[last: 0s]
~/repos/mocha (mark-wiemer/lint)
$ npm run test-node:integration
2024-09-29 10:36:06

> [email protected] test-node:integration
> run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 "test/integration/plugins/root-hooks.spec.js"


> [email protected] clean
> rimraf mocha.js mocha.js.map


> [email protected] build
> rollup -c ./rollup.config.js


./browser-entry.js → ./mocha.js...
created ./mocha.js in 1.9s


  root hooks
    when mocha run in serial mode
      ✔ should run root hooks when provided via mochaHooks object export
      ✔ should run root hooks when provided via mochaHooks function export
      support ESM when type=module or .mjs extension
        ✔ should run root hooks when provided via mochaHooks
      support ESM via .js extension w/o type=module
        1) should fail due to ambiguous file type
    when mocha in parallel mode
      ✔ should run root hooks when provided via mochaHooks object exports
      ✔ should run root hooks when provided via mochaHooks function export
      when running multiple jobs
        ✔ should run root hooks when provided via mochaHooks object exports for each job


  6 passing (9s)
  1 failing

  1) root hooks
       when mocha run in serial mode
         support ESM via .js extension w/o type=module
           should fail due to ambiguous file type:
     
expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
  expected
  {
    output: '\n✖ \x1b[31mERROR:\x1b[39m Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module C:\\Users\\markw\\repos\\mocha\\test\\integration\\fixtures\\plugins\\root-hooks\\root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:303:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1381:24)\n    at Module._compile (node:internal/modules/cjs/loader:1503:5)\n    at Module.replacementCompile (C:\\Users\\markw\\repos\\mocha\\node_modules\\append-transform\\index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)\n    at Object.<anonymous> (C:\\Users\\markw\\repos\\mocha\\node_modules\\append-transform\\index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1317:32)\n    at Module._load (node:internal/modules/cjs/loader:1127:12)\n    at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)\n    at cjsLoader (node:internal/modules/esm/translators:329:5)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:260:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)\n    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)\n    at async formattedImport (C:\\Users\\markw\\repos\\mocha\\lib\\nodejs\\esm-utils.js:2:567)\n    at async exports.requireOrImport (C:\\Users\\markw\\repos\\mocha\\lib\\nodejs\\esm-utils.js:7:1135)\n    at async exports.handleRequires (C:\\Users\\markw\\repos\\mocha\\lib\\cli\\run-helpers.js:38:364)\n    at async C:\\Users\\markw\\repos\\mocha\\lib\\cli\\run.js:18:40 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
    code: 1,
    args: [
      'C:\\Users\\markw\\repos\\mocha\\bin\\mocha.js',
      '--require=C:\\Users\\markw\\repos\\mocha\\test\\integration\\fixtures\\plugins\\root-hooks\\root-hook-defs-esm-broken.fixture.js',
      '--no-color',
      '--no-bail',
      '--no-parallel'
    ],
    command: 'C:\\Users\\markw\\repos\\mocha\\bin\\mocha.js --require=C:\\Users\\markw\\repos\\mocha\\test\\integration\\fixtures\\plugins\\root-hooks\\root-hook-defs-esm-broken.fixture.js --no-color --no-bail --no-parallel'
  }
  to contain output /SyntaxError: Unexpected token/


  expected Promise when fulfilled to contain output /SyntaxError: Unexpected token/
    expected
    {
      output: '\n✖ \x1b[31mERROR:\x1b[39m Error [ERR_REQUIRE_CYCLE_MODULE]: Cannot require() ES Module C:\\Users\\markw\\repos\\mocha\\test\\integration\\fixtures\\plugins\\root-hooks\\root-hook-defs-esm-broken.fixture.js in a cycle.\n    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:303:15)\n    at loadESMFromCJS (node:internal/modules/cjs/loader:1381:24)\n    at Module._compile (node:internal/modules/cjs/loader:1503:5)\n    at Module.replacementCompile (C:\\Users\\markw\\repos\\mocha\\node_modules\\append-transform\\index.js:60:13)\n    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)\n    at Object.<anonymous> (C:\\Users\\markw\\repos\\mocha\\node_modules\\append-transform\\index.js:64:4)\n    at Module.load (node:internal/modules/cjs/loader:1317:32)\n    at Module._load (node:internal/modules/cjs/loader:1127:12)\n    at TracingChannel.traceSync (node:diagnostics_channel:315:14)\n    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)\n    at cjsLoader (node:internal/modules/esm/translators:329:5)\n    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:260:7)\n    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)\n    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)\n    at async formattedImport (C:\\Users\\markw\\repos\\mocha\\lib\\nodejs\\esm-utils.js:2:567)\n    at async exports.requireOrImport (C:\\Users\\markw\\repos\\mocha\\lib\\nodejs\\esm-utils.js:7:1135)\n    at async exports.handleRequires (C:\\Users\\markw\\repos\\mocha\\lib\\cli\\run-helpers.js:38:364)\n    at async C:\\Users\\markw\\repos\\mocha\\lib\\cli\\run.js:18:40 {\n  code: \'ERR_REQUIRE_CYCLE_MODULE\'\n}\n',
      code: 1,
      args: [
        '--require=C:\\Users\\markw\\repos\\mocha\\test\\integration\\fixtures\\plugins\\root-hooks\\root-hook-defs-esm-broken.fixture.js',
        '--no-color',
        '--no-bail',
        '--no-parallel'
      ],
    }
    to contain output /SyntaxError: Unexpected token/
      at Array.forEach (<anonymous>)
  From previous event:
      at Context.<anonymous> (test\integration\plugins\root-hooks.spec.js:140:16)
      at callFn (lib\runnable.js:110:584)
      at Runnable.run (lib\runnable.js:110:57)
      at Runner.runTest (lib\runner.js:182:1054)
      at C:\Users\markw\repos\mocha\lib\runner.js:210:654
      at next (lib\runner.js:159:422)
      at C:\Users\markw\repos\mocha\lib\runner.js:159:809
      at next (lib\runner.js:147:579)
      at Immediate.<anonymous> (lib\runner.js:151:1253)
      at process.processImmediate (node:internal/timers:491:21)
      set UNEXPECTED_FULL_TRACE=true to see the full stack trace



[last: 27s]

@mark-wiemer
Copy link
Contributor Author

  • Last good node: 22.6.0
  • First bad node: 22.7.0

--experimental-detect-module is default in Node 22.7 and later
@mark-wiemer
Copy link
Contributor Author

Added tests to distinguish between --no-experimental-module-detection and --experimental-module-detection as the latter is the default in Node 22.7 and later

Copy link
Member

@voxpelli voxpelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks 🙏

Extra thanks for fixing the tests for latest Node version!

@voxpelli voxpelli changed the title fix: npm scripts on Windows test: fix npm scripts on windows Oct 2, 2024
@voxpelli voxpelli merged commit 1173da0 into mochajs:main Oct 2, 2024
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🛠 Repo: Windows fails to run npm test
2 participants