tungsten 0.7.0 → 0.7.1
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/.build-complete +1 -1
- package/dist/FrameworkConfig.d.ts +2 -0
- package/dist/FrameworkConfig.d.ts.map +1 -1
- package/dist/FrameworkConfig.types.test.d.ts +2 -0
- package/dist/FrameworkConfig.types.test.d.ts.map +1 -0
- package/dist/FrameworkConfig.types.test.js +6 -0
- package/dist/Instance/Instance.d.ts.map +1 -1
- package/dist/Instance/Instance.js +6 -33
- package/dist/Instance/InstanceConfig.d.ts +1 -0
- package/dist/Instance/InstanceConfig.d.ts.map +1 -1
- package/dist/Servers/DevServer.d.ts.map +1 -1
- package/dist/Servers/DevServer.js +10 -1
- package/dist/Servers/ProdServer.d.ts +1 -0
- package/dist/Servers/ProdServer.d.ts.map +1 -1
- package/dist/Servers/ProdServer.js +18 -1
- package/dist/Servers/routing.d.ts.map +1 -1
- package/dist/Servers/routing.js +9 -5
- package/dist/Servers/stubInstance.d.ts +8 -0
- package/dist/Servers/stubInstance.d.ts.map +1 -0
- package/dist/Servers/stubInstance.js +40 -0
- package/dist/build/createInstanceConfigFile.d.ts.map +1 -1
- package/dist/build/createInstanceConfigFile.js +1 -1
- package/dist/build/rollupProdConstants.d.ts.map +1 -1
- package/dist/componentHelpers.d.ts +2 -1
- package/dist/componentHelpers.d.ts.map +1 -1
- package/dist/componentHelpers.js +3 -0
- package/dist/frameworkConfigSchema.d.ts +2 -0
- package/dist/frameworkConfigSchema.d.ts.map +1 -1
- package/dist/frameworkConfigSchema.js +4 -1
- package/dist/getUserConfig.d.ts.map +1 -1
- package/dist/hydrate/hydrate.d.ts.map +1 -1
- package/dist/hydrate/hydrate.js +31 -10
- package/dist/hydrate/stubRouting.d.ts +8 -0
- package/dist/hydrate/stubRouting.d.ts.map +1 -0
- package/dist/hydrate/stubRouting.js +25 -0
- package/dist/makeFinalConfig.d.ts.map +1 -1
- package/dist/makeFinalConfig.js +2 -0
- package/dist/makeInstanceConfigFromFrameworkConfig.d.ts.map +1 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.js +1 -0
- package/dist/pipeline/PipelineRequestHandler.d.ts.map +1 -1
- package/dist/pipeline/PipelineRequestHandler.js +9 -1
- package/dist/pipeline/hydratePipeline.d.ts.map +1 -1
- package/dist/pipeline/hydratePipeline.js +28 -9
- package/dist/pipeline/pipeline.d.ts +35 -33
- package/dist/pipeline/pipeline.d.ts.map +1 -1
- package/dist/pipeline/pipeline.js +10 -5
- package/dist/pipeline/pipeline.types.test.d.ts +186 -76
- package/dist/pipeline/pipeline.types.test.d.ts.map +1 -1
- package/dist/pipeline/pipeline.types.test.js +2 -0
- package/dist/pipeline/pipelineDefinition.d.ts +20 -9
- package/dist/pipeline/pipelineDefinition.d.ts.map +1 -1
- package/dist/pipeline/pipelineSplit.types.test.d.ts +598 -124
- package/dist/pipeline/pipelineSplit.types.test.d.ts.map +1 -1
- package/dist/pipeline/runPipeline.d.ts +6 -8
- package/dist/pipeline/runPipeline.d.ts.map +1 -1
- package/dist/pipeline/runPipeline.js +8 -8
- package/dist/pipeline/runSplitPipeline.d.ts +3 -3
- package/dist/pipeline/runSplitPipeline.d.ts.map +1 -1
- package/dist/pipeline/runSplitPipeline.js +12 -8
- package/dist/pipeline/splitPipeline.d.ts +8 -8
- package/dist/pipeline/splitPipeline.d.ts.map +1 -1
- package/dist/render/contentTreeToRenderingTree.d.ts.map +1 -1
- package/dist/render/contentTreeToRenderingTree.js +4 -1
- package/dist/routing/MatchedRouteInfo.d.ts +2 -0
- package/dist/routing/MatchedRouteInfo.d.ts.map +1 -1
- package/dist/routing/MatchedRouteInfo.js +1 -1
- package/dist/routing/RouteContentFunction.d.ts +1 -1
- package/dist/routing/RouteContentFunction.d.ts.map +1 -1
- package/dist/routing/RouteTypes.d.ts +1 -1
- package/dist/routing/RouteTypes.d.ts.map +1 -1
- package/dist/routing/Routes.d.ts +6 -3
- package/dist/routing/Routes.d.ts.map +1 -1
- package/dist/routing/builder.d.ts +2 -1
- package/dist/routing/builder.d.ts.map +1 -1
- package/dist/routing/builder.js +6 -0
- package/dist/routing/redirectOf.d.ts +11 -0
- package/dist/routing/redirectOf.d.ts.map +1 -0
- package/dist/routing/redirectOf.js +32 -0
- package/dist/routing/routesArray.d.ts +2 -2
- package/dist/routing/routesArray.d.ts.map +1 -1
- package/dist/routing/routingBuilder.js +0 -1
- package/dist/testing/contentToString.d.ts +13 -0
- package/dist/testing/contentToString.d.ts.map +1 -0
- package/dist/testing/contentToString.js +105 -0
- package/dist/testing/display.d.ts +2 -0
- package/dist/testing/display.d.ts.map +1 -0
- package/dist/testing/display.js +37 -0
- package/dist/testing/ensure.d.ts +52 -41
- package/dist/testing/ensure.d.ts.map +1 -1
- package/dist/testing/ensure.js +204 -62
- package/dist/testing/ensure.types.test.d.ts +2 -0
- package/dist/testing/ensure.types.test.d.ts.map +1 -0
- package/dist/testing/ensure.types.test.js +34 -0
- package/dist/testing/host.d.ts +25 -25
- package/dist/testing/host.d.ts.map +1 -1
- package/dist/testing/host.js +1 -3
- package/dist/testing/host.types.test.d.ts +2 -0
- package/dist/testing/host.types.test.d.ts.map +1 -0
- package/dist/testing/host.types.test.js +81 -0
- package/dist/testing/hydrateTestApp.js +4 -3
- package/dist/testing/index.d.ts +2 -3
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -2
- package/dist/testing/pipeline/createTestPacketApp.d.ts +30 -0
- package/dist/testing/pipeline/createTestPacketApp.d.ts.map +1 -0
- package/dist/testing/pipeline/createTestPacketApp.js +45 -0
- package/dist/testing/pipeline/createTestPacketApp.types.test.d.ts +3 -0
- package/dist/testing/pipeline/createTestPacketApp.types.test.d.ts.map +1 -0
- package/dist/testing/pipeline/createTestPacketApp.types.test.js +101 -0
- package/dist/testing/pipeline/createTestPipelineApp.d.ts +70 -0
- package/dist/testing/pipeline/createTestPipelineApp.d.ts.map +1 -0
- package/dist/testing/pipeline/createTestPipelineApp.js +90 -0
- package/dist/testing/pipeline/createTestPipelineApp.types.test.d.ts +6 -0
- package/dist/testing/pipeline/createTestPipelineApp.types.test.d.ts.map +1 -0
- package/dist/testing/pipeline/createTestPipelineApp.types.test.js +146 -0
- package/dist/testing/pipeline/hostPipeline.d.ts +25 -0
- package/dist/testing/pipeline/hostPipeline.d.ts.map +1 -0
- package/dist/testing/pipeline/hostPipeline.js +18 -0
- package/dist/testing/{hydrateTestPipelineApp.d.ts → pipeline/hydrateTestPipelineApp.d.ts} +6 -6
- package/dist/testing/pipeline/hydrateTestPipelineApp.d.ts.map +1 -0
- package/dist/testing/{hydrateTestPipelineApp.js → pipeline/hydrateTestPipelineApp.js} +22 -19
- package/dist/testing/pipeline/hydrateTestPipelineApp.types.test.d.ts +2 -0
- package/dist/testing/pipeline/hydrateTestPipelineApp.types.test.d.ts.map +1 -0
- package/dist/testing/pipeline/hydrateTestPipelineApp.types.test.js +27 -0
- package/dist/testing/pipeline/index.d.ts +5 -0
- package/dist/testing/pipeline/index.d.ts.map +1 -0
- package/dist/testing/pipeline/index.js +4 -0
- package/dist/testing/pipeline/pipelineTestApp.d.ts +34 -0
- package/dist/testing/pipeline/pipelineTestApp.d.ts.map +1 -0
- package/dist/testing/pipeline/pipelineTestApp.js +100 -0
- package/dist/testing/pipeline/testPipelineRoute.d.ts +2 -0
- package/dist/testing/pipeline/testPipelineRoute.d.ts.map +1 -0
- package/dist/testing/pipeline/testPipelineRoute.js +1 -0
- package/dist/testing/resolveContent.d.ts +2 -0
- package/dist/testing/resolveContent.d.ts.map +1 -1
- package/dist/testing/resolveContent.js +9 -1
- package/package.json +5 -3
- package/vendor/css-select.js +3383 -0
- package/vendor/manifest.json +4 -3
- package/dist/testing/createTestPipelineApp.d.ts +0 -25
- package/dist/testing/createTestPipelineApp.d.ts.map +0 -1
- package/dist/testing/createTestPipelineApp.js +0 -153
- package/dist/testing/hostPipeline.d.ts +0 -157
- package/dist/testing/hostPipeline.d.ts.map +0 -1
- package/dist/testing/hostPipeline.js +0 -341
- package/dist/testing/hydrateTestPipelineApp.d.ts.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
|
+
import { TungstenStatefulComponent } from "../Components.js";
|
|
5
|
+
// Type tests: tsc is the assertion - nothing here runs. What each wrapper's content and updates
|
|
6
|
+
// hand back: the component's own content type, or resolved content
|
|
7
|
+
class Counter extends TungstenStatefulComponent {
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
super(...args);
|
|
10
|
+
_defineProperty(this, "state", {
|
|
11
|
+
n: 0
|
|
12
|
+
});
|
|
13
|
+
_defineProperty(this, "content", () => `${this.state.n}`);
|
|
14
|
+
_defineProperty(this, "bump", () => {
|
|
15
|
+
this.setState({
|
|
16
|
+
n: this.state.n + 1
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const _ownContent = true;
|
|
22
|
+
const _ownUpdate = true;
|
|
23
|
+
const _ownState = true;
|
|
24
|
+
const _resolvedContent = true;
|
|
25
|
+
const _resolvedUpdate = true;
|
|
26
|
+
const _resolvedState = true;
|
|
27
|
+
// the rest is shared, and the component's own methods come out on both
|
|
28
|
+
const _props = true;
|
|
29
|
+
const _api = true;
|
|
30
|
+
const _storeResolve = {
|
|
31
|
+
storeData: {
|
|
32
|
+
n: 1
|
|
33
|
+
},
|
|
34
|
+
resolve: true
|
|
35
|
+
};
|
|
36
|
+
const _storeResolveAbsent = {
|
|
37
|
+
storeData: {
|
|
38
|
+
n: 1
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
// @ts-expect-error -- resolve is true or absent
|
|
42
|
+
const _storeResolveFalse = {
|
|
43
|
+
storeData: {
|
|
44
|
+
n: 1
|
|
45
|
+
},
|
|
46
|
+
resolve: false
|
|
47
|
+
};
|
|
48
|
+
const _storeDont = {
|
|
49
|
+
storeData: {
|
|
50
|
+
n: 1
|
|
51
|
+
},
|
|
52
|
+
resolve: false
|
|
53
|
+
};
|
|
54
|
+
// @ts-expect-error -- resolve: false is required
|
|
55
|
+
const _storeDontAbsent = {
|
|
56
|
+
storeData: {
|
|
57
|
+
n: 1
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// @ts-expect-error -- one store form, as host()'s own options
|
|
61
|
+
const _storeTwoForms = {
|
|
62
|
+
storeData: {
|
|
63
|
+
n: 1
|
|
64
|
+
},
|
|
65
|
+
store: {}
|
|
66
|
+
};
|
|
67
|
+
const _resolve = {
|
|
68
|
+
location: '/leads'
|
|
69
|
+
};
|
|
70
|
+
// @ts-expect-error -- resolve is true or absent
|
|
71
|
+
const _resolveFalse = {
|
|
72
|
+
resolve: false
|
|
73
|
+
};
|
|
74
|
+
const _dont = {
|
|
75
|
+
location: '/leads',
|
|
76
|
+
resolve: false
|
|
77
|
+
};
|
|
78
|
+
// @ts-expect-error -- resolve: false is required
|
|
79
|
+
const _dontAbsent = {
|
|
80
|
+
location: '/leads'
|
|
81
|
+
};
|
|
@@ -147,7 +147,8 @@ export async function hydrateTestApp(RootComponent, ...args) {
|
|
|
147
147
|
const clientProps = options?.props ?? {}; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
148
148
|
const serverProps = options?.serverProps ?? clientProps;
|
|
149
149
|
const location = options?.location ?? '/';
|
|
150
|
-
const globalData = options?.globalData ? options.globalData
|
|
150
|
+
const globalData = options?.globalData ? options.globalData // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
151
|
+
: {}; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
151
152
|
const matchedRouteInfo = {
|
|
152
153
|
key: null,
|
|
153
154
|
params: options?.routeParams ?? {},
|
|
@@ -167,9 +168,9 @@ export async function hydrateTestApp(RootComponent, ...args) {
|
|
|
167
168
|
// routing() falls back to the built-in 404 when neither '404' nor 'default' is given
|
|
168
169
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
169
170
|
const appRoutes = options?.routes ?? {};
|
|
170
|
-
const context = options?.context ?? {};
|
|
171
|
+
const context = options?.context ?? {}; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
171
172
|
// one object for both passes: the server's is serialized into the page and carried to the client
|
|
172
|
-
const networkedData = options?.networkedData ?? {};
|
|
173
|
+
const networkedData = options?.networkedData ?? {}; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
173
174
|
// dev, so a path given twice fails the test
|
|
174
175
|
const routes = toRoutes(typeof appRoutes === 'function' ? appRoutes(null, context, networkedData) : appRoutes, true);
|
|
175
176
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- rootToHtml.ts builds a root content node the same way
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export { loadEnv } from './loadEnv.js';
|
|
2
2
|
export { testEnvVariableName } from './testEnvIsRequested.js';
|
|
3
3
|
export { type HydrateTestApp, type HydrateTestAppOptions, hydrateTestApp, } from './hydrateTestApp.js';
|
|
4
|
-
export { type HydrateTestPipelineApp, type HydrateTestPipelineAppOptions, hydrateTestPipelineApp, } from './hydrateTestPipelineApp.js';
|
|
5
4
|
export { type ComponentProps, type CreateTestAppArgs, type TestApp, type TestAppOptions, type TestStore, type TestStoreOverride, type TestStoreRegistration, type TestRoutes, createTestApp, testStore, } from './createTestApp.js';
|
|
6
|
-
export { type
|
|
7
|
-
export { type HostOptions, type HostStoreOptions, type Hosted, type HostedResolved, host, hostGeneric, hostJsx, } from './host.js';
|
|
5
|
+
export { type HostDontResolveOptions, type HostOptions, type HostResolveOptions, type HostStoreDontResolveOptions, type HostStoreOptions, type HostStoreResolveOptions, type Hosted, type HostedResolved, host, hostGeneric, hostJsx, } from './host.js';
|
|
8
6
|
export { testingComponentPackage } from './testingComponentPackage.js';
|
|
9
7
|
export { contentHtmlElements } from './helpers/contentHtmlElements.js';
|
|
10
8
|
export { ensure } from './ensure.js';
|
|
9
|
+
export { contentToString, type ContentToStringOptions } from './contentToString.js';
|
|
11
10
|
export { makeStore, type TrueStore } from '../Store/makeStore.js';
|
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACH,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAC/C,cAAc,GACjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACH,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EACH,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAC/C,cAAc,GACjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACH,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAC9F,KAAK,iBAAiB,EAAE,KAAK,qBAAqB,EAAE,KAAK,UAAU,EACnE,aAAa,EAAE,SAAS,GAC3B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACH,KAAK,sBAAsB,EAAE,KAAK,WAAW,EAAE,KAAK,kBAAkB,EACtE,KAAK,2BAA2B,EAAE,KAAK,gBAAgB,EAAE,KAAK,uBAAuB,EACrF,KAAK,MAAM,EAAE,KAAK,cAAc,EAChC,IAAI,EAAE,WAAW,EAAE,OAAO,GAC7B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AACnF,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAA"}
|
package/dist/testing/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { loadEnv } from './loadEnv.js';
|
|
2
2
|
export { testEnvVariableName } from './testEnvIsRequested.js';
|
|
3
3
|
export { hydrateTestApp } from './hydrateTestApp.js';
|
|
4
|
-
export { hydrateTestPipelineApp } from './hydrateTestPipelineApp.js';
|
|
5
4
|
export { createTestApp, testStore } from './createTestApp.js';
|
|
6
|
-
export { createTestPipelineApp } from './createTestPipelineApp.js';
|
|
7
5
|
export { host, hostGeneric, hostJsx } from './host.js';
|
|
8
6
|
export { testingComponentPackage } from './testingComponentPackage.js';
|
|
9
7
|
export { contentHtmlElements } from './helpers/contentHtmlElements.js';
|
|
10
8
|
export { ensure } from './ensure.js';
|
|
9
|
+
export { contentToString } from './contentToString.js';
|
|
11
10
|
export { makeStore } from '../Store/makeStore.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ConstructPackage, TungstenBaseComponent, TungstenComponentPropsBase } from '../../Components.jsx';
|
|
2
|
+
import type { Nothing } from '../../pipeline/pipeline.js';
|
|
3
|
+
import type { TestApp } from '../createTestApp.js';
|
|
4
|
+
import type { PipelineTestAppOptions } from './pipelineTestApp.js';
|
|
5
|
+
type Field<K extends string, T, Default> = Default extends T ? {
|
|
6
|
+
[_ in K]?: T;
|
|
7
|
+
} : {
|
|
8
|
+
[_ in K]: T;
|
|
9
|
+
};
|
|
10
|
+
export type PacketForComponent<C> = C extends {
|
|
11
|
+
readonly tungsten: {
|
|
12
|
+
readonly context: infer Ctx;
|
|
13
|
+
readonly networked: infer N;
|
|
14
|
+
readonly allRoutesData: infer G;
|
|
15
|
+
};
|
|
16
|
+
} ? Field<'context', Ctx, Nothing> & Field<'networked', N, Nothing> & Field<'allRoutesData', G, undefined> & {
|
|
17
|
+
routes?: never;
|
|
18
|
+
} : 'invalid component';
|
|
19
|
+
export type TestPacketAppOptions<Props extends object> = PipelineTestAppOptions<Props>;
|
|
20
|
+
export type CreateTestPacketAppArgs<Props extends object> = object extends Props ? [options?: TestPacketAppOptions<Props>] : [options: TestPacketAppOptions<Props> & {
|
|
21
|
+
props: Props;
|
|
22
|
+
}];
|
|
23
|
+
/**
|
|
24
|
+
* createTestPipelineApp() with the pipeline's result in place of the pipeline: the component is
|
|
25
|
+
* handed the packet's context, networked data and all-routes data as they are, with no stages run.
|
|
26
|
+
* There are no routes; the location still reaches the instance.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createTestPacketApp<Props extends TungstenComponentPropsBase, Component extends TungstenBaseComponent<any, any>, RouteData = undefined>(packet: PacketForComponent<Component>, RootComponent: new (pkg: ConstructPackage<Props, RouteData>) => Component, ...args: CreateTestPacketAppArgs<Props>): Promise<TestApp<Component>>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=createTestPacketApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTestPacketApp.d.ts","sourceRoot":"","sources":["../../../src/testing/pipeline/createTestPacketApp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAAE,qBAAqB,EAAE,0BAA0B,EACt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D;;;;GAIG;AACH,wBAAsB,mBAAmB,CACrC,KAAK,SAAS,0BAA0B,EACxC,SAAS,SAAS,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EACjD,SAAS,GAAG,SAAS,EAErB,MAAM,EAAE,kBAAkB,CAAC,SAAS,CAAC,EAErC,aAAa,EAAE,KAAK,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,SAAS,EACzE,GAAG,IAAI,EAAE,uBAAuB,CAAC,KAAK,CAAC,GACxC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CA8B7B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isPipelineApp } from '../../pipeline/pipelineDefinition.js';
|
|
2
|
+
import { routingNetworkedData } from '../../pipeline/runPipeline.js';
|
|
3
|
+
import { routing } from "../../Servers/routing.js";
|
|
4
|
+
import { toRoutes } from '../../routing/routesArray.js';
|
|
5
|
+
import { waitForEnvIfLoading } from '../loadEnv.js';
|
|
6
|
+
import { mountPipelineTestApp, pipelineTestTarget } from './pipelineTestApp.js';
|
|
7
|
+
/**
|
|
8
|
+
* createTestPipelineApp() with the pipeline's result in place of the pipeline: the component is
|
|
9
|
+
* handed the packet's context, networked data and all-routes data as they are, with no stages run.
|
|
10
|
+
* There are no routes; the location still reaches the instance.
|
|
11
|
+
*/
|
|
12
|
+
export async function createTestPacketApp(packet,
|
|
13
|
+
// Props is inferred from both the class and `props`, so literal props are typed by the component
|
|
14
|
+
RootComponent, ...args) {
|
|
15
|
+
await waitForEnvIfLoading();
|
|
16
|
+
const options = args[0];
|
|
17
|
+
if (isPipelineApp(packet) || typeof packet === 'object' && 'routes' in packet) {
|
|
18
|
+
throw new Error('createTestPacketApp() takes what a pipeline makes, { context, networked,' + ' allRoutesData }: for a pipeline or app, use createTestPipelineApp().');
|
|
19
|
+
}
|
|
20
|
+
const target = pipelineTestTarget(options, 'createTestPacketApp()');
|
|
21
|
+
const given = packet; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- the constraint above
|
|
22
|
+
const location = options?.location ?? '/';
|
|
23
|
+
const context = given.context ?? {}; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- the framework brands what it builds
|
|
24
|
+
const allRoutesData = given.allRoutesData; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- as above
|
|
25
|
+
const networkedData = routingNetworkedData(undefined);
|
|
26
|
+
const routes = toRoutes([], true);
|
|
27
|
+
const matchedRouteInfo = await routing(location, routes, context, networkedData);
|
|
28
|
+
return mountPipelineTestApp(target, {
|
|
29
|
+
location,
|
|
30
|
+
routes,
|
|
31
|
+
matchedRouteInfo,
|
|
32
|
+
allRoutesData,
|
|
33
|
+
context,
|
|
34
|
+
networkedData,
|
|
35
|
+
appRoutes: () => routes,
|
|
36
|
+
networked: given.networked ?? {},
|
|
37
|
+
// a navigation keeps the packet's all-routes data
|
|
38
|
+
pipeline: {
|
|
39
|
+
routingContext: context,
|
|
40
|
+
routingNetworkedData: networkedData,
|
|
41
|
+
allRoutesData: undefined,
|
|
42
|
+
afterRouting: undefined
|
|
43
|
+
}
|
|
44
|
+
}, RootComponent, options);
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTestPacketApp.types.test.d.ts","sourceRoot":"","sources":["../../../src/testing/pipeline/createTestPacketApp.types.test.ts"],"names":[],"mappings":"AAkCA,wBAAsB,MAAM,kBAgB3B;AAGD,wBAAsB,YAAY,kBAUjC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
|
+
import { TungstenSimpleComponent } from "../../Components.js";
|
|
5
|
+
import { contextStore } from '../../pipeline/contextStore.js';
|
|
6
|
+
import { pipeline } from '../../pipeline/pipeline.js';
|
|
7
|
+
import { splitPipeline } from '../../pipeline/splitPipeline.js';
|
|
8
|
+
import { createTestPacketApp } from './createTestPacketApp.js';
|
|
9
|
+
// Type tests: tsc is the assertion - nothing here runs. The packet must be what the root reads
|
|
10
|
+
const stage = pipeline.server('express').init(() => ({
|
|
11
|
+
api: 'client'
|
|
12
|
+
})).allRoutesData(() => ({
|
|
13
|
+
theme: 'dark'
|
|
14
|
+
}));
|
|
15
|
+
class Reads extends stage.SimpleComponent {
|
|
16
|
+
constructor(...args) {
|
|
17
|
+
super(...args);
|
|
18
|
+
_defineProperty(this, "content", () => `${this.tungsten.context.api} ${this.tungsten.allRoutesData.theme}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class Plain extends TungstenSimpleComponent {
|
|
22
|
+
constructor(...args) {
|
|
23
|
+
super(...args);
|
|
24
|
+
_defineProperty(this, "content", () => null);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const bare = pipeline.server('express');
|
|
28
|
+
class ReadsNothing extends bare.SimpleComponent {
|
|
29
|
+
constructor(...args) {
|
|
30
|
+
super(...args);
|
|
31
|
+
_defineProperty(this, "content", () => null);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const split = splitPipeline.server('express').serverInit(() => ({
|
|
35
|
+
networked: {
|
|
36
|
+
count: contextStore({
|
|
37
|
+
n: 0
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
})).clientInit(() => undefined);
|
|
41
|
+
class ReadsNetworked extends split.SimpleComponent {
|
|
42
|
+
constructor(...args) {
|
|
43
|
+
super(...args);
|
|
44
|
+
_defineProperty(this, "content", () => String(this.tungsten.networked.count.n.get()));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function checks() {
|
|
48
|
+
await createTestPacketApp({
|
|
49
|
+
context: {
|
|
50
|
+
api: 'a'
|
|
51
|
+
},
|
|
52
|
+
allRoutesData: {
|
|
53
|
+
theme: 't'
|
|
54
|
+
}
|
|
55
|
+
}, Reads);
|
|
56
|
+
// @ts-expect-error -- Reads reads a context: it has no default
|
|
57
|
+
await createTestPacketApp({
|
|
58
|
+
allRoutesData: {
|
|
59
|
+
theme: 't'
|
|
60
|
+
}
|
|
61
|
+
}, Reads);
|
|
62
|
+
// @ts-expect-error -- nor does its all-routes data
|
|
63
|
+
await createTestPacketApp({
|
|
64
|
+
context: {
|
|
65
|
+
api: 'a'
|
|
66
|
+
}
|
|
67
|
+
}, Reads);
|
|
68
|
+
// @ts-expect-error -- not the context Reads reads
|
|
69
|
+
await createTestPacketApp({
|
|
70
|
+
context: {
|
|
71
|
+
api: 1
|
|
72
|
+
},
|
|
73
|
+
allRoutesData: {
|
|
74
|
+
theme: 't'
|
|
75
|
+
}
|
|
76
|
+
}, Reads);
|
|
77
|
+
// the defaults: nothing read, nothing needed
|
|
78
|
+
await createTestPacketApp({}, ReadsNothing);
|
|
79
|
+
await createTestPacketApp({}, Plain);
|
|
80
|
+
await createTestPacketApp({
|
|
81
|
+
networked: {
|
|
82
|
+
count: contextStore({
|
|
83
|
+
n: 1
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}, ReadsNetworked);
|
|
87
|
+
// @ts-expect-error -- ReadsNetworked reads networked data
|
|
88
|
+
await createTestPacketApp({}, ReadsNetworked);
|
|
89
|
+
}
|
|
90
|
+
// a pipeline or app belongs to createTestPipelineApp()
|
|
91
|
+
export async function notAPipeline() {
|
|
92
|
+
// @ts-expect-error -- a stage
|
|
93
|
+
await createTestPacketApp(bare, ReadsNothing);
|
|
94
|
+
// @ts-expect-error -- an app
|
|
95
|
+
await createTestPacketApp(bare.routes(() => []), ReadsNothing);
|
|
96
|
+
// a loose component: an app's allRoutesData function would pass for its all-routes data
|
|
97
|
+
// @ts-expect-error -- a stage
|
|
98
|
+
await createTestPacketApp(stage, Plain);
|
|
99
|
+
// @ts-expect-error -- an app
|
|
100
|
+
await createTestPacketApp(stage.routes(() => []), Plain);
|
|
101
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ConstructPackage, TungstenBaseComponent, TungstenComponentPropsBase } from '../../Components.jsx';
|
|
2
|
+
import type { AllRoutesDataConstraint, PipelineApp } from '../../pipeline/pipelineDefinition.js';
|
|
3
|
+
import type { TestApp } from '../createTestApp.js';
|
|
4
|
+
import type { PipelineTestAppOptions } from './pipelineTestApp.js';
|
|
5
|
+
type StageForApp<App> = {
|
|
6
|
+
routes: (routes: () => []) => App;
|
|
7
|
+
};
|
|
8
|
+
type AppOf<A> = A extends PipelineApp<any, any, any, any> ? A : A extends StageForApp<infer App> ? App : never;
|
|
9
|
+
type AppTypes<A> = AppOf<A> extends PipelineApp<any, infer Ctx, infer N, infer G extends AllRoutesDataConstraint> ? {
|
|
10
|
+
context: Ctx;
|
|
11
|
+
networked: N & object;
|
|
12
|
+
allRoutesData: G;
|
|
13
|
+
} : never;
|
|
14
|
+
export type PipelineAppForComponent<C> = C extends {
|
|
15
|
+
readonly tungsten: {
|
|
16
|
+
readonly context: infer Ctx;
|
|
17
|
+
readonly networked: infer N;
|
|
18
|
+
readonly allRoutesData: infer G;
|
|
19
|
+
};
|
|
20
|
+
} ? PipelineApp<any, Ctx, N, G> : 'invalid component';
|
|
21
|
+
export type PipelineForComponent<C> = PipelineAppForComponent<C> extends infer App ? App extends PipelineApp<any, any, any, any> ? StageForApp<App> : App : never;
|
|
22
|
+
type ComponentReads<C> = C extends {
|
|
23
|
+
readonly tungsten: {
|
|
24
|
+
readonly context: infer Ctx;
|
|
25
|
+
readonly networked: infer N;
|
|
26
|
+
readonly allRoutesData: infer G;
|
|
27
|
+
};
|
|
28
|
+
} ? {
|
|
29
|
+
context: Ctx;
|
|
30
|
+
networked: N;
|
|
31
|
+
allRoutesData: G;
|
|
32
|
+
} : never;
|
|
33
|
+
type DifferingKeys<Made, Read> = {
|
|
34
|
+
[K in keyof Made & keyof Read]: [Made[K]] extends [Read[K]] ? never : K;
|
|
35
|
+
}[keyof Made & keyof Read];
|
|
36
|
+
type Mismatch<Made, Read> = [DifferingKeys<Made, Read>] extends [never] ? unknown : DifferingKeys<Made, Read> extends infer Ks extends keyof Made & keyof Read ? {
|
|
37
|
+
'pipeline does not provide required data:': {
|
|
38
|
+
[K in Ks]: Read[K];
|
|
39
|
+
};
|
|
40
|
+
'pipeline provided:': {
|
|
41
|
+
[K in Ks]: Made[K];
|
|
42
|
+
};
|
|
43
|
+
} : never;
|
|
44
|
+
export type AppCheck<A, C> = [AppOf<A>] extends [never] ? A extends {
|
|
45
|
+
clientAllRoutesData: unknown;
|
|
46
|
+
} ? {
|
|
47
|
+
'add .clientAllRoutesData(): the server makes all-routes data, so the client must': true;
|
|
48
|
+
} : {
|
|
49
|
+
'not a .routes() app, or a stage .routes() can follow': true;
|
|
50
|
+
} : [ComponentReads<C>] extends [never] ? {
|
|
51
|
+
'not a tungsten component': true;
|
|
52
|
+
} : Mismatch<AppTypes<A>, ComponentReads<C>>;
|
|
53
|
+
export declare const toApp: (pipelineOrApp: unknown) => PipelineApp;
|
|
54
|
+
export type TestPipelineAppOptions<Props extends object, A = PipelineApp> = PipelineTestAppOptions<Props> & {
|
|
55
|
+
allRoutesData?: AppTypes<A>['allRoutesData'];
|
|
56
|
+
networked?: AppTypes<A>['networked'];
|
|
57
|
+
};
|
|
58
|
+
export type TestPipelineApp<Component extends TungstenBaseComponent> = TestApp<Component>;
|
|
59
|
+
export type CreateTestPipelineAppArgs<Props extends object, A = PipelineApp> = object extends Props ? [options?: TestPipelineAppOptions<Props, A>] : [options: TestPipelineAppOptions<Props, A> & {
|
|
60
|
+
props: Props;
|
|
61
|
+
}];
|
|
62
|
+
/**
|
|
63
|
+
* createTestApp() for an app built with pipeline() or splitPipeline(): the app's browser stages
|
|
64
|
+
* run - Init, the all-routes data, Post - and the location is routed against its routes, so the
|
|
65
|
+
* test sees the context, stores and route the app's own page would. The app is a .routes()
|
|
66
|
+
* result: the app's own export, a smaller set of routes on the same pipeline, or another pipeline.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createTestPipelineApp<Props extends TungstenComponentPropsBase, Component extends TungstenBaseComponent<any, any>, A extends object, RouteData = undefined>(pipelineOrApp: A & AppCheck<A, Component>, RootComponent: new (pkg: ConstructPackage<Props, RouteData>) => Component, ...args: CreateTestPipelineAppArgs<Props, A>): Promise<TestPipelineApp<Component>>;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=createTestPipelineApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTestPipelineApp.d.ts","sourceRoot":"","sources":["../../../src/testing/pipeline/createTestPipelineApp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACR,gBAAgB,EAAE,qBAAqB,EAAE,0BAA0B,EACtE,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EACR,uBAAuB,EAAgB,WAAW,EACrD,MAAM,sCAAsC,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAclE,KAAK,WAAW,CAAC,GAAG,IAAI;IAAE,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,CAAA;CAAE,CAAA;AAG7D,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GACvD,CAAC,SAAS,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,KAAK,CAAA;AAGpD,KAAK,QAAQ,CAAC,CAAC,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MAAM,EAAE,CAAC,GAAG,WAAW,IAClE,sBAAsB,CAAC,KAAK,CAAC,GAAG;IAE9B,aAAa,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAA;IAG5C,SAAS,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;CACvC,CAAA;AAEL,MAAM,MAAM,eAAe,CAAC,SAAS,SAAS,qBAAqB,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;AAGzF,MAAM,MAAM,yBAAyB,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC,GAAG,WAAW,IAAI,MAAM,SAAS,KAAK,GAC7F,CAAC,OAAO,CAAC,EAAE,sBAAsB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAG5C,CAAC,OAAO,EAAE,sBAAsB,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAAA;AAqDpE;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACvC,KAAK,SAAS,0BAA0B,EACxC,SAAS,SAAS,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAGjD,CAAC,SAAS,MAAM,EAChB,SAAS,GAAG,SAAS,EAErB,aAAa,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,SAAS,CAAC,EAEzC,aAAa,EAAE,KAAK,GAAG,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,SAAS,EACzE,GAAG,IAAI,EAAE,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,GAC7C,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAkCrC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { clientRoute, isPipelineApp } from '../../pipeline/pipelineDefinition.js';
|
|
2
|
+
import { JSONstringify } from '../../json.js';
|
|
3
|
+
import { routing } from "../../Servers/routing.js";
|
|
4
|
+
import { fromTransport, NetworkedTransport } from '../../pipeline/networkedTransport.js';
|
|
5
|
+
import { afterRoutingFor, pipelineContext, pipelineRoutes, routingContext, routingNetworkedData } from '../../pipeline/runPipeline.js';
|
|
6
|
+
import { splitContext } from '../../pipeline/runSplitPipeline.js';
|
|
7
|
+
import { waitForEnvIfLoading } from '../loadEnv.js';
|
|
8
|
+
import { mountPipelineTestApp, pipelineTestTarget } from './pipelineTestApp.js';
|
|
9
|
+
// the app, or the stage ended with empty routes
|
|
10
|
+
export const toApp = pipelineOrApp => isPipelineApp(pipelineOrApp) ? pipelineOrApp : pipelineOrApp.routes(() => []); // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- the harnesses' constraint: a stage
|
|
11
|
+
// the symmetric pipeline's stages, with null for the request
|
|
12
|
+
async function runSymmetric(app, allRoutesData) {
|
|
13
|
+
const init = await app.init?.(null, undefined);
|
|
14
|
+
const data = allRoutesData ?? (await app.allRoutesData?.(null, init));
|
|
15
|
+
const post = await app.post?.(null, init, data);
|
|
16
|
+
const rerun = app.allRoutesData;
|
|
17
|
+
return {
|
|
18
|
+
init,
|
|
19
|
+
context: pipelineContext(init, post),
|
|
20
|
+
routingContext: init,
|
|
21
|
+
routingNetworkedData: undefined,
|
|
22
|
+
networked: {},
|
|
23
|
+
allRoutesData: data,
|
|
24
|
+
rerunAllRoutesData: rerun && (async () => rerun(null, init)),
|
|
25
|
+
afterRouting: undefined
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function runSplit(app, allRoutesData, served) {
|
|
29
|
+
const page = JSON.parse(JSONstringify(new NetworkedTransport(served))); // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- toJSON gives an object
|
|
30
|
+
const networked = fromTransport(page) ?? {};
|
|
31
|
+
const init = await app.clientInit?.(networked);
|
|
32
|
+
const data = allRoutesData ?? (await app.clientAllRoutesData?.(init));
|
|
33
|
+
const post = await app.clientPost?.(init, data);
|
|
34
|
+
const context = splitContext(init, post);
|
|
35
|
+
const rerun = app.clientAllRoutesData;
|
|
36
|
+
const afterRouting = app.clientAfterRouting;
|
|
37
|
+
return {
|
|
38
|
+
init,
|
|
39
|
+
context,
|
|
40
|
+
routingContext: init?.context,
|
|
41
|
+
routingNetworkedData: init?.networked,
|
|
42
|
+
networked,
|
|
43
|
+
allRoutesData: data,
|
|
44
|
+
rerunAllRoutesData: rerun && (async () => rerun(init)),
|
|
45
|
+
afterRouting: afterRouting && (async (route, allRoutes) => splitContext(await afterRouting(context, route, allRoutes), undefined))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* createTestApp() for an app built with pipeline() or splitPipeline(): the app's browser stages
|
|
50
|
+
* run - Init, the all-routes data, Post - and the location is routed against its routes, so the
|
|
51
|
+
* test sees the context, stores and route the app's own page would. The app is a .routes()
|
|
52
|
+
* result: the app's own export, a smaller set of routes on the same pipeline, or another pipeline.
|
|
53
|
+
*/
|
|
54
|
+
export async function createTestPipelineApp(pipelineOrApp,
|
|
55
|
+
// Props is inferred from both the class and `props`, so literal props are typed by the component
|
|
56
|
+
RootComponent, ...args) {
|
|
57
|
+
await waitForEnvIfLoading();
|
|
58
|
+
const options = args[0];
|
|
59
|
+
const target = pipelineTestTarget(options, 'createTestPipelineApp()');
|
|
60
|
+
const app = toApp(pipelineOrApp);
|
|
61
|
+
const stages = app.split === true ? await runSplit(app, options?.allRoutesData, options?.networked ?? {}) : await runSymmetric(app, options?.allRoutesData);
|
|
62
|
+
const location = options?.location ?? '/';
|
|
63
|
+
const allRoutesData = stages.allRoutesData; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- the framework brands what it builds
|
|
64
|
+
const routeContext = routingContext(stages.routingContext);
|
|
65
|
+
const networkedData = routingNetworkedData(stages.routingNetworkedData);
|
|
66
|
+
// dev, so a path given twice fails the test
|
|
67
|
+
const routes = pipelineRoutes(app, null, stages.init, true);
|
|
68
|
+
const matchedRouteInfo = await routing(location, routes, routeContext, networkedData);
|
|
69
|
+
const afterRouting = afterRoutingFor(stages.afterRouting);
|
|
70
|
+
const context = afterRouting === undefined ? stages.context // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- as above
|
|
71
|
+
: await afterRouting(clientRoute(matchedRouteInfo, location), allRoutesData);
|
|
72
|
+
const rerun = stages.rerunAllRoutesData;
|
|
73
|
+
return mountPipelineTestApp(target, {
|
|
74
|
+
location,
|
|
75
|
+
routes,
|
|
76
|
+
matchedRouteInfo,
|
|
77
|
+
allRoutesData,
|
|
78
|
+
context,
|
|
79
|
+
networkedData,
|
|
80
|
+
appRoutes: reqRes => pipelineRoutes(app, reqRes, stages.init, true),
|
|
81
|
+
networked: stages.networked,
|
|
82
|
+
pipeline: {
|
|
83
|
+
routingContext: routeContext,
|
|
84
|
+
routingNetworkedData: networkedData,
|
|
85
|
+
allRoutesData: rerun && (async () => await rerun()),
|
|
86
|
+
// eslint-disable-line @typescript-eslint/no-unsafe-type-assertion -- as above
|
|
87
|
+
afterRouting
|
|
88
|
+
}
|
|
89
|
+
}, RootComponent, options);
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function checks(): Promise<void>;
|
|
2
|
+
export declare function stageChecks(): Promise<void>;
|
|
3
|
+
export declare function bareChecks(): Promise<void>;
|
|
4
|
+
export declare function splitChecks(): Promise<void>;
|
|
5
|
+
export declare function clientDataChecks(): Promise<void>;
|
|
6
|
+
//# sourceMappingURL=createTestPipelineApp.types.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTestPipelineApp.types.test.d.ts","sourceRoot":"","sources":["../../../src/testing/pipeline/createTestPipelineApp.types.test.ts"],"names":[],"mappings":"AA+BA,wBAAsB,MAAM,kBAU3B;AAcD,wBAAsB,WAAW,kBAOhC;AAOD,wBAAsB,UAAU,kBAE/B;AAeD,wBAAsB,WAAW,kBAQhC;AAmBD,wBAAsB,gBAAgB,kBAIrC"}
|