Title: test: replace mocha with vitest by edusperoni · Pull Request #6094 · NativeScript/nativescript-cli · GitHub
Open Graph Title: test: replace mocha with vitest by edusperoni · Pull Request #6094 · NativeScript/nativescript-cli
X Title: test: replace mocha with vitest by edusperoni · Pull Request #6094 · NativeScript/nativescript-cli
Description: PR Checklist The PR title follows our guidelines. There is an issue for the bug/feature this PR is for. (no tracking issue — happy to open one) You have signed the CLA. All existing tests are passing. Tests for the changes are included. (this PR is the test runner; four pre-existing test defects are fixed below) Draft — opened for visibility while the approach is reviewed. What is the current behavior? Mocha, configured by test/.mocharc.yml, with a hand-written declaration file supplying the globals. istanbul is a devDependency that nothing references. What is the new behavior? Vitest, running the compiled output in dist/ — the same thing mocha ran, and for a specific reason (below). Pass counts are identical on both platforms, measured on the same commit base: passing skipped/pending duration macOS — main (mocha) 1514 9 pending 36s macOS — this branch 1514 38 skipped 23s Linux CI — main (mocha) 1501 9 pending — Linux CI — this branch 1501 38 skipped — The 13-test gap between platforms is macOS-only tests, and it exists on main too. The skipped delta is previously-hidden tests becoming visible, explained below. Why it runs compiled output rather than the TypeScript sources Running the sources directly was the original goal and is not achievable without a much larger change. The injector discovers dependencies by regex-parsing constructor source text — annotate() in lib/common/helpers.ts calls fn.toString() and matches CONSTRUCTOR_ARGS. tsc emits constructor($logger, $fs); oxc's class transform emits constructor(...args), so every injectable fails with unable to resolve ..._args. 209 files register injectables this way. Measured rather than assumed: lib/common/test/unit-tests/mobile/devices-service is 135/135 failing against the sources and 135/135 passing against tsc's output. Making the sources runnable means replacing the DI container's parameter-name reflection with explicit tokens — its own project, not a test-runner change. Test changes the runner required before/after renamed to beforeAll/afterAll (16 hooks) 42 tests using mocha's done callback converted: 9 promise chains to async/await; the rest are event-emitter driven and go through a small withDone() adapter that wraps a callback-style body in the promise the runner expects the hand-written mocha global typings replaced with vitest/globals Four pre-existing defects this surfaced Vitest's per-file isolation and its stricter handling of empty suites exposed problems mocha's shared process was hiding. All predate this PR: Six suites were silently disabled, and mocha reported nothing. test/options.ts disabled its whole suite with an early return; getNSValue in project-data-service generates cases from an array whose entries are all commented out; and four suites in ios-project-service guard their bodies with a darwin check, so off macOS they register no tests at all. Mocha accepts an empty suite silently — which is exactly why the Linux count sits 13 below macOS with nothing to indicate why. The first two are now explicit .skip (the whole of the 9 → 38 change); the darwin-gated four are skipped at suite level, since an empty suite is tolerated when skipped. test/project-commands.ts never restored a global it patched. It assigned helpers.isInteractive = () => true in a beforeEach with no restore, so from the moment that file ran, every file after it saw an interactive terminal regardless of environment. That is why project-name-service passed in CI while depending on the non-interactive path, and why it only failed once isolation removed the leak. Both now use setIsInteractive() — the override the helper already exposes — with an afterEach. A callstack assertion matched "at next", which is a mocha runner frame. It now requires a stack frame rather than one runner's internals. Also istanbul is dropped — nothing referenced it. dev/tsc-to-mocha-watch.js becomes dev/tsc-to-vitest-watch.js; the old one required chalk, which has not been a declared dependency since e562267ce. It passes --watch explicitly, because vitest only infers watch mode from a TTY and would otherwise run once and exit, taking tsc --watch down with it. packages/doctor moves too, and runs TypeScript directly After this PR there is no mocha left in the repository. (nativescript-envinfo has no test script, so nothing to move there.) Doctor does not need the compiled-output indirection the CLI does — nothing in it reflects over constructor source — so vitest runs its TypeScript directly. That removes two things that existed only to support testing the build output: the dist-test compile (build.all) scripts/copy-test-fixtures.js, which existed to place example.zip next to the compiled tests; resolved from the sources it is already there tsconfig.test.json becomes typecheck-only, since test types were previously checked as a side effect of compiling them — test is now tsc -p tsconfig.test.json && vitest run so that check is not silently lost. The runner needed two changes: the extractZip test and its afterEach used mocha's done callback, and android-tools-info used before/after. 82 passing, unchanged. Verification 101 files pass on both platforms; counts match main exactly on each test runs via npm run build, so it inherits the clean-then-compile from #6092 — a deleted source cannot leave stale output for the runner to pick up watch mode verified end to end: renamed a test in a .ts, confirmed tsc re-emitted and vitest re-ran only that file, in 38ms tsc --noEmit clean packages/doctor: 82 passing across 5 files, matching its mocha baseline rebased onto current main; #6091 landed a new test in between and it runs under vitest unchanged Summary by CodeRabbit Tests Modernized automated testing with improved async handling and Vitest-based test execution. Added continuous validation across Node.js 20, 22, and 24. Improved test reliability and cleanup across platform-specific and device-related scenarios. Added clearer handling for unsupported macOS-only test suites. Developer Experience Added a watch mode that automatically recompiles and reruns tests as changes are made. Improved test configuration for the Doctor package and streamlined test artifacts.
Open Graph Description: PR Checklist The PR title follows our guidelines. There is an issue for the bug/feature this PR is for. (no tracking issue — happy to open one) You have signed the CLA. All existing tests are ...
X Description: PR Checklist The PR title follows our guidelines. There is an issue for the bug/feature this PR is for. (no tracking issue — happy to open one) You have signed the CLA. All existing tests are ...
Opengraph URL: https://github.com/NativeScript/nativescript-cli/pull/6094
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d80573c6-e7d9-b744-1254-9e296e6e8dd1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E1B6:20AA01:30E77F2:3E293B5:6B01B747 |
| html-safe-nonce | 926eeadbe729048c464437a07221ff97d6c9e3b2a17f2d4de60cfa0cd43c62d3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUI2OjIwQUEwMTozMEU3N0YyOjNFMjkzQjU6NkIwMUI3NDciLCJ2aXNpdG9yX2lkIjoiMzQ3MTkxNzM4OTEwMzM0NzUyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ced1a33e0dda15875ecb8614b2010cd8656277f917a2aa568f2d0d76a53eeef8 |
| hovercard-subject-tag | pull_request:4155687519 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/nativescript-cli/pull/6094/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | PR Checklist The PR title follows our guidelines. There is an issue for the bug/feature this PR is for. (no tracking issue — happy to open one) You have signed the CLA. All existing tests are ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/nativescript-cli git https://github.com/NativeScript/nativescript-cli.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 21347346 |
| octolytics-dimension-repository_nwo | NativeScript/nativescript-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21347346 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/nativescript-cli |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width