@equinor/fusion-framework-vitest-plugin-react-app 0.2.0-next.3 → 1.0.0-next.4
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 +28 -0
- package/README.md +9 -6
- package/dist/esm/app-test.js +1 -0
- package/dist/esm/app-test.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 +15 -4
- package/dist/esm/scope/resolve-fusion.js.map +1 -1
- package/dist/esm/test-app.js +39 -6
- 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 +13 -3
- package/dist/types/test-app.d.ts +44 -11
- package/dist/types/test.d.ts +25 -14
- package/dist/types/version.d.ts +1 -1
- package/docs/advanced.md +76 -12
- package/docs/migrating-an-existing-app.md +9 -9
- package/docs/module-mocks.md +2 -2
- package/package.json +5 -4
- package/src/__tests__/merge-env-config.test.ts +67 -0
- package/src/app-test.ts +1 -0
- 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 +21 -10
- package/src/test-app.tsx +49 -7
- package/src/test.tsx +12 -5
- package/src/version.ts +1 -1
- package/tsconfig.json +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @equinor/fusion-framework-vitest-plugin-react-app
|
|
2
2
|
|
|
3
|
+
## 1.0.0-next.4
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- b3d46e0: Rename the `testApp`/`test` fixtures for extending the mocked application and parent framework
|
|
8
|
+
configuration: `configure` is now `configureApp`, the new `configureFramework` fixture
|
|
9
|
+
introduced alongside it is now `configureFusion`, and `env` is now `appEnv`.
|
|
10
|
+
|
|
11
|
+
```diff
|
|
12
|
+
-const test = testApp.extend('configure', { injected: true }, () => ...);
|
|
13
|
+
+const test = testApp.extend('configureApp', { injected: true }, () => ...);
|
|
14
|
+
|
|
15
|
+
-test.override('fusion', async ({ env }) => ...);
|
|
16
|
+
+test.override('fusion', async ({ appEnv }) => ...);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`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.
|
|
20
|
+
|
|
21
|
+
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).
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
const test = baseTest.extend("appEnv", ({ appEnv }) =>
|
|
25
|
+
mergeEnvConfig(appEnv, {
|
|
26
|
+
endpoints: { "cpr-api": { url: backendBaseUrl } },
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
```
|
|
30
|
+
|
|
3
31
|
## 0.2.0-next.3
|
|
4
32
|
|
|
5
33
|
### 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,7 +302,7 @@ 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('
|
|
305
|
+
const test = testApp.extend('configureApp', { injected: true }, () =>
|
|
303
306
|
(configurator) => enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
304
307
|
);
|
|
305
308
|
|
|
@@ -316,7 +319,7 @@ A plain Vite plugin — Vitest configs are Vite configs, so this registers direc
|
|
|
316
319
|
`vitest.config.ts`, no CLI command required. It serves an application's manifest/config
|
|
317
320
|
(resolved the same way `ffc app build`/`ffc app dev` do) and its own module-configurator
|
|
318
321
|
export as virtual modules, so the `/test` entry-point's `test`/`render` need no per-test
|
|
319
|
-
`
|
|
322
|
+
`appEnv`/`configureApp` wiring.
|
|
320
323
|
|
|
321
324
|
```ts
|
|
322
325
|
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"}
|
|
@@ -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,5 +1,6 @@
|
|
|
1
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';
|
|
4
5
|
/**
|
|
5
6
|
* Resolves the parent Fusion instance backing an application module scope, building a
|
|
@@ -7,12 +8,22 @@ import { defaultAppEnv } from './default-app-env';
|
|
|
7
8
|
* given.
|
|
8
9
|
*
|
|
9
10
|
* @template TEnv - The application environment descriptor.
|
|
10
|
-
* @param env -
|
|
11
|
-
*
|
|
11
|
+
* @param options - `env` seeds the built-in app manifest mock; navigation defaults to real
|
|
12
|
+
* browser history, matching Browser Mode. `configure` runs afterwards on the same
|
|
13
|
+
* configurator — e.g. call `enableNavigation` again to override the history, or register
|
|
14
|
+
* extra modules and service discovery entries. `fusion`, an already-built parent instance,
|
|
15
|
+
* is reused as-is and skips `configure` entirely.
|
|
12
16
|
* @returns The given `fusion`, or a fresh mocked parent Fusion instance.
|
|
13
17
|
*/
|
|
14
|
-
export async function resolveFusion(
|
|
18
|
+
export async function resolveFusion(options) {
|
|
19
|
+
const { env, fusion, configure } = options ?? {};
|
|
15
20
|
return (fusion ??
|
|
16
|
-
mockFramework((configurator) =>
|
|
21
|
+
mockFramework(async (configurator) => {
|
|
22
|
+
enableAppManifestMock(configurator, env ?? defaultAppEnv);
|
|
23
|
+
enableNavigation(configurator, {
|
|
24
|
+
configure: (config) => config.setHistory(createHistory('browser')),
|
|
25
|
+
});
|
|
26
|
+
await configure?.(configurator);
|
|
27
|
+
}));
|
|
17
28
|
}
|
|
18
29
|
//# 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,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"resolve-fusion.js","sourceRoot":"","sources":["../../../src/scope/resolve-fusion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAiC,MAAM,gCAAgC,CAAC;AAC9F,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;;;;;;;;;;;;GAYG;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,SAAS,CAAC,CAAC;aACnE,CAAC,CAAC;YACH,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,7 +42,7 @@ 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('
|
|
45
|
+
* const test = testApp.extend('configureApp', { injected: true }, () =>
|
|
33
46
|
* (configurator) => enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
34
47
|
* );
|
|
35
48
|
*
|
|
@@ -39,14 +52,34 @@ import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
|
39
52
|
* });
|
|
40
53
|
* });
|
|
41
54
|
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Extend the parent framework mock with an application module
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const test = testApp.extend('configureFusion', { injected: true }, () =>
|
|
59
|
+
* (configurator) => {
|
|
60
|
+
* enableFeatureFlagMock(configurator);
|
|
61
|
+
* configurator.serviceDiscovery.addServices([
|
|
62
|
+
* { key: 'people', uri: baseUrl('people') },
|
|
63
|
+
* { key: 'context', uri: baseUrl('context') },
|
|
64
|
+
* ]);
|
|
65
|
+
* },
|
|
66
|
+
* );
|
|
67
|
+
* ```
|
|
42
68
|
*/
|
|
43
69
|
export const testApp = baseTest
|
|
44
|
-
.extend('
|
|
70
|
+
.extend('appEnv', { injected: true }, defaultAppEnv)
|
|
45
71
|
// `test.extend`'s plain-`value` overload rejects function types (ambiguous with the
|
|
46
72
|
// resolver-`fn` overload), so a function-typed fixture default must go through `fn` instead.
|
|
47
|
-
.extend('
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
.extend('configureApp', { injected: true }, () => undefined)
|
|
74
|
+
// Runs after the built-in app manifest/navigation setup, so a test can register extra
|
|
75
|
+
// framework modules, service discovery entries, or call `enableNavigation` again to
|
|
76
|
+
// override the history, without reimplementing the base setup.
|
|
77
|
+
.extend('configureFusion', { injected: true }, () => undefined)
|
|
78
|
+
// IMPORTANT: `.override('fusion', ...)` replaces this resolver entirely, so `configureFusion`
|
|
79
|
+
// is never called — reach for `configureFusion` to extend the base mock, `fusion` only to
|
|
80
|
+
// replace it outright (e.g. with a fully custom or non-mocked instance).
|
|
81
|
+
.extend('fusion', async ({ appEnv, configureFusion }) => resolveFusion({ env: appEnv, configure: configureFusion }))
|
|
82
|
+
.extend('app', async ({ configureApp, appEnv, fusion }) => mockAppModules(configureApp, appEnv, fusion))
|
|
50
83
|
.extend('render', ({ fusion, app }) => {
|
|
51
84
|
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
52
85
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;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,sFAAsF;IACtF,oFAAoF;IACpF,+DAA+D;KAC9D,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