@equinor/fusion-framework-vitest-plugin-react-app 1.0.0 → 1.0.2
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/dist/esm/index.js +9 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resolve-app-test-env.js +8 -2
- package/dist/esm/resolve-app-test-env.js.map +1 -1
- package/dist/esm/scope/resolve-fusion.js +22 -24
- package/dist/esm/scope/resolve-fusion.js.map +1 -1
- package/dist/esm/test-app.js +5 -8
- package/dist/esm/test-app.js.map +1 -1
- package/dist/esm/test.js +2 -1
- package/dist/esm/test.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/resolve-app-test-env.d.ts +3 -1
- package/dist/types/scope/resolve-fusion.d.ts +6 -7
- package/dist/types/test-app.d.ts +12 -11
- package/dist/types/test.d.ts +20 -9
- package/dist/types/version.d.ts +1 -1
- package/package.json +17 -19
- package/CHANGELOG.md +0 -81
- package/docs/advanced.md +0 -209
- package/docs/configuration.md +0 -112
- package/docs/getting-started.md +0 -66
- package/docs/migrating-an-existing-app.md +0 -202
- package/docs/module-mocks.md +0 -120
- package/docs/overview.md +0 -49
- package/docs/troubleshooting.md +0 -67
- package/docs/why-browser-mode.md +0 -128
- package/src/__tests__/app-test-vite-plugin.test.ts +0 -109
- package/src/__tests__/merge-env-config.test.ts +0 -67
- package/src/__tests__/resolve-app-test-env.test.ts +0 -83
- package/src/app-test.ts +0 -19
- package/src/define-project.ts +0 -91
- package/src/index.ts +0 -124
- package/src/merge-env-config.ts +0 -58
- package/src/render-app-component.tsx +0 -116
- package/src/render-app-hook.tsx +0 -135
- package/src/render.tsx +0 -64
- package/src/resolve-app-test-env.ts +0 -132
- package/src/scope/create-app-scope-wrapper.tsx +0 -26
- package/src/scope/default-app-env.ts +0 -13
- package/src/scope/index.ts +0 -4
- package/src/scope/resolve-app-scope.ts +0 -46
- package/src/scope/resolve-fusion.ts +0 -74
- package/src/test-app.tsx +0 -148
- package/src/test.tsx +0 -42
- package/src/version.ts +0 -2
- package/src/virtual-modules.d.ts +0 -12
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -10
package/src/test-app.tsx
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
2
|
-
import { test as baseTest } from 'vitest';
|
|
3
|
-
import { render, renderHook } from 'vitest-browser-react';
|
|
4
|
-
import type { RenderOptions, RenderHookOptions } from 'vitest-browser-react';
|
|
5
|
-
|
|
6
|
-
import { mockAppModules } from '@equinor/fusion-framework-app/mock';
|
|
7
|
-
import type { AppMockConfigureFn } from '@equinor/fusion-framework-app/mock';
|
|
8
|
-
import type { AppEnv } from '@equinor/fusion-framework-app';
|
|
9
|
-
import type { AppModule } from '@equinor/fusion-framework-module-app';
|
|
10
|
-
import type { NavigationModule } from '@equinor/fusion-framework-module-navigation';
|
|
11
|
-
import type { FrameworkMockConfigureFn } from '@equinor/fusion-framework/mock';
|
|
12
|
-
|
|
13
|
-
import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `vitest`'s `test`, extended with an application module scope fixture.
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* An alternative to {@link renderAppComponent}/{@link renderAppHook} for a test file whose
|
|
20
|
-
* cases share seeded fixture defaults: `appEnv`/`configureApp` become suite-level concerns,
|
|
21
|
-
* overridden once per file (or per `describe` block) with `testApp.extend(...)`, rather than
|
|
22
|
-
* an options object repeated on every call. `fusion`/`app` are still instantiated fresh per
|
|
23
|
-
* test — only the seeded defaults are shared, not state between tests. They also resolve
|
|
24
|
-
* lazily: a test that only destructures `app` never pays for rendering anything, and one
|
|
25
|
-
* that only destructures `render`/`renderHook` gets the same fixture wiring automatically.
|
|
26
|
-
*
|
|
27
|
-
* Both entry points stay supported: reach for `renderAppComponent`/`renderAppHook` for a
|
|
28
|
-
* one-off test whose configuration is not shared by the rest of the file; reach for
|
|
29
|
-
* `testApp` when several cases in a file share one set of seeded fixture defaults.
|
|
30
|
-
*
|
|
31
|
-
* @remarks `configureApp`/`configureFusion` default to `undefined` here
|
|
32
|
-
* Unlike `@equinor/fusion-framework-vitest-plugin-react-app/test`'s `test`, this `testApp` does
|
|
33
|
-
* not resolve the app's real `src/config.ts` — it requires `appTestVitePlugin`'s Vite virtual
|
|
34
|
-
* modules to load that file as live code, which `testApp` (no Vite dependency) cannot do. Extend
|
|
35
|
-
* `test` from `/test` instead when a suite needs to compose with the app's real configuration.
|
|
36
|
-
*
|
|
37
|
-
* @remarks Overriding `fusion` bypasses `configureFusion`
|
|
38
|
-
* `fusion` and `configureFusion` are not independent: `fusion`'s default resolver is what
|
|
39
|
-
* calls `configureFusion`. `.override('fusion', ...)` replaces that resolver outright, so a
|
|
40
|
-
* `configureFusion` override on the same test/suite is silently never called. Use
|
|
41
|
-
* `configureFusion` to extend the base framework mock; use `fusion` only to replace it
|
|
42
|
-
* entirely (e.g. with a fully custom or non-mocked instance).
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```tsx
|
|
46
|
-
* testApp('resolves current context', async ({ app, render }) => {
|
|
47
|
-
* const screen = await render(<App />);
|
|
48
|
-
* expect(app.context).toBeDefined();
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @example Seed a module for every test in a suite
|
|
53
|
-
* ```tsx
|
|
54
|
-
* describe('with a seeded context module', () => {
|
|
55
|
-
* const test = testApp.extend(
|
|
56
|
-
* 'configureApp',
|
|
57
|
-
* { injected: true },
|
|
58
|
-
* (): AppMockConfigureFn =>
|
|
59
|
-
* (configurator) =>
|
|
60
|
-
* enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
61
|
-
* );
|
|
62
|
-
*
|
|
63
|
-
* test('starts on the seeded context', async ({ render }) => {
|
|
64
|
-
* const screen = await render(<App />);
|
|
65
|
-
* await expect.element(screen.getByText(projectA.title)).toBeVisible();
|
|
66
|
-
* });
|
|
67
|
-
* });
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @example Type `app`'s registered modules for consumers
|
|
71
|
-
* ```tsx
|
|
72
|
-
* // `configureApp`'s `TModules` generic only types that callback's own `configurator` parameter.
|
|
73
|
-
* // `app`'s type was already fixed (to `unknown`) when the base `testApp` chain defined it, so a
|
|
74
|
-
* // later `configureApp` override does not retroactively change what `app` is typed as. Re-extend
|
|
75
|
-
* // `app` too, with the same `TModules`, to get a typed `app.navigation` in tests.
|
|
76
|
-
* const test = testApp
|
|
77
|
-
* .extend(
|
|
78
|
-
* 'configureApp',
|
|
79
|
-
* { injected: true },
|
|
80
|
-
* ({ configureApp }): AppMockConfigureFn<[NavigationModule]> =>
|
|
81
|
-
* async (configurator, args) => {
|
|
82
|
-
* await configureApp?.(configurator, args);
|
|
83
|
-
* enableNavigation(configurator, '/app');
|
|
84
|
-
* },
|
|
85
|
-
* )
|
|
86
|
-
* .extend('app', ({ configureApp, appEnv, fusion }) =>
|
|
87
|
-
* mockAppModules<[NavigationModule], AppEnv>(configureApp, appEnv as AppEnv, fusion),
|
|
88
|
-
* );
|
|
89
|
-
*
|
|
90
|
-
* test('exposes the navigation module', async ({ app }) => {
|
|
91
|
-
* expect(app.navigation).toBeDefined();
|
|
92
|
-
* });
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @example Extend the parent framework mock with an application module
|
|
96
|
-
* ```tsx
|
|
97
|
-
* const test = testApp.extend(
|
|
98
|
-
* 'configureFusion',
|
|
99
|
-
* { injected: true },
|
|
100
|
-
* (): FrameworkMockConfigureFn<[AppModule, NavigationModule]> =>
|
|
101
|
-
* (configurator) => {
|
|
102
|
-
* // seed a specific flag rather than merely enabling the mock — that's already the
|
|
103
|
-
* // default when the optional feature-flag peer dependency is installed
|
|
104
|
-
* enableFeatureFlagMock(configurator, (mock) => mock.addFeature({ key: 'new-search', enabled: true }));
|
|
105
|
-
* configurator.serviceDiscovery.addServices([
|
|
106
|
-
* { key: 'people', uri: baseUrl('people') },
|
|
107
|
-
* { key: 'context', uri: baseUrl('context') },
|
|
108
|
-
* ]);
|
|
109
|
-
* },
|
|
110
|
-
* );
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export const testApp = baseTest
|
|
114
|
-
.extend('appEnv', { injected: true }, defaultAppEnv)
|
|
115
|
-
// `test.extend`'s plain-`value` overload rejects function types (ambiguous with the
|
|
116
|
-
// resolver-`fn` overload), so a function-typed fixture default must go through `fn` instead.
|
|
117
|
-
.extend('configureApp', { injected: true }, () => undefined as AppMockConfigureFn | undefined)
|
|
118
|
-
// Runs after the built-in app manifest/navigation/feature-flag setup, so a test can register
|
|
119
|
-
// extra framework modules, service discovery entries, or call `enableNavigation`/
|
|
120
|
-
// `enableFeatureFlagMock` again to override either, without reimplementing the base setup.
|
|
121
|
-
.extend(
|
|
122
|
-
'configureFusion',
|
|
123
|
-
{ injected: true },
|
|
124
|
-
() => undefined as FrameworkMockConfigureFn<[AppModule, NavigationModule]> | undefined,
|
|
125
|
-
)
|
|
126
|
-
// IMPORTANT: `.override('fusion', ...)` replaces this resolver entirely, so `configureFusion`
|
|
127
|
-
// is never called — reach for `configureFusion` to extend the base mock, `fusion` only to
|
|
128
|
-
// replace it outright (e.g. with a fully custom or non-mocked instance).
|
|
129
|
-
.extend('fusion', async ({ appEnv, configureFusion }) =>
|
|
130
|
-
resolveFusion({ env: appEnv, configure: configureFusion }),
|
|
131
|
-
)
|
|
132
|
-
.extend('app', async ({ configureApp, appEnv, fusion }) =>
|
|
133
|
-
mockAppModules<unknown, AppEnv>(configureApp, appEnv as AppEnv, fusion),
|
|
134
|
-
)
|
|
135
|
-
.extend('render', ({ fusion, app }) => {
|
|
136
|
-
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
137
|
-
return (ui: ReactElement, options?: Omit<RenderOptions, 'wrapper'>) =>
|
|
138
|
-
render(ui, { ...options, wrapper });
|
|
139
|
-
})
|
|
140
|
-
.extend('renderHook', ({ fusion, app }) => {
|
|
141
|
-
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
142
|
-
return <Result, Props = undefined>(
|
|
143
|
-
cb: (initialProps?: Props) => Result,
|
|
144
|
-
options?: Omit<RenderHookOptions<Props>, 'wrapper'>,
|
|
145
|
-
) => renderHook(cb, { ...options, wrapper });
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
export default testApp;
|
package/src/test.tsx
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { testApp as baseTestApp } from './test-app';
|
|
2
|
-
|
|
3
|
-
// resolved at test-time by `appTestVitePlugin` (@equinor/fusion-framework-vitest-plugin-react-app);
|
|
4
|
-
// see virtual-modules.d.ts for the ambient module declarations
|
|
5
|
-
import { manifest, config } from 'virtual:fusion-app-test-env';
|
|
6
|
-
import { configure as configureApp } from 'virtual:fusion-app-test-configure';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `vitest`'s `test`, pre-seeded with the application's own manifest, config, and
|
|
10
|
-
* module-configurator, resolved the same way `ffc app build`/`ffc app dev` resolve them.
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Requires `appTestVitePlugin` (`@equinor/fusion-framework-vitest-plugin-react-app`) registered in
|
|
14
|
-
* your `vitest.config.ts` `plugins`, which serves the virtual modules backing this fixture.
|
|
15
|
-
* Running the same test file without the plugin registered fails to resolve those imports.
|
|
16
|
-
*
|
|
17
|
-
* Per-test mocking still works exactly like the base `testApp`: `.extend('configureApp', ...)` or
|
|
18
|
-
* a per-case `test.override('appEnv', ...)` layers on top of the resolved values.
|
|
19
|
-
*
|
|
20
|
-
* @remarks `.override('configureApp', ...)` replaces the app's real `configure`
|
|
21
|
-
* This fixture's default value *is* the app's real `src/config.ts` `configure` export.
|
|
22
|
-
* `.override('configureApp', ...)` replaces that default outright, so an override that doesn't
|
|
23
|
-
* itself call the real `configure(configurator, args)` skips the app's production module setup
|
|
24
|
-
* entirely, rather than composing with it. See [Advanced usage](../docs/advanced.md) for the
|
|
25
|
-
* compose-safely pattern.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* import { test } from '@equinor/fusion-framework-vitest-plugin-react-app/test';
|
|
30
|
-
* import { App } from '../App';
|
|
31
|
-
*
|
|
32
|
-
* test('renders the app', async ({ render }) => {
|
|
33
|
-
* const screen = await render(<App />);
|
|
34
|
-
* await expect.element(screen.getByRole('heading')).toBeVisible();
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export const test = baseTestApp
|
|
39
|
-
.extend('appEnv', { injected: true }, { manifest, config })
|
|
40
|
-
.extend('configureApp', { injected: true }, () => configureApp);
|
|
41
|
-
|
|
42
|
-
export default test;
|
package/src/version.ts
DELETED
package/src/virtual-modules.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare module 'virtual:fusion-app-test-env' {
|
|
2
|
-
import type { AppEnv } from '@equinor/fusion-framework-app';
|
|
3
|
-
|
|
4
|
-
export const manifest: AppEnv['manifest'];
|
|
5
|
-
export const config: AppEnv['config'];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
declare module 'virtual:fusion-app-test-configure' {
|
|
9
|
-
import type { AppMockConfigureFn } from '@equinor/fusion-framework-app/mock';
|
|
10
|
-
|
|
11
|
-
export const configure: AppMockConfigureFn | undefined;
|
|
12
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"jsx": "react-jsx",
|
|
5
|
-
"outDir": "dist/esm",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"declarationDir": "./dist/types",
|
|
8
|
-
"paths": {
|
|
9
|
-
"*": ["./*"]
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"references": [
|
|
13
|
-
{ "path": "../../cli" },
|
|
14
|
-
{ "path": "../../framework" },
|
|
15
|
-
{ "path": "../../app" },
|
|
16
|
-
{ "path": "../../modules/module" },
|
|
17
|
-
{ "path": "../../modules/app" },
|
|
18
|
-
{ "path": "../../modules/navigation" },
|
|
19
|
-
{ "path": "../../modules/feature-flag" },
|
|
20
|
-
{ "path": "../../react/framework" },
|
|
21
|
-
{ "path": "../../react/modules/module" },
|
|
22
|
-
{ "path": "../../utils/imports" }
|
|
23
|
-
],
|
|
24
|
-
"include": ["src/**/*"],
|
|
25
|
-
"exclude": ["node_modules", "dist", "src/__tests__/**/*"]
|
|
26
|
-
}
|
package/vitest.config.ts
DELETED