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

[core] Fix running mocha related scripts on Windows locally #44664

Merged
merged 8 commits into from
Dec 16, 2024
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ If the CI job fails, then you most likely need to run the commands that failed l
This runs the unit tests in a `jsdom` environment.
If it fails then `pnpm test:unit` should<sup>[1](test/README.md#accessibility-tree-exclusion)</sup> fail locally as well.
You can narrow the scope of tests run with `pnpm test:unit --grep ComponentName`.
If you encounter error: `'m)[jt]s?' is not recognized as an internal or external command` while running `pnpm test:unit`, it is likely because of an issue with how the test file extensions are handled in the script. Solution: Modify the `nx_test_unit` script in the root `package.json` to
`"nx_test_unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.{js,jsx,ts,tsx}' 'packages-internal/**/*.test.{js,jsx,ts,tsx}' 'docs/**/*.test.{js,jsx,ts,tsx}'"` This change ensures that the test files are correctly recognized with the appropriate extensions and allows running tests using the `--grep` flag on Windows.
Copy link
Member

@oliviertassinari oliviertassinari Dec 7, 2024

Choose a reason for hiding this comment

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

I haven't looked close, but at first sight, this can't fly, we can't possibly ask Windows contributors to change the source to run the tests, it's horrible DX.

Can we instead change the script source?

Either this was broken in #44143 or it's mochajs/mocha#5219. I can't easily test this on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I understand. I tried to look further into it to see if I could have a command that runs the tests successfully on both windows and mac but I wasn't able to find one.

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli Dec 11, 2024

Choose a reason for hiding this comment

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

I am a Windows user, adding double quotes works, as shown in mochajs/mocha#5219. For example:

--- a/package.json
+++ b/package.json
@@ -95,7 +95,7 @@
     "nx_test_karma": "cross-env NODE_ENV=test karma start test/karma.conf.js",
     "nx_test_regressions_run": "mocha --config test/regressions/.mocharc.js --delay 'test/regressions/**/*.test.js'
",
     "nx_test_regressions_pigment_css_run": "mocha --config apps/pigment-css-vite-app/.mocharc.cjs --delay 'apps/pig
ment-css-vite-app/**/*.test.js'",
-    "nx_test_unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.?(c|m)[jt]s?(x)' 'packages-internal/**/*.tes
t.?(c|m)[jt]s?(x)' 'docs/**/*.test.?(c|m)[jt]s?(x)'"
+    "nx_test_unit": "cross-env NODE_ENV=test mocha \"packages/**/*.test.?(c|m)[jt]s?(x)\" \"packages-internal/**/*.
test.?(c|m)[jt]s?(x)\" \"docs/**/*.test.?(c|m)[jt]s?(x)\""
   },
   "dependencies": {
     "@googleapis/sheets": "^9.3.1",

@ChristopherJamesL Can you try the change and confirm? It needs to be applied to other scripts too.

If `pnpm test:unit` passes locally, but fails in CI, consider [Accessibility tree exclusion in CI](test/README.md#accessibility-tree-exclusion).

#### ci/circleci: test_browser-1
Expand Down
Loading