@equinor/fusion-framework-vitest-plugin-react-app 0.2.0-next.3 → 1.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +14 -7
- package/dist/esm/app-test.js +1 -0
- package/dist/esm/app-test.js.map +1 -1
- package/dist/esm/define-project.js +4 -2
- package/dist/esm/define-project.js.map +1 -1
- package/dist/esm/merge-env-config.js +37 -0
- package/dist/esm/merge-env-config.js.map +1 -0
- package/dist/esm/resolve-app-test-env.js +5 -5
- package/dist/esm/scope/resolve-app-scope.js +1 -1
- package/dist/esm/scope/resolve-app-scope.js.map +1 -1
- package/dist/esm/scope/resolve-fusion.js +40 -5
- package/dist/esm/scope/resolve-fusion.js.map +1 -1
- package/dist/esm/test-app.js +74 -7
- package/dist/esm/test-app.js.map +1 -1
- package/dist/esm/test.js +12 -5
- package/dist/esm/test.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/app-test.d.ts +1 -0
- package/dist/types/merge-env-config.d.ts +33 -0
- package/dist/types/resolve-app-test-env.d.ts +5 -5
- package/dist/types/scope/resolve-fusion.d.ts +16 -3
- package/dist/types/test-app.d.ts +79 -12
- package/dist/types/test.d.ts +25 -14
- package/dist/types/version.d.ts +1 -1
- package/docs/advanced.md +81 -12
- package/docs/configuration.md +1 -1
- package/docs/migrating-an-existing-app.md +14 -9
- package/docs/module-mocks.md +2 -2
- package/docs/troubleshooting.md +3 -0
- package/package.json +15 -7
- package/src/__tests__/merge-env-config.test.ts +67 -0
- package/src/app-test.ts +1 -0
- package/src/define-project.ts +4 -2
- package/src/merge-env-config.ts +58 -0
- package/src/resolve-app-test-env.ts +5 -5
- package/src/scope/resolve-app-scope.ts +1 -1
- package/src/scope/resolve-fusion.ts +55 -10
- package/src/test-app.tsx +84 -8
- package/src/test.tsx +12 -5
- package/src/version.ts +1 -1
- package/tsconfig.json +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# @equinor/fusion-framework-vitest-plugin-react-app
|
|
2
2
|
|
|
3
|
+
## 1.0.0-next.5
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1813f8a: `resolveFusion` (and both the `/test` fixtures and `testApp`) now enable the feature-flag
|
|
8
|
+
mock by default, with no flags enabled, so `useFeature` needs no `localStorage` or URL
|
|
9
|
+
seeding in tests.
|
|
10
|
+
|
|
11
|
+
`@equinor/fusion-framework-module-feature-flag` is an optional peer dependency: the mock is
|
|
12
|
+
only wired up when the package is actually installed, so apps that don't use feature flags
|
|
13
|
+
aren't forced to add it. Install it to get the default mock; call `enableFeatureFlagMock`
|
|
14
|
+
again inside `configureFusion` to seed specific flags.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 1813f8a: Exclude `.d.ts` files from the default `server.warmup.clientFiles` and `optimizeDeps.entries`
|
|
19
|
+
globs in `defineProject`. Previously, an app shipping a CJS-style declaration file (for example
|
|
20
|
+
one using `export =`) failed the Vite warmup scan, since it was loaded as ESM.
|
|
21
|
+
- 1813f8a: Revert the mocked framework's default navigation history from browser history back to in-memory
|
|
22
|
+
history. Browser history leaked URL/history state between tests; `configureFusion`/`enableNavigation`
|
|
23
|
+
can still opt back into browser history for a test that specifically needs it.
|
|
24
|
+
- Updated dependencies [c8008e3]
|
|
25
|
+
- @equinor/fusion-framework-app@13.0.3-next.0
|
|
26
|
+
- @equinor/fusion-framework-cli@15.2.11-next.0
|
|
27
|
+
- @equinor/fusion-framework-module-app@8.0.6-next.0
|
|
28
|
+
- @equinor/fusion-framework-module-navigation@7.0.9-next.0
|
|
29
|
+
- @equinor/fusion-framework-react@9.0.0-next.0
|
|
30
|
+
- @equinor/fusion-framework-module-feature-flag@2.1.0-next.0
|
|
31
|
+
|
|
32
|
+
## 1.0.0-next.4
|
|
33
|
+
|
|
34
|
+
### Major Changes
|
|
35
|
+
|
|
36
|
+
- b3d46e0: Rename the `testApp`/`test` fixtures for extending the mocked application and parent framework
|
|
37
|
+
configuration: `configure` is now `configureApp`, the new `configureFramework` fixture
|
|
38
|
+
introduced alongside it is now `configureFusion`, and `env` is now `appEnv`.
|
|
39
|
+
|
|
40
|
+
```diff
|
|
41
|
+
-const test = testApp.extend('configure', { injected: true }, () => ...);
|
|
42
|
+
+const test = testApp.extend('configureApp', { injected: true }, () => ...);
|
|
43
|
+
|
|
44
|
+
-test.override('fusion', async ({ env }) => ...);
|
|
45
|
+
+test.override('fusion', async ({ appEnv }) => ...);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`configureFusion` composes with the base parent-framework mock (app manifest and navigation) the same way `configureApp` composes with the base app-module mock — see [Advanced usage](docs/advanced.md#extend-the-parent-framework-mock-with-configurefusion) for extending framework-scope modules such as feature flags, service discovery, or navigation history.
|
|
49
|
+
|
|
50
|
+
Also adds `mergeEnvConfig`, a new utility exported from the `/test` entry point for overriding one endpoint's URL (or an `environment` value) on `appEnv` without dropping the rest of the app's `AppConfig` — a plain object spread over `AppConfig` copies nothing, since it stores `environment`/`endpoints` behind private fields exposed only through getters. See [Advanced usage](docs/advanced.md#fake-an-endpoint-url-with-mergeenvconfig).
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const test = baseTest.extend("appEnv", ({ appEnv }) =>
|
|
54
|
+
mergeEnvConfig(appEnv, {
|
|
55
|
+
endpoints: { "cpr-api": { url: backendBaseUrl } },
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
```
|
|
59
|
+
|
|
3
60
|
## 0.2.0-next.3
|
|
4
61
|
|
|
5
62
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -18,9 +18,12 @@ Use this package when you need to:
|
|
|
18
18
|
resolution pipeline `ffc app build`/`ffc app dev` use, served as virtual modules by
|
|
19
19
|
`appTestVitePlugin`.
|
|
20
20
|
- **Share seeded fixture defaults across a test file** — `testApp`, a `vitest` `test` extended
|
|
21
|
-
with `
|
|
21
|
+
with `appEnv`/`configureApp`/`app`/`render`/`renderHook` fixtures, instead of repeating options on
|
|
22
22
|
every call. Each test still gets its own fresh `fusion`/`app` instances; only the seeded
|
|
23
23
|
defaults are shared, not state between tests.
|
|
24
|
+
- **Fake one endpoint's URL without losing the rest of the config** — `mergeEnvConfig` merges
|
|
25
|
+
`environment`/`endpoints` overrides into an `AppEnv`'s `config`; a plain object spread over
|
|
26
|
+
`AppConfig` (which stores both behind private fields) silently drops everything.
|
|
24
27
|
|
|
25
28
|
## Installation
|
|
26
29
|
|
|
@@ -78,7 +81,7 @@ entry-point's `test`/`render` when several cases in a file share one seeded scop
|
|
|
78
81
|
`renderAppComponent`, `renderAppHook`, `testApp`. No app-specific resolution; you pass
|
|
79
82
|
`env`/`configure` yourself.
|
|
80
83
|
- **`@equinor/fusion-framework-vitest-plugin-react-app/test`** — `test`, `render`. Require
|
|
81
|
-
`appTestVitePlugin` registered in `vitest.config.ts`; `
|
|
84
|
+
`appTestVitePlugin` registered in `vitest.config.ts`; `appEnv`/`configureApp` are resolved
|
|
82
85
|
automatically from the application's own manifest, config, and module-configurator.
|
|
83
86
|
- **`@equinor/fusion-framework-vitest-plugin-react-app/config`** — `defineProject`. Registers
|
|
84
87
|
`appTestVitePlugin`, headless Playwright/Chromium, test-file inclusion, and lazy-import
|
|
@@ -94,7 +97,7 @@ import { defineProject } from '@equinor/fusion-framework-vitest-plugin-react-app
|
|
|
94
97
|
export default defineProject();
|
|
95
98
|
```
|
|
96
99
|
|
|
97
|
-
Then use the pre-seeded `test` fixture — no per-test `
|
|
100
|
+
Then use the pre-seeded `test` fixture — no per-test `appEnv`/`configureApp` wiring:
|
|
98
101
|
|
|
99
102
|
```tsx
|
|
100
103
|
import { expect } from 'vitest';
|
|
@@ -280,7 +283,7 @@ test('mounts the child app once its script loads', async () => {
|
|
|
280
283
|
|
|
281
284
|
`vitest`'s `test`, extended with an application module scope fixture — an alternative to
|
|
282
285
|
`renderAppComponent`/`renderAppHook` for a test file whose cases share one mocked scope:
|
|
283
|
-
`
|
|
286
|
+
`appEnv`/`configureApp` become suite-level concerns, overridden once per file (or per `describe`
|
|
284
287
|
block) with `testApp.extend(...)`, rather than an options object repeated on every call.
|
|
285
288
|
`fusion`/`app` resolve lazily — a test that only destructures `app` never pays for rendering
|
|
286
289
|
anything, and one that only destructures `render`/`renderHook` gets the same mocked scope
|
|
@@ -299,8 +302,12 @@ Seed a module for every test in a suite:
|
|
|
299
302
|
|
|
300
303
|
```tsx
|
|
301
304
|
describe('with a seeded context module', () => {
|
|
302
|
-
const test = testApp.extend(
|
|
303
|
-
|
|
305
|
+
const test = testApp.extend(
|
|
306
|
+
'configureApp',
|
|
307
|
+
{ injected: true },
|
|
308
|
+
(): AppMockConfigureFn =>
|
|
309
|
+
(configurator) =>
|
|
310
|
+
enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
304
311
|
);
|
|
305
312
|
|
|
306
313
|
test('starts on the seeded context', async ({ render }) => {
|
|
@@ -316,7 +323,7 @@ A plain Vite plugin — Vitest configs are Vite configs, so this registers direc
|
|
|
316
323
|
`vitest.config.ts`, no CLI command required. It serves an application's manifest/config
|
|
317
324
|
(resolved the same way `ffc app build`/`ffc app dev` do) and its own module-configurator
|
|
318
325
|
export as virtual modules, so the `/test` entry-point's `test`/`render` need no per-test
|
|
319
|
-
`
|
|
326
|
+
`appEnv`/`configureApp` wiring.
|
|
320
327
|
|
|
321
328
|
```ts
|
|
322
329
|
appTestVitePlugin({
|
package/dist/esm/app-test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { renderAppHook, } from './render-app-hook';
|
|
2
2
|
export { renderAppComponent, } from './render-app-component';
|
|
3
3
|
export { testApp } from './test-app';
|
|
4
|
+
export { mergeEnvConfig } from './merge-env-config.js';
|
|
4
5
|
// `test`/`render` import virtual modules only served once `appTestVitePlugin`
|
|
5
6
|
// (@equinor/fusion-framework-vitest-plugin-react-app) is registered — using any export from
|
|
6
7
|
// this module requires the plugin registered in your `vitest.config.ts` `plugins`.
|
package/dist/esm/app-test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-test.js","sourceRoot":"","sources":["../../src/app-test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"app-test.js","sourceRoot":"","sources":["../../src/app-test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,cAAc,EAAgC,MAAM,uBAAuB,CAAC;AAGrF,8EAA8E;AAC9E,4FAA4F;AAC5F,mFAAmF;AACnF,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -53,13 +53,15 @@ export const defineProject = (override) => {
|
|
|
53
53
|
// pre-transforms all source up front so deps only reached via lazy/code-split imports
|
|
54
54
|
// (e.g. route components) are discovered before the first test request, not mid-run —
|
|
55
55
|
// the latter forces Vite to reload the page and fails the in-flight test file import
|
|
56
|
-
|
|
56
|
+
// `.d.ts` files are excluded: a CJS-style declaration file (e.g. one using `export =`)
|
|
57
|
+
// fails the warmup scan when loaded as ESM
|
|
58
|
+
server: { warmup: { clientFiles: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'] } },
|
|
57
59
|
// same reasoning as `server.warmup` above, but for the esbuild dep scanner: without this,
|
|
58
60
|
// its default entry detection can miss code-split route files entirely, so a package only
|
|
59
61
|
// ever imported from one of those (e.g. react-router's own deps) is discovered mid-run
|
|
60
62
|
// instead of up front — statically crawling every source file (which esbuild's scanner
|
|
61
63
|
// follows through dynamic imports too) avoids that with no per-package name needed
|
|
62
|
-
optimizeDeps: { entries: ['src/**/*.{ts,tsx}'] },
|
|
64
|
+
optimizeDeps: { entries: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'] },
|
|
63
65
|
};
|
|
64
66
|
// a function replaces the config outright; a plain object deep-merges onto it via Vite's own mergeConfig
|
|
65
67
|
const resolved = typeof override === 'function'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-project.js","sourceRoot":"","sources":["../../src/define-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EACL,aAAa,IAAI,mBAAmB,EACpC,WAAW,GAEZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAW/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgC,EAAuB,EAAE;IACrF,MAAM,QAAQ,GAAwB;QACpC,OAAO,EAAE,CAAC,iBAAiB,EAAE,CAAC;QAC9B,IAAI,EAAE;YACJ,OAAO,EAAE,CAAC,+BAA+B,CAAC;YAC1C,OAAO,EAAE;gBACP,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,UAAU,EAAE;gBACtB,QAAQ,EAAE,IAAI;gBACd,iFAAiF;gBACjF,2FAA2F;gBAC3F,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;gBACtC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;aACrC;SACF;QACD,sFAAsF;QACtF,sFAAsF;QACtF,qFAAqF;QACrF,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,mBAAmB,CAAC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"define-project.js","sourceRoot":"","sources":["../../src/define-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EACL,aAAa,IAAI,mBAAmB,EACpC,WAAW,GAEZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAW/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgC,EAAuB,EAAE;IACrF,MAAM,QAAQ,GAAwB;QACpC,OAAO,EAAE,CAAC,iBAAiB,EAAE,CAAC;QAC9B,IAAI,EAAE;YACJ,OAAO,EAAE,CAAC,+BAA+B,CAAC;YAC1C,OAAO,EAAE;gBACP,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,UAAU,EAAE;gBACtB,QAAQ,EAAE,IAAI;gBACd,iFAAiF;gBACjF,2FAA2F;gBAC3F,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE;gBACtC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;aACrC;SACF;QACD,sFAAsF;QACtF,sFAAsF;QACtF,qFAAqF;QACrF,uFAAuF;QACvF,2CAA2C;QAC3C,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,EAAE,EAAE;QAC5E,0FAA0F;QAC1F,0FAA0F;QAC1F,uFAAuF;QACvF,uFAAuF;QACvF,mFAAmF;QACnF,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,EAAE;KACnE,CAAC;IACF,yGAAyG;IACzG,MAAM,QAAQ,GACZ,OAAO,QAAQ,KAAK,UAAU;QAC5B,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACpB,CAAC,CAAC,QAAQ;YACR,CAAC,CAAE,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAyB;YAC1D,CAAC,CAAC,QAAQ,CAAC;IACjB,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AppConfig } from '@equinor/fusion-framework-module-app';
|
|
2
|
+
/**
|
|
3
|
+
* Merges `environment`/`endpoints` overrides into an `AppEnv`'s `config`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* `AppConfig` stores both behind private fields exposed only through getters, so
|
|
7
|
+
* `{ ...env.config, endpoints: {...} }` silently drops everything it doesn't explicitly
|
|
8
|
+
* restate — a plain object spread copies no own enumerable properties off an `AppConfig`
|
|
9
|
+
* instance. Reach for this instead of hand-rolling that merge in a test fixture.
|
|
10
|
+
*
|
|
11
|
+
* @template TEnv - The `AppEnv` shape being merged into.
|
|
12
|
+
* @param env - The `AppEnv` to merge overrides into; left untouched, `config` may be omitted.
|
|
13
|
+
* @param overrides - Partial `environment`/`endpoints` values, merged over any existing config.
|
|
14
|
+
* @returns A new `AppEnv` with a new `AppConfig` reflecting the merge.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const test = testApp.extend('appEnv', ({ appEnv }) =>
|
|
18
|
+
* mergeEnvConfig(appEnv, { endpoints: { 'cpr-api': { url: backendBaseUrl } } }),
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function mergeEnvConfig(env, overrides) {
|
|
23
|
+
// each overridden endpoint keeps any field the caller didn't explicitly override
|
|
24
|
+
const endpoints = Object.entries(overrides.endpoints ?? {}).reduce(
|
|
25
|
+
// defaults, then any existing endpoint, then the override (override wins)
|
|
26
|
+
(acc, [key, override]) => Object.assign(acc, { [key]: Object.assign({ url: '', scopes: [] }, acc[key], override) }), { ...env.config?.endpoints });
|
|
27
|
+
// caller-supplied environment values win over the existing ones
|
|
28
|
+
return {
|
|
29
|
+
...env,
|
|
30
|
+
config: new AppConfig({
|
|
31
|
+
environment: { ...env.config?.environment, ...overrides.environment },
|
|
32
|
+
endpoints,
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export default mergeEnvConfig;
|
|
37
|
+
//# sourceMappingURL=merge-env-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-env-config.js","sourceRoot":"","sources":["../../src/merge-env-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAcjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAS,EACT,SAEC;IAED,iFAAiF;IACjF,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM;IAChE,0EAA0E;IAC1E,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,CACvB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,EAC3F,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,CAC7B,CAAC;IACF,gEAAgE;IAChE,OAAO;QACL,GAAG,GAAG;QACN,MAAM,EAAE,IAAI,SAAS,CAAC;YACpB,WAAW,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC,WAAW,EAAE;YACrE,SAAS;SACV,CAAC;KACH,CAAC;AACJ,CAAC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -8,11 +8,11 @@ import { resolvePackage } from '@equinor/fusion-framework-cli/utils';
|
|
|
8
8
|
* back to an empty config if none exists.
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
|
-
* Intended to seed `@equinor/fusion-framework-vitest-plugin-react-app/test`'s `testApp` `
|
|
11
|
+
* Intended to seed `@equinor/fusion-framework-vitest-plugin-react-app/test`'s `testApp` `appEnv` fixture, so
|
|
12
12
|
* a test suite exercises the application's real manifest/config instead of a hand-maintained
|
|
13
13
|
* duplicate. Anything a specific test still needs faked (a missing endpoint, a different
|
|
14
|
-
* `appKey`) can be layered on top with `testApp.extend('
|
|
15
|
-
* `test.override('
|
|
14
|
+
* `appKey`) can be layered on top with `testApp.extend('appEnv', ...)` or a per-test
|
|
15
|
+
* `test.override('appEnv', ...)`.
|
|
16
16
|
*
|
|
17
17
|
* @param options - Resolution options; `entrypoint` defaults to the current working directory.
|
|
18
18
|
* @returns The resolved application manifest and config.
|
|
@@ -25,8 +25,8 @@ import { resolvePackage } from '@equinor/fusion-framework-cli/utils';
|
|
|
25
25
|
* import { configure } from '../config';
|
|
26
26
|
*
|
|
27
27
|
* const test = testApp
|
|
28
|
-
* .extend('
|
|
29
|
-
* .extend('
|
|
28
|
+
* .extend('appEnv', { injected: true }, () => resolveAppTestEnv())
|
|
29
|
+
* .extend('configureApp', { injected: true }, () => configure);
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
export const resolveAppTestEnv = async (options) => {
|
|
@@ -14,7 +14,7 @@ import { defaultAppEnv } from './default-app-env';
|
|
|
14
14
|
export async function resolveAppScope(options) {
|
|
15
15
|
const { configure, env, fusion: providedFusion } = options ?? {};
|
|
16
16
|
const resolvedEnv = env ?? defaultAppEnv;
|
|
17
|
-
const framework = await resolveFusion(resolvedEnv, providedFusion);
|
|
17
|
+
const framework = await resolveFusion({ env: resolvedEnv, fusion: providedFusion });
|
|
18
18
|
const app = await mockAppModules(configure, resolvedEnv, framework);
|
|
19
19
|
return { framework, app };
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-app-scope.js","sourceRoot":"","sources":["../../../src/scope/resolve-app-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAMpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAelD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAGnC,OAID;IACC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACjE,MAAM,WAAW,GAAG,GAAG,IAAK,aAAsB,CAAC;IACnD,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-app-scope.js","sourceRoot":"","sources":["../../../src/scope/resolve-app-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAMpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAelD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAGnC,OAID;IACC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACjE,MAAM,WAAW,GAAG,GAAG,IAAK,aAAsB,CAAC;IACnD,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC;IACpF,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -1,18 +1,53 @@
|
|
|
1
|
-
import { mockFramework } from '@equinor/fusion-framework/mock';
|
|
1
|
+
import { mockFramework, } from '@equinor/fusion-framework/mock';
|
|
2
2
|
import { enableAppManifestMock } from '@equinor/fusion-framework-app/mock';
|
|
3
|
+
import { enableNavigation, createHistory } from '@equinor/fusion-framework-module-navigation';
|
|
3
4
|
import { defaultAppEnv } from './default-app-env';
|
|
5
|
+
/**
|
|
6
|
+
* Enables the feature-flag mock only when `@equinor/fusion-framework-module-feature-flag` — an
|
|
7
|
+
* optional peer dependency — is actually installed, so apps that don't use feature flags aren't
|
|
8
|
+
* forced to install a module they never reference.
|
|
9
|
+
*/
|
|
10
|
+
async function enableFeatureFlagMockIfAvailable(configurator) {
|
|
11
|
+
try {
|
|
12
|
+
const { enableFeatureFlagMock } = await import('@equinor/fusion-framework-module-feature-flag/mock');
|
|
13
|
+
enableFeatureFlagMock(configurator);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
// re-throw anything other than the optional peer being missing, so a real
|
|
17
|
+
// registration failure isn't silently swallowed
|
|
18
|
+
if (error instanceof Error &&
|
|
19
|
+
(error.message.includes('Cannot find module') || error.message.includes('MODULE_NOT_FOUND'))) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
4
25
|
/**
|
|
5
26
|
* Resolves the parent Fusion instance backing an application module scope, building a
|
|
6
27
|
* fresh {@link mockFramework} instance with this app's own manifest served when none is
|
|
7
28
|
* given.
|
|
8
29
|
*
|
|
9
30
|
* @template TEnv - The application environment descriptor.
|
|
10
|
-
* @param env -
|
|
11
|
-
*
|
|
31
|
+
* @param options - `env` seeds the built-in app manifest mock; navigation defaults to in-memory
|
|
32
|
+
* history, so tests don't leak URL/history state between runs. Feature flags default to the
|
|
33
|
+
* in-memory feature-flag mock, with none enabled, when the optional
|
|
34
|
+
* `@equinor/fusion-framework-module-feature-flag` peer dependency is installed. `configure`
|
|
35
|
+
* runs afterwards on the same configurator — e.g. call `enableNavigation` or
|
|
36
|
+
* `enableFeatureFlagMock` again to override either, or register extra modules and service
|
|
37
|
+
* discovery entries. `fusion`, an already-built parent instance, is reused as-is and skips
|
|
38
|
+
* `configure` entirely.
|
|
12
39
|
* @returns The given `fusion`, or a fresh mocked parent Fusion instance.
|
|
13
40
|
*/
|
|
14
|
-
export async function resolveFusion(
|
|
41
|
+
export async function resolveFusion(options) {
|
|
42
|
+
const { env, fusion, configure } = options ?? {};
|
|
15
43
|
return (fusion ??
|
|
16
|
-
mockFramework((configurator) =>
|
|
44
|
+
mockFramework(async (configurator) => {
|
|
45
|
+
enableAppManifestMock(configurator, env ?? defaultAppEnv);
|
|
46
|
+
enableNavigation(configurator, {
|
|
47
|
+
configure: (config) => config.setHistory(createHistory('memory')),
|
|
48
|
+
});
|
|
49
|
+
await enableFeatureFlagMockIfAvailable(configurator);
|
|
50
|
+
await configure?.(configurator);
|
|
51
|
+
}));
|
|
17
52
|
}
|
|
18
53
|
//# sourceMappingURL=resolve-fusion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-fusion.js","sourceRoot":"","sources":["../../../src/scope/resolve-fusion.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"resolve-fusion.js","sourceRoot":"","sources":["../../../src/scope/resolve-fusion.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,GAGd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAE3E,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAG9F,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,KAAK,UAAU,gCAAgC,CAC7C,YAAsE;IAEtE,IAAI,CAAC;QACH,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAC5C,oDAAoD,CACrD,CAAC;QACF,qBAAqB,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,0EAA0E;QAC1E,gDAAgD;QAChD,IACE,KAAK,YAAY,KAAK;YACtB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAC5F,CAAC;YACD,OAAO;QACT,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAA+B,OAIjE;IACC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACjD,OAAO,CACL,MAAM;QACN,aAAa,CAAgC,KAAK,EAAE,YAAY,EAAE,EAAE;YAClE,qBAAqB,CAAC,YAAY,EAAE,GAAG,IAAK,aAAsB,CAAC,CAAC;YACpE,gBAAgB,CAAC,YAAY,EAAE;gBAC7B,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;aAClE,CAAC,CAAC;YACH,MAAM,gCAAgC,CAAC,YAAY,CAAC,CAAC;YACrD,MAAM,SAAS,EAAE,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/dist/esm/test-app.js
CHANGED
|
@@ -7,7 +7,7 @@ import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
|
7
7
|
*
|
|
8
8
|
* @remarks
|
|
9
9
|
* An alternative to {@link renderAppComponent}/{@link renderAppHook} for a test file whose
|
|
10
|
-
* cases share seeded fixture defaults: `
|
|
10
|
+
* cases share seeded fixture defaults: `appEnv`/`configureApp` become suite-level concerns,
|
|
11
11
|
* overridden once per file (or per `describe` block) with `testApp.extend(...)`, rather than
|
|
12
12
|
* an options object repeated on every call. `fusion`/`app` are still instantiated fresh per
|
|
13
13
|
* test — only the seeded defaults are shared, not state between tests. They also resolve
|
|
@@ -18,6 +18,19 @@ import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
|
18
18
|
* one-off test whose configuration is not shared by the rest of the file; reach for
|
|
19
19
|
* `testApp` when several cases in a file share one set of seeded fixture defaults.
|
|
20
20
|
*
|
|
21
|
+
* @remarks `configureApp`/`configureFusion` default to `undefined` here
|
|
22
|
+
* Unlike `@equinor/fusion-framework-vitest-plugin-react-app/test`'s `test`, this `testApp` does
|
|
23
|
+
* not resolve the app's real `src/config.ts` — it requires `appTestVitePlugin`'s Vite virtual
|
|
24
|
+
* modules to load that file as live code, which `testApp` (no Vite dependency) cannot do. Extend
|
|
25
|
+
* `test` from `/test` instead when a suite needs to compose with the app's real configuration.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Overriding `fusion` bypasses `configureFusion`
|
|
28
|
+
* `fusion` and `configureFusion` are not independent: `fusion`'s default resolver is what
|
|
29
|
+
* calls `configureFusion`. `.override('fusion', ...)` replaces that resolver outright, so a
|
|
30
|
+
* `configureFusion` override on the same test/suite is silently never called. Use
|
|
31
|
+
* `configureFusion` to extend the base framework mock; use `fusion` only to replace it
|
|
32
|
+
* entirely (e.g. with a fully custom or non-mocked instance).
|
|
33
|
+
*
|
|
21
34
|
* @example
|
|
22
35
|
* ```tsx
|
|
23
36
|
* testApp('resolves current context', async ({ app, render }) => {
|
|
@@ -29,8 +42,12 @@ import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
|
29
42
|
* @example Seed a module for every test in a suite
|
|
30
43
|
* ```tsx
|
|
31
44
|
* describe('with a seeded context module', () => {
|
|
32
|
-
* const test = testApp.extend(
|
|
33
|
-
*
|
|
45
|
+
* const test = testApp.extend(
|
|
46
|
+
* 'configureApp',
|
|
47
|
+
* { injected: true },
|
|
48
|
+
* (): AppMockConfigureFn =>
|
|
49
|
+
* (configurator) =>
|
|
50
|
+
* enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
34
51
|
* );
|
|
35
52
|
*
|
|
36
53
|
* test('starts on the seeded context', async ({ render }) => {
|
|
@@ -39,14 +56,64 @@ import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
|
39
56
|
* });
|
|
40
57
|
* });
|
|
41
58
|
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Type `app`'s registered modules for consumers
|
|
61
|
+
* ```tsx
|
|
62
|
+
* // `configureApp`'s `TModules` generic only types that callback's own `configurator` parameter.
|
|
63
|
+
* // `app`'s type was already fixed (to `unknown`) when the base `testApp` chain defined it, so a
|
|
64
|
+
* // later `configureApp` override does not retroactively change what `app` is typed as. Re-extend
|
|
65
|
+
* // `app` too, with the same `TModules`, to get a typed `app.navigation` in tests.
|
|
66
|
+
* const test = testApp
|
|
67
|
+
* .extend(
|
|
68
|
+
* 'configureApp',
|
|
69
|
+
* { injected: true },
|
|
70
|
+
* ({ configureApp }): AppMockConfigureFn<[NavigationModule]> =>
|
|
71
|
+
* async (configurator, args) => {
|
|
72
|
+
* await configureApp?.(configurator, args);
|
|
73
|
+
* enableNavigation(configurator, '/app');
|
|
74
|
+
* },
|
|
75
|
+
* )
|
|
76
|
+
* .extend('app', ({ configureApp, appEnv, fusion }) =>
|
|
77
|
+
* mockAppModules<[NavigationModule], AppEnv>(configureApp, appEnv as AppEnv, fusion),
|
|
78
|
+
* );
|
|
79
|
+
*
|
|
80
|
+
* test('exposes the navigation module', async ({ app }) => {
|
|
81
|
+
* expect(app.navigation).toBeDefined();
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Extend the parent framework mock with an application module
|
|
86
|
+
* ```tsx
|
|
87
|
+
* const test = testApp.extend(
|
|
88
|
+
* 'configureFusion',
|
|
89
|
+
* { injected: true },
|
|
90
|
+
* (): FrameworkMockConfigureFn<[AppModule, NavigationModule]> =>
|
|
91
|
+
* (configurator) => {
|
|
92
|
+
* // seed a specific flag rather than merely enabling the mock — that's already the
|
|
93
|
+
* // default when the optional feature-flag peer dependency is installed
|
|
94
|
+
* enableFeatureFlagMock(configurator, (mock) => mock.addFeature({ key: 'new-search', enabled: true }));
|
|
95
|
+
* configurator.serviceDiscovery.addServices([
|
|
96
|
+
* { key: 'people', uri: baseUrl('people') },
|
|
97
|
+
* { key: 'context', uri: baseUrl('context') },
|
|
98
|
+
* ]);
|
|
99
|
+
* },
|
|
100
|
+
* );
|
|
101
|
+
* ```
|
|
42
102
|
*/
|
|
43
103
|
export const testApp = baseTest
|
|
44
|
-
.extend('
|
|
104
|
+
.extend('appEnv', { injected: true }, defaultAppEnv)
|
|
45
105
|
// `test.extend`'s plain-`value` overload rejects function types (ambiguous with the
|
|
46
106
|
// resolver-`fn` overload), so a function-typed fixture default must go through `fn` instead.
|
|
47
|
-
.extend('
|
|
48
|
-
|
|
49
|
-
|
|
107
|
+
.extend('configureApp', { injected: true }, () => undefined)
|
|
108
|
+
// Runs after the built-in app manifest/navigation/feature-flag setup, so a test can register
|
|
109
|
+
// extra framework modules, service discovery entries, or call `enableNavigation`/
|
|
110
|
+
// `enableFeatureFlagMock` again to override either, without reimplementing the base setup.
|
|
111
|
+
.extend('configureFusion', { injected: true }, () => undefined)
|
|
112
|
+
// IMPORTANT: `.override('fusion', ...)` replaces this resolver entirely, so `configureFusion`
|
|
113
|
+
// is never called — reach for `configureFusion` to extend the base mock, `fusion` only to
|
|
114
|
+
// replace it outright (e.g. with a fully custom or non-mocked instance).
|
|
115
|
+
.extend('fusion', async ({ appEnv, configureFusion }) => resolveFusion({ env: appEnv, configure: configureFusion }))
|
|
116
|
+
.extend('app', async ({ configureApp, appEnv, fusion }) => mockAppModules(configureApp, appEnv, fusion))
|
|
50
117
|
.extend('render', ({ fusion, app }) => {
|
|
51
118
|
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
52
119
|
return (ui, options) => render(ui, { ...options, wrapper });
|
package/dist/esm/test-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-app.js","sourceRoot":"","sources":["../../src/test-app.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"test-app.js","sourceRoot":"","sources":["../../src/test-app.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAOpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ;KAC5B,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,aAAa,CAAC;IACpD,oFAAoF;IACpF,6FAA6F;KAC5F,MAAM,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,SAA2C,CAAC;IAC9F,6FAA6F;IAC7F,kFAAkF;IAClF,2FAA2F;KAC1F,MAAM,CACL,iBAAiB,EACjB,EAAE,QAAQ,EAAE,IAAI,EAAE,EAClB,GAAG,EAAE,CAAC,SAAgF,CACvF;IACD,8FAA8F;IAC9F,0FAA0F;IAC1F,yEAAyE;KACxE,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,EAAE,CACtD,aAAa,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAC3D;KACA,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CACxD,cAAc,CAAkB,YAAY,EAAE,MAAgB,EAAE,MAAM,CAAC,CACxE;KACA,MAAM,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE;IACpC,MAAM,OAAO,GAAG,qBAAqB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAClE,OAAO,CAAC,EAAgB,EAAE,OAAwC,EAAE,EAAE,CACpE,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC;KACD,MAAM,CAAC,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE;IACxC,MAAM,OAAO,GAAG,qBAAqB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAClE,OAAO,CACL,EAAoC,EACpC,OAAmD,EACnD,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEL,eAAe,OAAO,CAAC"}
|
package/dist/esm/test.js
CHANGED
|
@@ -2,7 +2,7 @@ import { testApp as baseTestApp } from './test-app';
|
|
|
2
2
|
// resolved at test-time by `appTestVitePlugin` (@equinor/fusion-framework-vitest-plugin-react-app);
|
|
3
3
|
// see virtual-modules.d.ts for the ambient module declarations
|
|
4
4
|
import { manifest, config } from 'virtual:fusion-app-test-env';
|
|
5
|
-
import { configure } from 'virtual:fusion-app-test-configure';
|
|
5
|
+
import { configure as configureApp } from 'virtual:fusion-app-test-configure';
|
|
6
6
|
/**
|
|
7
7
|
* `vitest`'s `test`, pre-seeded with the application's own manifest, config, and
|
|
8
8
|
* module-configurator, resolved the same way `ffc app build`/`ffc app dev` resolve them.
|
|
@@ -12,8 +12,15 @@ import { configure } from 'virtual:fusion-app-test-configure';
|
|
|
12
12
|
* your `vitest.config.ts` `plugins`, which serves the virtual modules backing this fixture.
|
|
13
13
|
* Running the same test file without the plugin registered fails to resolve those imports.
|
|
14
14
|
*
|
|
15
|
-
* Per-test mocking still works exactly like the base `testApp`: `.extend('
|
|
16
|
-
* a per-case `test.override('
|
|
15
|
+
* Per-test mocking still works exactly like the base `testApp`: `.extend('configureApp', ...)` or
|
|
16
|
+
* a per-case `test.override('appEnv', ...)` layers on top of the resolved values.
|
|
17
|
+
*
|
|
18
|
+
* @remarks `.override('configureApp', ...)` replaces the app's real `configure`
|
|
19
|
+
* This fixture's default value *is* the app's real `src/config.ts` `configure` export.
|
|
20
|
+
* `.override('configureApp', ...)` replaces that default outright, so an override that doesn't
|
|
21
|
+
* itself call the real `configure(configurator, args)` skips the app's production module setup
|
|
22
|
+
* entirely, rather than composing with it. See [Advanced usage](../docs/advanced.md) for the
|
|
23
|
+
* compose-safely pattern.
|
|
17
24
|
*
|
|
18
25
|
* @example
|
|
19
26
|
* ```tsx
|
|
@@ -27,7 +34,7 @@ import { configure } from 'virtual:fusion-app-test-configure';
|
|
|
27
34
|
* ```
|
|
28
35
|
*/
|
|
29
36
|
export const test = baseTestApp
|
|
30
|
-
.extend('
|
|
31
|
-
.extend('
|
|
37
|
+
.extend('appEnv', { injected: true }, { manifest, config })
|
|
38
|
+
.extend('configureApp', { injected: true }, () => configureApp);
|
|
32
39
|
export default test;
|
|
33
40
|
//# sourceMappingURL=test.js.map
|
package/dist/esm/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,oGAAoG;AACpG,+DAA+D;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpD,oGAAoG;AACpG,+DAA+D;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW;KAC5B,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;KAC1D,MAAM,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;AAElE,eAAe,IAAI,CAAC"}
|
package/dist/esm/version.js
CHANGED