@equinor/fusion-framework-vitest-plugin-react-app 0.2.0-next.0
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 +104 -0
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/dist/esm/app-test.js +9 -0
- package/dist/esm/app-test.js.map +1 -0
- package/dist/esm/define-project.js +68 -0
- package/dist/esm/define-project.js.map +1 -0
- package/dist/esm/index.js +99 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/render-app-component.js +52 -0
- package/dist/esm/render-app-component.js.map +1 -0
- package/dist/esm/render-app-hook.js +63 -0
- package/dist/esm/render-app-hook.js.map +1 -0
- package/dist/esm/render.js +49 -0
- package/dist/esm/render.js.map +1 -0
- package/dist/esm/resolve-app-test-env.js +85 -0
- package/dist/esm/resolve-app-test-env.js.map +1 -0
- package/dist/esm/scope/create-app-scope-wrapper.js +15 -0
- package/dist/esm/scope/create-app-scope-wrapper.js.map +1 -0
- package/dist/esm/scope/default-app-env.js +12 -0
- package/dist/esm/scope/default-app-env.js.map +1 -0
- package/dist/esm/scope/index.js +5 -0
- package/dist/esm/scope/index.js.map +1 -0
- package/dist/esm/scope/resolve-app-scope.js +21 -0
- package/dist/esm/scope/resolve-app-scope.js.map +1 -0
- package/dist/esm/scope/resolve-fusion.js +18 -0
- package/dist/esm/scope/resolve-fusion.js.map +1 -0
- package/dist/esm/test-app.js +59 -0
- package/dist/esm/test-app.js.map +1 -0
- package/dist/esm/test.js +33 -0
- package/dist/esm/test.js.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/app-test.d.ts +6 -0
- package/dist/types/define-project.d.ts +41 -0
- package/dist/types/index.d.ts +45 -0
- package/dist/types/render-app-component.d.ts +86 -0
- package/dist/types/render-app-hook.d.ts +99 -0
- package/dist/types/render.d.ts +37 -0
- package/dist/types/resolve-app-test-env.d.ts +56 -0
- package/dist/types/scope/create-app-scope-wrapper.d.ts +14 -0
- package/dist/types/scope/default-app-env.d.ts +5 -0
- package/dist/types/scope/index.d.ts +4 -0
- package/dist/types/scope/resolve-app-scope.d.ts +31 -0
- package/dist/types/scope/resolve-fusion.d.ts +13 -0
- package/dist/types/test-app.d.ts +68 -0
- package/dist/types/test.d.ts +66 -0
- package/dist/types/version.d.ts +1 -0
- package/docs/advanced.md +140 -0
- package/docs/configuration.md +109 -0
- package/docs/getting-started.md +66 -0
- package/docs/migrating-an-existing-app.md +197 -0
- package/docs/module-mocks.md +120 -0
- package/docs/overview.md +49 -0
- package/docs/troubleshooting.md +64 -0
- package/docs/why-browser-mode.md +113 -0
- package/package.json +87 -0
- package/src/__tests__/app-test-vite-plugin.test.ts +109 -0
- package/src/__tests__/resolve-app-test-env.test.ts +83 -0
- package/src/app-test.ts +18 -0
- package/src/define-project.ts +84 -0
- package/src/index.ts +124 -0
- package/src/render-app-component.tsx +116 -0
- package/src/render-app-hook.tsx +135 -0
- package/src/render.tsx +64 -0
- package/src/resolve-app-test-env.ts +132 -0
- package/src/scope/create-app-scope-wrapper.tsx +26 -0
- package/src/scope/default-app-env.ts +13 -0
- package/src/scope/index.ts +4 -0
- package/src/scope/resolve-app-scope.ts +46 -0
- package/src/scope/resolve-fusion.ts +29 -0
- package/src/test-app.tsx +72 -0
- package/src/test.tsx +35 -0
- package/src/version.ts +2 -0
- package/src/virtual-modules.d.ts +12 -0
- package/tsconfig.json +24 -0
- package/vitest.config.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,iBAAiB,EAAiC,MAAM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per } from './scope';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a component inside a real, mock-backed application module scope.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Wraps `vitest-browser-react`'s `render` with the same provider nesting
|
|
8
|
+
* `createComponent` uses in production — a `FrameworkProvider` (the parent Fusion
|
|
9
|
+
* instance, from `mockFramework`) around a `ModuleProvider` (this app's own modules,
|
|
10
|
+
* from `mockAppModules`, `@equinor/fusion-framework-app/mock`). See {@link renderAppHook}
|
|
11
|
+
* for the equivalent helper when testing a hook in isolation, rather than a component.
|
|
12
|
+
*
|
|
13
|
+
* @template TModules - Module descriptors beyond the default set.
|
|
14
|
+
* @template TEnv - The application environment descriptor.
|
|
15
|
+
* @param ui - The component to render.
|
|
16
|
+
* @param options - A `configure` callback and `env` for `mockAppModules`, plus any other `render` option.
|
|
17
|
+
* @returns The `render` result plus `fusion.framework` and `fusion.app`, once the mocked application module scope resolves.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { getByText } = await renderAppComponent(<Apploader appKey="child-app" />, {
|
|
22
|
+
* fusion: await mockFramework<[AppModule]>((configurator) => {
|
|
23
|
+
* // register the child app's own manifest against the `app` module
|
|
24
|
+
* }),
|
|
25
|
+
* });
|
|
26
|
+
* await expect.element(getByText(/mounted/)).toBeInTheDocument();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Drive a module directly and assert the re-render
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const { getByText, fusion } = await renderAppComponent<[ContextModule]>(<App />, {
|
|
32
|
+
* configure: (configurator) => enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
33
|
+
* });
|
|
34
|
+
* await fusion.app.context.setCurrentContextByIdAsync(projectB.id);
|
|
35
|
+
* await expect.element(getByText(/project-b/)).toBeInTheDocument();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function renderAppComponent(ui, options) {
|
|
39
|
+
const { configure, env, fusion: providedFusion, ...renderOptions } = options ?? {};
|
|
40
|
+
const { framework, app } = await resolveAppScope({
|
|
41
|
+
configure,
|
|
42
|
+
env,
|
|
43
|
+
fusion: providedFusion,
|
|
44
|
+
});
|
|
45
|
+
const result = await render(ui, {
|
|
46
|
+
...renderOptions,
|
|
47
|
+
wrapper: createAppScopeWrapper({ framework, app }),
|
|
48
|
+
});
|
|
49
|
+
return { ...result, fusion: { framework, app } };
|
|
50
|
+
}
|
|
51
|
+
export default renderAppComponent;
|
|
52
|
+
//# sourceMappingURL=render-app-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-app-component.js","sourceRoot":"","sources":["../../src/render-app-component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAQ9C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAmDjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAItC,EAAgB,EAChB,OAAmD;IAEnD,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACnF,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,eAAe,CAAiB;QAC/D,SAAS;QACT,GAAG;QACH,MAAM,EAAE,cAAc;KACvB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,EAAE,EAAE;QAC9B,GAAG,aAAa;QAChB,OAAO,EAAE,qBAAqB,CAAW,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;KAC7D,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { renderHook } from 'vitest-browser-react';
|
|
2
|
+
import { resolveAppScope, createAppScopeWrapper } from './scope';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a hook inside a real, mock-backed application module scope.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Wraps `vitest-browser-react`'s `renderHook` with the same provider nesting
|
|
8
|
+
* `createComponent` uses in production — a `FrameworkProvider` (the parent Fusion
|
|
9
|
+
* instance, from `mockFramework`) around a `ModuleProvider` (this app's own modules,
|
|
10
|
+
* from `mockAppModules`, `@equinor/fusion-framework-app/mock`) — the real
|
|
11
|
+
* `event`/`http`/`msal` module pipeline. Only requests a seeded middleware answers are
|
|
12
|
+
* faked; a request with no matching middleware still reaches the real network. Use this
|
|
13
|
+
* for any hook that reads from the application module scope or the parent framework
|
|
14
|
+
* (e.g. `useAppModule`, `useAccessToken`, `useFramework`), instead of hand-wiring
|
|
15
|
+
* `mockFramework`, `mockAppModules`, `FrameworkProvider` and `ModuleProvider` in every test.
|
|
16
|
+
*
|
|
17
|
+
* @template Result - The value returned by the rendered hook.
|
|
18
|
+
* @template Props - The props accepted by the rendered hook.
|
|
19
|
+
* @template TModules - Module descriptors beyond the default set.
|
|
20
|
+
* @template TEnv - The application environment descriptor.
|
|
21
|
+
* @param render - The hook to render, receiving `initialProps`.
|
|
22
|
+
* @param options - A `configure` callback and `env` for `mockAppModules`, plus any other
|
|
23
|
+
* `renderHook` option.
|
|
24
|
+
* @returns The `renderHook` result plus `fusion.framework` and `fusion.app`, once the mocked application module scope resolves.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const { result } = await renderAppHook(() => useAccessToken({ scopes: ['User.Read'] }));
|
|
29
|
+
* await vi.waitFor(() => expect(result.current.pending).toBe(false));
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Sign in a named user
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const { result } = await renderAppHook(() => useCurrentAccount(), {
|
|
35
|
+
* configure: (configurator) => configurator.msal.setAccount({ name: 'Ada Lovelace' }),
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Reuse a pre-built parent Fusion instance
|
|
40
|
+
* ```tsx
|
|
41
|
+
* const fusion = await mockFramework<[AppModule]>((configurator) =>
|
|
42
|
+
* enableAppManifestMock(configurator, env),
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* const { result: a } = await renderAppHook(() => useAccessToken({ scopes: ['User.Read'] }), { fusion });
|
|
46
|
+
* const { result: b } = await renderAppHook(() => useCurrentAccount(), { fusion });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function renderAppHook(render, options) {
|
|
50
|
+
const { configure, env, fusion: providedFusion, ...renderHookOptions } = options ?? {};
|
|
51
|
+
const { framework, app } = await resolveAppScope({
|
|
52
|
+
configure,
|
|
53
|
+
env,
|
|
54
|
+
fusion: providedFusion,
|
|
55
|
+
});
|
|
56
|
+
const result = await renderHook(render, {
|
|
57
|
+
...renderHookOptions,
|
|
58
|
+
wrapper: createAppScopeWrapper({ framework, app }),
|
|
59
|
+
});
|
|
60
|
+
return { ...result, fusion: { framework, app } };
|
|
61
|
+
}
|
|
62
|
+
export default renderAppHook;
|
|
63
|
+
//# sourceMappingURL=render-app-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-app-hook.js","sourceRoot":"","sources":["../../src/render-app-hook.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAQlD,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AA0DjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAMjC,MAAwC,EACxC,OAAqD;IAErD,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,iBAAiB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACvF,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,MAAM,eAAe,CAAiB;QAC/D,SAAS;QACT,GAAG;QACH,MAAM,EAAE,cAAc;KACvB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE;QACtC,GAAG,iBAAiB;QACpB,OAAO,EAAE,qBAAqB,CAAW,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;KAC7D,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { renderAppComponent, } from './render-app-component';
|
|
2
|
+
// resolved at test-time by `appTestVitePlugin` (@equinor/fusion-framework-vitest-plugin-react-app);
|
|
3
|
+
// see virtual-modules.d.ts for the ambient module declarations
|
|
4
|
+
import { manifest, config } from 'virtual:fusion-app-test-env';
|
|
5
|
+
import { configure } from 'virtual:fusion-app-test-configure';
|
|
6
|
+
/**
|
|
7
|
+
* Renders a component inside the application's own module scope for use in plain `describe`/`it`
|
|
8
|
+
* tests, using the manifest, config, and module-configurator resolved for this application — no
|
|
9
|
+
* per-test wiring, and no custom `test` fixture required.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Requires `appTestVitePlugin` (`@equinor/fusion-framework-vitest-plugin-react-app`) registered in
|
|
13
|
+
* your `vitest.config.ts` `plugins`, which serves the virtual modules backing the resolved
|
|
14
|
+
* `env`/`configure`. Running the same test file without the plugin registered fails to resolve
|
|
15
|
+
* those imports.
|
|
16
|
+
*
|
|
17
|
+
* Pass `env` or `configure` in `options` to override the resolved values for a single render.
|
|
18
|
+
*
|
|
19
|
+
* @template TModules - Module descriptors beyond the default set.
|
|
20
|
+
* @param ui - The component to render.
|
|
21
|
+
* @param options - Overrides for `env`/`configure`, plus any other `renderAppComponent` option.
|
|
22
|
+
* @returns The `render` result plus `fusion.framework` and `fusion.app`, once the mocked application module scope resolves.
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import { describe, expect, it } from 'vitest';
|
|
26
|
+
* import { render } from '@equinor/fusion-framework-vitest-plugin-react-app/test';
|
|
27
|
+
* import { App } from '../App';
|
|
28
|
+
*
|
|
29
|
+
* describe('App', () => {
|
|
30
|
+
* it('renders the app', async () => {
|
|
31
|
+
* const { getByRole } = await render(<App />);
|
|
32
|
+
* await expect.element(getByRole('heading')).toBeVisible();
|
|
33
|
+
* });
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export async function render(ui, options) {
|
|
38
|
+
const { configure: configureOverride, env: envOverride, ...renderOptions } = options ?? {};
|
|
39
|
+
return renderAppComponent(ui, {
|
|
40
|
+
...renderOptions,
|
|
41
|
+
env: envOverride ?? { manifest, config },
|
|
42
|
+
// the resolved `configure` is generic over the app's own module set (`unknown`), while
|
|
43
|
+
// `TModules` here is caller-supplied *extra* modules — safe to widen for the common case
|
|
44
|
+
// where callers don't override it with a `TModules`-specific configurator
|
|
45
|
+
configure: (configureOverride ?? configure),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export default render;
|
|
49
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/render.tsx"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAEhC,oGAAoG;AACpG,+DAA+D;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,EAAgB,EAChB,OAAqD;IAErD,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC3F,OAAO,kBAAkB,CAAmB,EAAE,EAAE;QAC9C,GAAG,aAAa;QAChB,GAAG,EAAE,WAAW,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE;QACxC,uFAAuF;QACvF,yFAAyF;QACzF,0EAA0E;QAC1E,SAAS,EAAE,CAAC,iBAAiB,IAAI,SAAS,CAAqD;KAChG,CAAC,CAAC;AACL,CAAC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { FileNotFoundError } from '@equinor/fusion-imports';
|
|
2
|
+
import { createAppManifestFromPackage, loadAppManifest, loadAppConfig, mergeAppManifests, ApiAppConfigSchema, } from '@equinor/fusion-framework-cli/app';
|
|
3
|
+
import { resolvePackage } from '@equinor/fusion-framework-cli/utils';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves an application's manifest and config using the same pipeline `ffc app build`/
|
|
6
|
+
* `ffc app dev` use: a base manifest generated from `package.json`, merged with a local
|
|
7
|
+
* `app.manifest.ts` if one exists; and `app.config.ts` for endpoints/environment, falling
|
|
8
|
+
* back to an empty config if none exists.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Intended to seed `@equinor/fusion-framework-vitest-plugin-react-app/test`'s `testApp` `env` fixture, so
|
|
12
|
+
* a test suite exercises the application's real manifest/config instead of a hand-maintained
|
|
13
|
+
* duplicate. Anything a specific test still needs faked (a missing endpoint, a different
|
|
14
|
+
* `appKey`) can be layered on top with `testApp.extend('env', ...)` or a per-test
|
|
15
|
+
* `test.override('env', ...)`.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Resolution options; `entrypoint` defaults to the current working directory.
|
|
18
|
+
* @returns The resolved application manifest and config.
|
|
19
|
+
* @throws If no `package.json` can be found from `entrypoint` upward, or an explicitly requested
|
|
20
|
+
* `manifest`/`config` file does not exist.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { resolveAppTestEnv } from '@equinor/fusion-framework-vitest-plugin-react-app';
|
|
24
|
+
* import { testApp } from '@equinor/fusion-framework-vitest-plugin-react-app/test';
|
|
25
|
+
* import { configure } from '../config';
|
|
26
|
+
*
|
|
27
|
+
* const test = testApp
|
|
28
|
+
* .extend('env', { injected: true }, () => resolveAppTestEnv())
|
|
29
|
+
* .extend('configure', { injected: true }, () => configure);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const resolveAppTestEnv = async (options) => {
|
|
33
|
+
const pkg = await resolvePackage({ cwd: options?.entrypoint });
|
|
34
|
+
const env = { command: 'build', mode: 'test', root: pkg.root, environment: 'test' };
|
|
35
|
+
const baseManifest = createAppManifestFromPackage(env, pkg.packageJson);
|
|
36
|
+
const [manifest, config] = await Promise.all([
|
|
37
|
+
resolveManifest(env, baseManifest, options?.manifest),
|
|
38
|
+
resolveConfig(env, options?.config),
|
|
39
|
+
]);
|
|
40
|
+
return { manifest, config };
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Loads `app.manifest(.*)?` (or applies an inline {@link AppManifestFn}), falling back to the
|
|
44
|
+
* package-derived manifest when none exists — mirrors `ffc app build`'s own fallback so a test
|
|
45
|
+
* env matches a real build with zero manifest file.
|
|
46
|
+
*/
|
|
47
|
+
const resolveManifest = async (env, base, manifest) => {
|
|
48
|
+
// an inline function is applied directly, the same way a loaded `app.manifest.ts`'s default export would be
|
|
49
|
+
if (typeof manifest === 'function') {
|
|
50
|
+
const result = await manifest(env, { base });
|
|
51
|
+
return mergeAppManifests(base, result ?? {});
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return (await loadAppManifest(env, { base, file: manifest })).manifest;
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
// an explicitly requested manifest that's missing is a real error; only the default lookup falls back
|
|
58
|
+
if (err instanceof FileNotFoundError && !manifest)
|
|
59
|
+
return base;
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Loads `app.config(.*)?` (or applies an inline {@link AppConfigFn}), falling back to an empty
|
|
65
|
+
* config when none exists — mirrors `ffc app build`'s own fallback so a test env matches a real
|
|
66
|
+
* build with zero config file.
|
|
67
|
+
*/
|
|
68
|
+
const resolveConfig = async (env, config) => {
|
|
69
|
+
// an inline function is applied directly, the same way a loaded `app.config.ts`'s default export would be
|
|
70
|
+
if (typeof config === 'function') {
|
|
71
|
+
const result = await config(env, { base: { environment: {} } });
|
|
72
|
+
return ApiAppConfigSchema.parse(result ?? { environment: {} });
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return (await loadAppConfig(env, { file: config })).config;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
// an explicitly requested config that's missing is a real error; only the default lookup falls back
|
|
79
|
+
if (err instanceof FileNotFoundError && !config)
|
|
80
|
+
return { environment: {} };
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export default resolveAppTestEnv;
|
|
85
|
+
//# sourceMappingURL=resolve-app-test-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-app-test-env.js","sourceRoot":"","sources":["../../src/resolve-app-test-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EACL,4BAA4B,EAC5B,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GAInB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AA4BrE;;;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AsG;QACtG,IAAI,GAAG,YAAY,iBAAiB,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC/D,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG,KAAK,EACzB,GAAe,EACf,MAA6B,EACN,EAAE;IACzB,0GAA0G;IAC1G,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAChE,OAAO,kBAAkB,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,aAAa,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAC7D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,oGAAoG;QACpG,IAAI,GAAG,YAAY,iBAAiB,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;QAC5E,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FrameworkProvider } from '@equinor/fusion-framework-react';
|
|
3
|
+
import { ModuleProvider } from '@equinor/fusion-framework-react-module';
|
|
4
|
+
/**
|
|
5
|
+
* The provider nesting `createComponent` uses in production, for wrapping a component or
|
|
6
|
+
* hook under test in its resolved {@link AppScope}.
|
|
7
|
+
*
|
|
8
|
+
* @template TModules - Module descriptors beyond the default set.
|
|
9
|
+
* @param scope - The resolved parent Fusion instance and application module scope.
|
|
10
|
+
* @returns A wrapper component nesting a `FrameworkProvider` around a `ModuleProvider`.
|
|
11
|
+
*/
|
|
12
|
+
export function createAppScopeWrapper({ framework, app, }) {
|
|
13
|
+
return ({ children }) => (_jsx(FrameworkProvider, { value: framework, children: _jsx(ModuleProvider, { value: app, children: children }) }));
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=create-app-scope-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-app-scope-wrapper.js","sourceRoot":"","sources":["../../../src/scope/create-app-scope-wrapper.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAKxE;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAwD,EAC3F,SAAS,EACT,GAAG,GACgB;IACnB,OAAO,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC,CAChD,KAAC,iBAAiB,IAAC,KAAK,EAAE,SAAS,YACjC,KAAC,cAAc,IAAC,KAAK,EAAE,GAAG,YAAG,QAAQ,GAAkB,GACrC,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application environment used when a test does not care about its own app identity.
|
|
3
|
+
*/
|
|
4
|
+
export const defaultAppEnv = {
|
|
5
|
+
manifest: {
|
|
6
|
+
appKey: 'test-app',
|
|
7
|
+
displayName: 'Test App',
|
|
8
|
+
description: 'A test application',
|
|
9
|
+
type: 'standalone',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=default-app-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-app-env.js","sourceRoot":"","sources":["../../../src/scope/default-app-env.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,QAAQ,EAAE;QACR,MAAM,EAAE,UAAU;QAClB,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,oBAAoB;QACjC,IAAI,EAAE,YAAY;KACnB;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAiB,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { mockAppModules } from '@equinor/fusion-framework-app/mock';
|
|
2
|
+
import { resolveFusion } from './resolve-fusion';
|
|
3
|
+
import { defaultAppEnv } from './default-app-env';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the parent Fusion instance and application module scope shared by every
|
|
6
|
+
* `packages/react/app` testing helper.
|
|
7
|
+
*
|
|
8
|
+
* @template TModules - Module descriptors beyond the default set.
|
|
9
|
+
* @template TEnv - The application environment descriptor.
|
|
10
|
+
* @param options - A `configure` callback and `env` for {@link mockAppModules}, plus an
|
|
11
|
+
* already-built `fusion` instance to reuse instead of a fresh one.
|
|
12
|
+
* @returns The resolved {@link AppScope}.
|
|
13
|
+
*/
|
|
14
|
+
export async function resolveAppScope(options) {
|
|
15
|
+
const { configure, env, fusion: providedFusion } = options ?? {};
|
|
16
|
+
const resolvedEnv = env ?? defaultAppEnv;
|
|
17
|
+
const framework = await resolveFusion(resolvedEnv, providedFusion);
|
|
18
|
+
const app = await mockAppModules(configure, resolvedEnv, framework);
|
|
19
|
+
return { framework, app };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=resolve-app-scope.js.map
|
|
@@ -0,0 +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;IACnE,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mockFramework } from '@equinor/fusion-framework/mock';
|
|
2
|
+
import { enableAppManifestMock } from '@equinor/fusion-framework-app/mock';
|
|
3
|
+
import { defaultAppEnv } from './default-app-env';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the parent Fusion instance backing an application module scope, building a
|
|
6
|
+
* fresh {@link mockFramework} instance with this app's own manifest served when none is
|
|
7
|
+
* given.
|
|
8
|
+
*
|
|
9
|
+
* @template TEnv - The application environment descriptor.
|
|
10
|
+
* @param env - The application environment; defaults to {@link defaultAppEnv}.
|
|
11
|
+
* @param fusion - An already-built parent Fusion instance to reuse instead.
|
|
12
|
+
* @returns The given `fusion`, or a fresh mocked parent Fusion instance.
|
|
13
|
+
*/
|
|
14
|
+
export async function resolveFusion(env, fusion) {
|
|
15
|
+
return (fusion ??
|
|
16
|
+
mockFramework((configurator) => enableAppManifestMock(configurator, env ?? defaultAppEnv)));
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=resolve-fusion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-fusion.js","sourceRoot":"","sources":["../../../src/scope/resolve-fusion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAU,EACV,MAAe;IAEf,OAAO,CACL,MAAM;QACN,aAAa,CAAc,CAAC,YAAY,EAAE,EAAE,CAC1C,qBAAqB,CAAC,YAAY,EAAE,GAAG,IAAK,aAAsB,CAAC,CACpE,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { test as baseTest } from 'vitest';
|
|
2
|
+
import { render, renderHook } from 'vitest-browser-react';
|
|
3
|
+
import { mockAppModules } from '@equinor/fusion-framework-app/mock';
|
|
4
|
+
import { defaultAppEnv, resolveFusion, createAppScopeWrapper } from './scope';
|
|
5
|
+
/**
|
|
6
|
+
* `vitest`'s `test`, extended with an application module scope fixture.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* An alternative to {@link renderAppComponent}/{@link renderAppHook} for a test file whose
|
|
10
|
+
* cases share seeded fixture defaults: `env`/`configure` become suite-level concerns,
|
|
11
|
+
* overridden once per file (or per `describe` block) with `testApp.extend(...)`, rather than
|
|
12
|
+
* an options object repeated on every call. `fusion`/`app` are still instantiated fresh per
|
|
13
|
+
* test — only the seeded defaults are shared, not state between tests. They also resolve
|
|
14
|
+
* lazily: a test that only destructures `app` never pays for rendering anything, and one
|
|
15
|
+
* that only destructures `render`/`renderHook` gets the same fixture wiring automatically.
|
|
16
|
+
*
|
|
17
|
+
* Both entry points stay supported: reach for `renderAppComponent`/`renderAppHook` for a
|
|
18
|
+
* one-off test whose configuration is not shared by the rest of the file; reach for
|
|
19
|
+
* `testApp` when several cases in a file share one set of seeded fixture defaults.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* testApp('resolves current context', async ({ app, render }) => {
|
|
24
|
+
* const screen = await render(<App />);
|
|
25
|
+
* expect(app.context).toBeDefined();
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Seed a module for every test in a suite
|
|
30
|
+
* ```tsx
|
|
31
|
+
* describe('with a seeded context module', () => {
|
|
32
|
+
* const test = testApp.extend('configure', { injected: true }, () =>
|
|
33
|
+
* (configurator) => enableContextMock(configurator, (mock) => mock.setCurrentContext(projectA)),
|
|
34
|
+
* );
|
|
35
|
+
*
|
|
36
|
+
* test('starts on the seeded context', async ({ render }) => {
|
|
37
|
+
* const screen = await render(<App />);
|
|
38
|
+
* await expect.element(screen.getByText(projectA.title)).toBeVisible();
|
|
39
|
+
* });
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const testApp = baseTest
|
|
44
|
+
.extend('env', { injected: true }, defaultAppEnv)
|
|
45
|
+
// `test.extend`'s plain-`value` overload rejects function types (ambiguous with the
|
|
46
|
+
// resolver-`fn` overload), so a function-typed fixture default must go through `fn` instead.
|
|
47
|
+
.extend('configure', { injected: true }, () => undefined)
|
|
48
|
+
.extend('fusion', async ({ env }) => resolveFusion(env))
|
|
49
|
+
.extend('app', async ({ configure, env, fusion }) => mockAppModules(configure, env, fusion))
|
|
50
|
+
.extend('render', ({ fusion, app }) => {
|
|
51
|
+
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
52
|
+
return (ui, options) => render(ui, { ...options, wrapper });
|
|
53
|
+
})
|
|
54
|
+
.extend('renderHook', ({ fusion, app }) => {
|
|
55
|
+
const wrapper = createAppScopeWrapper({ framework: fusion, app });
|
|
56
|
+
return (cb, options) => renderHook(cb, { ...options, wrapper });
|
|
57
|
+
});
|
|
58
|
+
export default testApp;
|
|
59
|
+
//# sourceMappingURL=test-app.js.map
|
|
@@ -0,0 +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;AAIpE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ;KAC5B,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,aAAa,CAAC;IACjD,oFAAoF;IACpF,6FAA6F;KAC5F,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,SAA2C,CAAC;KAC1F,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;KACvD,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAClD,cAAc,CAAkB,SAAS,EAAE,GAAa,EAAE,MAAM,CAAC,CAClE;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
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { testApp as baseTestApp } from './test-app';
|
|
2
|
+
// resolved at test-time by `appTestVitePlugin` (@equinor/fusion-framework-vitest-plugin-react-app);
|
|
3
|
+
// see virtual-modules.d.ts for the ambient module declarations
|
|
4
|
+
import { manifest, config } from 'virtual:fusion-app-test-env';
|
|
5
|
+
import { configure } from 'virtual:fusion-app-test-configure';
|
|
6
|
+
/**
|
|
7
|
+
* `vitest`'s `test`, pre-seeded with the application's own manifest, config, and
|
|
8
|
+
* module-configurator, resolved the same way `ffc app build`/`ffc app dev` resolve them.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Requires `appTestVitePlugin` (`@equinor/fusion-framework-vitest-plugin-react-app`) registered in
|
|
12
|
+
* your `vitest.config.ts` `plugins`, which serves the virtual modules backing this fixture.
|
|
13
|
+
* Running the same test file without the plugin registered fails to resolve those imports.
|
|
14
|
+
*
|
|
15
|
+
* Per-test mocking still works exactly like the base `testApp`: `.extend('configure', ...)` or
|
|
16
|
+
* a per-case `test.override('env', ...)` layers on top of the resolved values.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { test } from '@equinor/fusion-framework-vitest-plugin-react-app/test';
|
|
21
|
+
* import { App } from '../App';
|
|
22
|
+
*
|
|
23
|
+
* test('renders the app', async ({ render }) => {
|
|
24
|
+
* const screen = await render(<App />);
|
|
25
|
+
* await expect.element(screen.getByRole('heading')).toBeVisible();
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const test = baseTestApp
|
|
30
|
+
.extend('env', { injected: true }, { manifest, config })
|
|
31
|
+
.extend('configure', { injected: true }, () => configure);
|
|
32
|
+
export default test;
|
|
33
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +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;AAE9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW;KAC5B,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;KACvD,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AAE5D,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC"}
|