-
Notifications
You must be signed in to change notification settings - Fork 10
feat(vitest-plugin): extract react-app testing helpers into vitest-plugin-react-app #5286
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1fb0357
feat(react-app): vitest render/test-app fixtures under src/vitest
odinr cc0e519
refactor: extract react-app vitest helpers into vitest-plugin-react-app
odinr 42d6637
ci: fix Playwright install invocation to filter into a package that d…
odinr 2db24c5
fix(vitest-plugin-react-app): declare vitest as a peer dependency
odinr 3d0c588
fix(vitest-plugin-react-app): correct tsconfig project reference
odinr e99f7ab
test(vitest-plugin-react-app): cover resolveAppTestEnv and appTestVit…
odinr 7f4cf25
docs: add missing changeset for CLI ./vitest entry-point removal
odinr b379cb2
fix(module-context): make telemetry an optional peer dependency
odinr 18b4b2d
docs(vitest-plugin-react-app): fix quick-start snippet and fixture wo…
odinr 2712834
docs(vitest-plugin-react-app): clarify testApp fixture-sharing wording
odinr 40e9d15
fix(react-app): remove stale vitest-browser-react peer dependency
odinr 428534c
test(module-context): cover telemetry tracking for initial-context re…
odinr 0cc1a0d
test(react-app): add useToken rerender regression test
odinr 6ab2c32
refactor(tests): format code for better readability in useToken and C…
odinr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@equinor/fusion-log": patch | ||
| --- | ||
|
|
||
| Guard the `process.env` access used to detect the current log level so it no longer throws in environments without a Node-style `process` global (e.g. Vitest Browser Mode). |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@equinor/fusion-framework-module-context": patch | ||
| --- | ||
|
|
||
| Fix `ContextModule.postInitialize` logging a `console.warn` for the valid "no initial context" case (no context in the path and no parent context). The default `resolveInitialContext` resolver used RxJS `first()` without a default value, so completing with no emissions threw an `EmptyError` that got logged as if resolution had actually failed. `first()` now falls back to `undefined`, so a genuinely empty result completes silently and only real resolution failures are logged. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@equinor/fusion-framework-module-msal": patch | ||
| --- | ||
|
|
||
| Remove a stray `console.log` left in `resolveVersion`'s minor-version-mismatch warning path. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@equinor/fusion-framework-react-app": patch | ||
| --- | ||
|
|
||
| Remove `docs/testing.md` and replace the README's testing section with a pointer to `@equinor/fusion-framework-vitest-plugin-react-app`, now that `renderAppHook`, `renderAppComponent`, `testApp`, and the `appTestVitePlugin` Vite plugin live in that separate package instead of this one. Both described the old `./vitest` entry-point as requiring `@testing-library/react` and returning a top-level `modules` field, which no longer applies now that the helpers are built on `vitest-browser-react` and return a nested `fusion: { framework, app }` object. The README's API-reference table no longer lists a `/vitest` entry-point. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,27 @@ | ||
| --- | ||
| "@equinor/fusion-framework-react-app": minor | ||
| "@equinor/fusion-framework-react-app": major | ||
| --- | ||
|
|
||
| Add `renderAppComponent` to the `/testing` entry-point, a component-level counterpart to `renderAppHook` for testing components (not just hooks) against a real, mock-backed application module scope. | ||
| Remove the `./vitest` entry-point. `renderAppComponent` — a component-level counterpart to `renderAppHook` for testing components (not just hooks) against a real, mock-backed application module scope, built on `vitest-browser-react` instead of `@testing-library/react` — now lives in a separate package, `@equinor/fusion-framework-vitest-plugin-react-app`. | ||
|
|
||
| ```tsx | ||
| import { renderAppComponent } from '@equinor/fusion-framework-react-app/testing'; | ||
| import { waitFor } from '@testing-library/react'; | ||
| import { renderAppComponent } from '@equinor/fusion-framework-vitest-plugin-react-app'; | ||
| import { Apploader } from '../apploader/Apploader'; | ||
|
|
||
| const { container } = await renderAppComponent(<Apploader appKey="child-app" />); | ||
| await waitFor(() => expect(container.textContent).toContain('mounted')); | ||
| const screen = await renderAppComponent(<Apploader appKey="child-app" />); | ||
| await expect.element(screen.getByText('mounted')).toBeVisible(); | ||
| ``` | ||
|
|
||
| `renderAppComponent` wraps `@testing-library/react`'s `render` with the same `FrameworkProvider` + `ModuleProvider` nesting `renderAppHook` uses, backed by `mockFramework` and `mockAppModules` (`@equinor/fusion-framework-app/mock`), so tests can render a real component tree without hand-wiring those mocks. | ||
| `renderAppComponent` wraps `vitest-browser-react`'s `render` with the same `FrameworkProvider` + `ModuleProvider` nesting `renderAppHook` uses, backed by `mockFramework` and `mockAppModules` (`@equinor/fusion-framework-app/mock`), so tests can render a real component tree without hand-wiring those mocks. | ||
|
|
||
| The result also carries a nested `fusion` object (`fusion.framework`, `fusion.app`) — nested rather than spread directly onto the result so `vitest-browser-react`'s own return shape stays free to evolve without ever colliding with it — so a test can drive a module directly after the initial render and assert the component re-renders, instead of hand-wiring `mockAppModules`/`ModuleProvider` itself to reach the same instance: | ||
|
|
||
| ```tsx | ||
| const { getByText, fusion } = await renderAppComponent<[ContextModule]>(<App />, { | ||
| configure: (configurator) => enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)), | ||
| }); | ||
| await act(() => fusion.app.context.setCurrentContextByIdAsync(projectB.id)); | ||
| await expect.element(getByText(/project-b/)).toBeVisible(); | ||
| ``` | ||
|
|
||
| **Breaking change:** the `./vitest` entry-point is removed with no compatibility shim. Migrate by installing `@equinor/fusion-framework-vitest-plugin-react-app` and importing `renderAppComponent` from it instead, and replacing `@testing-library/react`'s `render`/`waitFor`/`act` with `vitest-browser-react`/`vitest`'s equivalents. | ||
|
odinr marked this conversation as resolved.
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,23 @@ | ||
| --- | ||
| "@equinor/fusion-framework-react-app": minor | ||
| "@equinor/fusion-framework-react-app": major | ||
| --- | ||
|
|
||
| Add a `/testing` entry-point with `renderAppHook`, a pre-wrapped `renderHook` for testing app-scoped hooks (`useAppModule`, `useAccessToken`, etc.) against a real, mock-backed module and framework instance. | ||
| Remove the `./vitest` entry-point. `renderAppHook` — a pre-wrapped `renderHook` for testing app-scoped hooks (`useAppModule`, `useAccessToken`, etc.) against a real, mock-backed module and framework instance, built on `vitest-browser-react` instead of `@testing-library/react` — now lives in a separate package, `@equinor/fusion-framework-vitest-plugin-react-app`. | ||
|
|
||
| ```tsx | ||
| import { renderAppHook } from '@equinor/fusion-framework-react-app/testing'; | ||
| import { waitFor } from '@testing-library/react'; | ||
| import { renderAppHook } from '@equinor/fusion-framework-vitest-plugin-react-app'; | ||
|
|
||
| const { result } = await renderAppHook(() => useAccessToken({ scopes: ['User.Read'] })); | ||
| await waitFor(() => expect(result.current.pending).toBe(false)); | ||
| await vi.waitFor(() => expect(result.current.pending).toBe(false)); | ||
| ``` | ||
|
|
||
| `renderAppHook` wraps the hook with the same `FrameworkProvider` + `ModuleProvider` nesting `renderApp` uses in production, backed by `mockFramework` and `mockAppModules` (`@equinor/fusion-framework-app/mock`), so app teams no longer need to hand-wire those mocks in every test. | ||
|
|
||
| Requires `@testing-library/react` (added as an optional peer dependency). | ||
| The result also carries a nested `fusion` object (`fusion.framework`, `fusion.app`) — the same instances the hook rendered against, for driving a module the hook itself doesn't return — nested rather than spread directly onto the result so the underlying `renderHook` return shape stays free to evolve without ever colliding with it. | ||
|
|
||
| **Breaking change:** the `./vitest` entry-point is removed with no compatibility shim. Migrate by installing `@equinor/fusion-framework-vitest-plugin-react-app` and importing `renderAppHook` from it instead, replacing `@testing-library/react`'s `render`/`waitFor`/`act` with `vitest-browser-react`/`vitest`'s equivalents, and reading `fusion.framework`/`fusion.app` instead of the old result shape. | ||
|
|
||
| ```diff | ||
| -import { renderAppHook } from '@equinor/fusion-framework-react-app/vitest'; | ||
| +import { renderAppHook } from '@equinor/fusion-framework-vitest-plugin-react-app'; | ||
|
odinr marked this conversation as resolved.
|
||
| ``` | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@equinor/fusion-framework-react": patch | ||
| --- | ||
|
|
||
| Fix `useFrameworkModule`'s console warning to name the actually-requested module key instead of always printing `undefined`. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| "@equinor/fusion-framework-vitest-plugin-react-app": minor | ||
| --- | ||
|
|
||
| Add `@equinor/fusion-framework-vitest-plugin-react-app`: Vitest/`vitest-browser-react` helpers for testing a Fusion Framework React application inside a real, mock-backed application module scope — the same `FrameworkProvider` + `ModuleProvider` nesting `renderApp`/`createComponent` wire up in production, backed by `mockFramework` and `mockAppModules` (`@equinor/fusion-framework-app/mock`). | ||
|
|
||
| ```tsx | ||
| import { renderAppHook } from '@equinor/fusion-framework-vitest-plugin-react-app'; | ||
| import { useAccessToken } from '@equinor/fusion-framework-react-app/msal'; | ||
|
|
||
| const { result } = await renderAppHook(() => useAccessToken({ scopes: ['User.Read'] })); | ||
| await vi.waitFor(() => expect(result.current.pending).toBe(false)); | ||
| ``` | ||
|
|
||
| Highlights: | ||
|
|
||
| - `renderAppHook`/`renderAppComponent` — render a hook or component against the real `event`/`http`/`msal` module pipeline, with only the network boundary faked; the result carries a nested `fusion: { framework, app }` for driving a module directly after the initial render. | ||
| - `testApp` — a `vitest` `test` extended with `env`/`configure`/`app`/`render`/`renderHook` fixtures, for a test file whose cases share one mocked scope. | ||
| - `appTestVitePlugin` — a Vite plugin resolving an application's own manifest, config, and module-configurator (the same pipeline `ffc app build`/`ffc app dev` use) as virtual modules. | ||
| - A `/test` entry-point exporting `test`/`render`, pre-seeded from the resolved manifest/config/configure once `appTestVitePlugin` is registered — no per-test `env`/`configure` wiring. | ||
|
|
||
| This replaces `@equinor/fusion-framework-react-app`'s removed `./vitest` entry-point; see that package's changelog for migration notes. | ||
|
odinr marked this conversation as resolved.
|
||
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.