Repository navigation
feat(vite): add Vite build support for on-device Vitest runner - #87
Open
codeprefect wants to merge 1 commit into
Open
codeprefect wants to merge 1 commit into
codeprefect wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: This is AI-assisted, but manually tested by a human
Overview
This PR adds Vite build support to
@nativescript/unit-test-runneralongside the existing Webpack build pipeline, enabling developers using@nativescript/viteto execute on-device Vitest suites.It introduces automatic Vite integration via
@nativescript/unit-test-runner/vite, creates standard entrypoint redirection and shims for test builds, provides a dedicatedcreateViteTestRegistryhelper forimport.meta.globlazy imports, and adds full Istanbul code coverage integration for Vite.Motivation
With the introduction of
@nativescript/vite, developers migrating NativeScript projects away from Webpack needed first-class support forns test. Vite resolves entrypoints, glob imports, and module dependencies differently from Webpack:require.contextis specific to Webpack; Vite usesimport.meta.glob.test.tsonly when building for testing (ns test), while excluding test specs from regular application production/development builds.Key Changes
1. Vite Plugin Integration (
nativescript.vite.mjs&src/vite.ts)nativescript.vite.mjsat the repository root, which is automatically picked up and loaded by@nativescript/viteviaexternalConfigsPlugin.unitTestRunner(options)from@nativescript/unit-test-runner/vite(src/vite.ts) with type definitions for:include: Glob patterns defining test specs.entryPath: Path to the test entry file (defaults tosrc/test.tsorapp/test.ts).coverage: Istanbul coverage instrumentation toggle.test.tsacross standard project structures (src/test.ts,app/test.ts, etc.).includefrom non-test production/development builds.@rollup/plugin-istanbulintegration during test builds when coverage is enabled.@nativescript/unit-test-runner/shims/vitest.mjs.2. Runtime Test Module Registry (
src/runtime/registry.ts)createViteTestRegistry: Accepts the module loader map produced byimport.meta.glob('./**/*.test.{js,ts}').executeWrappedModuleto unwrapPromiseinstances returned by Vite's lazy dynamic module loaders (() => import(...)).declare global { interface ImportMeta { glob(...) } }so TypeScript projects do not error ifvite/clientreferences are not globally present.createNativeScriptTestRegistryis preserved as an alias forcreateViteTestRegistry.createWebpackTestRegistryandcreateViteTestRegistrycan gracefully handle contexts or module maps passed to either function.3. Exports & Package Setup (
package.json,src/runtime/index.ts)"./vite"export map pointing todist/src/vite.jsandsrc/vite.ts.createViteTestRegistryfrom@nativescript/unit-test-runner/runtime.4. Tests & Documentation
src/node/vite-plugin.spec.ts): Added comprehensive test suite verifying:src/runtime/registry.spec.ts): Added tests covering lazy loaders, Promise evaluation, path normalization, and error handling for missing modules.README.md): Updated the setup guide with:test.tssetup usingcreateViteTestRegistry(import.meta.glob(...)).setRootApp(app)before mounting components).How to Test
1. Automated Tests
npm run test npm run buildVerify that all 85 unit tests pass and compilation succeeds.
2. Manual Verification in a Vite Project
src/test.ts: