@quilted/create 0.1.66 → 0.1.68
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 +14 -0
- package/build/cjs/_virtual/babel.cjs +5 -0
- package/build/cjs/_virtual/estree.cjs +5 -0
- package/build/cjs/_virtual/typescript.cjs +5 -0
- package/build/cjs/_virtual/yaml.cjs +5 -0
- package/build/cjs/cli.cjs +2 -2
- package/build/cjs/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/babel.cjs +51 -0
- package/build/cjs/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/estree.cjs +70 -0
- package/build/cjs/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/typescript.cjs +62 -0
- package/build/cjs/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/yaml.cjs +196 -0
- package/build/cjs/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/standalone.cjs +69 -0
- package/build/cjs/packages/cli-kit/source/prompt.cjs +2 -2
- package/build/cjs/packages/events/source/{abort.cjs → abort/AbortError.cjs} +6 -0
- package/build/cjs/shared.cjs +4 -8
- package/build/esm/_virtual/babel.mjs +3 -0
- package/build/esm/_virtual/estree.mjs +3 -0
- package/build/esm/_virtual/typescript.mjs +3 -0
- package/build/esm/_virtual/yaml.mjs +3 -0
- package/build/esm/cli.mjs +1 -1
- package/build/esm/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/babel.mjs +46 -0
- package/build/esm/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/estree.mjs +65 -0
- package/build/esm/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/typescript.mjs +57 -0
- package/build/esm/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/yaml.mjs +191 -0
- package/build/esm/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/standalone.mjs +64 -0
- package/build/esm/packages/cli-kit/source/prompt.mjs +1 -1
- package/build/esm/packages/events/source/{abort.mjs → abort/AbortError.mjs} +6 -0
- package/build/esm/shared.mjs +4 -8
- package/build/esnext/_virtual/babel.esnext +3 -0
- package/build/esnext/_virtual/estree.esnext +3 -0
- package/build/esnext/_virtual/typescript.esnext +3 -0
- package/build/esnext/_virtual/yaml.esnext +3 -0
- package/build/esnext/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/babel.esnext +46 -0
- package/build/esnext/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/estree.esnext +65 -0
- package/build/esnext/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/typescript.esnext +57 -0
- package/build/esnext/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/plugins/yaml.esnext +191 -0
- package/build/esnext/node_modules/.pnpm/prettier@3.0.0/node_modules/prettier/standalone.esnext +64 -0
- package/build/esnext/packages/cli-kit/source/prompt.esnext +1 -1
- package/build/esnext/packages/events/source/{abort.esnext → abort/AbortError.esnext} +6 -0
- package/build/esnext/shared.esnext +4 -8
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared.d.ts.map +1 -1
- package/package.json +2 -2
- package/source/help.ts +6 -6
- package/source/package.ts +4 -3
- package/source/shared.ts +10 -7
- package/templates/app-basic/features/Start/Start.test.tsx +2 -2
- package/templates/app-basic/tests/{render.tsx → render/render.tsx} +3 -34
- package/templates/app-basic/tests/render/types.ts +29 -0
- package/templates/app-basic/tests/render.ts +6 -0
- package/templates/app-graphql/features/Start/Start.test.tsx +3 -3
- package/templates/app-graphql/tests/render/render.tsx +59 -0
- package/templates/app-graphql/tests/render/types.ts +63 -0
- package/templates/app-graphql/tests/render.ts +7 -0
- package/templates/app-trpc/App.tsx +32 -2
- package/templates/app-trpc/tests/{render.tsx → render/render.tsx} +12 -37
- package/templates/app-trpc/tests/render/types.ts +35 -0
- package/templates/app-trpc/tests/render.ts +6 -0
- package/build/cjs/_virtual/parser-babel.cjs +0 -5
- package/build/cjs/_virtual/parser-typescript.cjs +0 -5
- package/build/cjs/_virtual/parser-yaml.cjs +0 -5
- package/build/cjs/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-babel.cjs +0 -64
- package/build/cjs/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-typescript.cjs +0 -292
- package/build/cjs/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-yaml.cjs +0 -185
- package/build/cjs/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/standalone.cjs +0 -151
- package/build/esm/_virtual/parser-babel.mjs +0 -3
- package/build/esm/_virtual/parser-typescript.mjs +0 -3
- package/build/esm/_virtual/parser-yaml.mjs +0 -3
- package/build/esm/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-babel.mjs +0 -59
- package/build/esm/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-typescript.mjs +0 -287
- package/build/esm/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-yaml.mjs +0 -180
- package/build/esm/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/standalone.mjs +0 -146
- package/build/esnext/_virtual/parser-babel.esnext +0 -3
- package/build/esnext/_virtual/parser-typescript.esnext +0 -3
- package/build/esnext/_virtual/parser-yaml.esnext +0 -3
- package/build/esnext/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-babel.esnext +0 -59
- package/build/esnext/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-typescript.esnext +0 -287
- package/build/esnext/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/parser-yaml.esnext +0 -180
- package/build/esnext/node_modules/.pnpm/prettier@2.8.1/node_modules/prettier/standalone.esnext +0 -146
- package/templates/app-graphql/tests/render.tsx +0 -126
package/source/help.ts
CHANGED
|
@@ -13,16 +13,16 @@ export function printHelp({
|
|
|
13
13
|
|
|
14
14
|
const usage = stripIndent`
|
|
15
15
|
${color.bold('Usage:')} ${command} ${
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
kind ? color.magenta(kind) : color.magenta('[kind]')
|
|
17
|
+
} ${color.green('[name]')} ${color.cyan('[options]')}
|
|
18
18
|
`;
|
|
19
19
|
|
|
20
20
|
console.log(usage);
|
|
21
21
|
|
|
22
22
|
const example = stripIndent`
|
|
23
23
|
${color.bold('Example:')} ${command} ${color.magenta(
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
kind ?? 'app',
|
|
25
|
+
)} ${color.green(`my-${kind ?? 'app'}`)} ${color.cyan('--install')}
|
|
26
26
|
`;
|
|
27
27
|
|
|
28
28
|
console.log(color.dim(example));
|
|
@@ -72,8 +72,8 @@ export function printHelp({
|
|
|
72
72
|
)} flag is set.
|
|
73
73
|
|
|
74
74
|
Must be one of the following: ${color.bold('pnpm')}, ${color.bold(
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
'npm',
|
|
76
|
+
)}, or ${color.bold('yarn')}.
|
|
77
77
|
|
|
78
78
|
${color.cyan(`--extras`)}, ${color.cyan(`--no-extras`)}
|
|
79
79
|
Extra developer tools to configure when creating your new project. This option only
|
package/source/package.ts
CHANGED
|
@@ -238,9 +238,10 @@ export async function createProject() {
|
|
|
238
238
|
|
|
239
239
|
await outputRoot.write(
|
|
240
240
|
path.join(packageDirectory, 'README.md'),
|
|
241
|
-
(
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
(await packageTemplate.read('README.md')).replaceAll(
|
|
242
|
+
'{{name}}',
|
|
243
|
+
toValidPackageName(name!),
|
|
244
|
+
),
|
|
244
245
|
);
|
|
245
246
|
|
|
246
247
|
if (partOfMonorepo) {
|
package/source/shared.ts
CHANGED
|
@@ -162,14 +162,17 @@ export async function format(
|
|
|
162
162
|
) {
|
|
163
163
|
const [
|
|
164
164
|
{format: rootFormat, default: prettier},
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
babel,
|
|
166
|
+
typescript,
|
|
167
|
+
yaml,
|
|
168
|
+
estree,
|
|
168
169
|
] = await Promise.all([
|
|
169
170
|
import('prettier/standalone'),
|
|
170
|
-
import('prettier/
|
|
171
|
-
import('prettier/
|
|
172
|
-
import('prettier/
|
|
171
|
+
import('prettier/plugins/babel'),
|
|
172
|
+
import('prettier/plugins/typescript'),
|
|
173
|
+
import('prettier/plugins/yaml'),
|
|
174
|
+
// @ts-expect-error Types are not generated correctly for this entry
|
|
175
|
+
import('prettier/plugins/estree'),
|
|
173
176
|
]);
|
|
174
177
|
|
|
175
178
|
// CJS workaround
|
|
@@ -181,7 +184,7 @@ export async function format(
|
|
|
181
184
|
singleQuote: true,
|
|
182
185
|
trailingComma: 'all',
|
|
183
186
|
parser,
|
|
184
|
-
plugins: [babel, typescript, yaml],
|
|
187
|
+
plugins: [babel, typescript, yaml, estree],
|
|
185
188
|
});
|
|
186
189
|
}
|
|
187
190
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {describe, it, expect} from '@quilted/quilt/testing';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {renderApp} from '~/tests/render.ts';
|
|
4
4
|
|
|
5
5
|
import Start from './Start.tsx';
|
|
6
6
|
|
|
7
7
|
describe('<Start />', () => {
|
|
8
8
|
it('includes a welcome message', async () => {
|
|
9
|
-
const start = await
|
|
9
|
+
const start = await renderApp(<Start />);
|
|
10
10
|
expect(start).toContainReactText('Hello world!');
|
|
11
11
|
});
|
|
12
12
|
});
|
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
import '@quilted/quilt/matchers';
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
createRender,
|
|
5
3
|
QuiltAppTesting,
|
|
6
4
|
createTestRouter,
|
|
7
5
|
} from '@quilted/quilt/testing';
|
|
8
6
|
|
|
9
|
-
import {
|
|
10
|
-
AppContextReact,
|
|
11
|
-
type AppContext as AppContextType,
|
|
12
|
-
} from '~/shared/context.ts';
|
|
13
|
-
|
|
14
|
-
type Router = ReturnType<typeof createTestRouter>;
|
|
15
|
-
|
|
16
|
-
export {createTestRouter};
|
|
17
|
-
|
|
18
|
-
export interface RenderOptions {
|
|
19
|
-
/**
|
|
20
|
-
* A custom router to use for this component test. You can use a
|
|
21
|
-
* custom router to simulate a particular URL, and you can spy on
|
|
22
|
-
* its navigation method to check that components navigate as
|
|
23
|
-
* you expect.
|
|
24
|
-
*/
|
|
25
|
-
router?: Router;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A custom locale to use for this component test.
|
|
29
|
-
*/
|
|
30
|
-
locale?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RenderContext extends AppContextType {
|
|
34
|
-
/**
|
|
35
|
-
* The router used for this component test.
|
|
36
|
-
*/
|
|
37
|
-
router: Router;
|
|
38
|
-
}
|
|
7
|
+
import {AppContextReact} from '~/shared/context.ts';
|
|
39
8
|
|
|
40
|
-
|
|
9
|
+
import {RenderOptions, RenderContext, RenderActions} from './types.ts';
|
|
41
10
|
|
|
42
11
|
/**
|
|
43
12
|
* Renders a component with test-friendly versions of all global
|
|
44
13
|
* context available to the application.
|
|
45
14
|
*/
|
|
46
|
-
export const
|
|
15
|
+
export const renderApp = createRender<
|
|
47
16
|
RenderOptions,
|
|
48
17
|
RenderContext,
|
|
49
18
|
RenderActions,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {createTestRouter} from '@quilted/quilt/testing';
|
|
2
|
+
|
|
3
|
+
import type {AppContext} from '~/shared/context.ts';
|
|
4
|
+
|
|
5
|
+
type Router = ReturnType<typeof createTestRouter>;
|
|
6
|
+
|
|
7
|
+
export interface RenderOptions {
|
|
8
|
+
/**
|
|
9
|
+
* A custom router to use for this component test. You can use a
|
|
10
|
+
* custom router to simulate a particular URL, and you can spy on
|
|
11
|
+
* its navigation method to check that components navigate as
|
|
12
|
+
* you expect.
|
|
13
|
+
*/
|
|
14
|
+
readonly router?: Router;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A custom locale to use for this component test.
|
|
18
|
+
*/
|
|
19
|
+
readonly locale?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface RenderContext extends AppContext {
|
|
23
|
+
/**
|
|
24
|
+
* The router used for this component test.
|
|
25
|
+
*/
|
|
26
|
+
readonly router: Router;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RenderActions extends Record<string, never> {}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {describe, it, expect} from '@quilted/quilt/testing';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
createGraphQLController,
|
|
4
|
+
renderApp,
|
|
6
5
|
fillGraphQL,
|
|
6
|
+
createGraphQLController,
|
|
7
7
|
} from '~/tests/render.tsx';
|
|
8
8
|
|
|
9
9
|
import Start from './Start.tsx';
|
|
@@ -14,7 +14,7 @@ describe('<Start />', () => {
|
|
|
14
14
|
const name = 'Winston';
|
|
15
15
|
const graphql = createGraphQLController(fillGraphQL(startQuery, {name}));
|
|
16
16
|
|
|
17
|
-
const start = await
|
|
17
|
+
const start = await renderApp(<Start />, {graphql});
|
|
18
18
|
|
|
19
19
|
expect(graphql).toHavePerformedGraphQLOperation(startQuery);
|
|
20
20
|
expect(start).toContainReactText(`Hello ${name}!`);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRender,
|
|
3
|
+
QuiltAppTesting,
|
|
4
|
+
createTestRouter,
|
|
5
|
+
} from '@quilted/quilt/testing';
|
|
6
|
+
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
|
|
7
|
+
|
|
8
|
+
import {AppContextReact} from '~/shared/context.ts';
|
|
9
|
+
|
|
10
|
+
import {TestGraphQL, createGraphQLController} from '../graphql.ts';
|
|
11
|
+
|
|
12
|
+
import {RenderOptions, RenderContext, RenderActions} from './types.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Renders a component with test-friendly versions of all global
|
|
16
|
+
* context available to the application.
|
|
17
|
+
*/
|
|
18
|
+
export const renderApp = createRender<
|
|
19
|
+
RenderOptions,
|
|
20
|
+
RenderContext,
|
|
21
|
+
RenderActions,
|
|
22
|
+
true
|
|
23
|
+
>({
|
|
24
|
+
// Create context that can be used by the `render` function, and referenced by test
|
|
25
|
+
// authors on the `root.context` property. Context is used to share data between your
|
|
26
|
+
// React tree and your test code, and is ideal for mocking out global context providers.
|
|
27
|
+
context({router = createTestRouter(), graphql = createGraphQLController()}) {
|
|
28
|
+
return {router, graphql, queryClient: new QueryClient()};
|
|
29
|
+
},
|
|
30
|
+
// Render all of our app-wide context providers around each component under test.
|
|
31
|
+
render(element, context, {locale}) {
|
|
32
|
+
const {router, graphql, queryClient} = context;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<QuiltAppTesting routing={router} localization={locale}>
|
|
36
|
+
<AppContextReact.Provider value={context}>
|
|
37
|
+
<TestGraphQL controller={graphql}>
|
|
38
|
+
<QueryClientProvider client={queryClient}>
|
|
39
|
+
{element}
|
|
40
|
+
</QueryClientProvider>
|
|
41
|
+
</TestGraphQL>
|
|
42
|
+
</AppContextReact.Provider>
|
|
43
|
+
</QuiltAppTesting>
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
async afterRender(wrapper) {
|
|
47
|
+
// If your components need to resolve data before they can render, you can
|
|
48
|
+
// use this hook to wait for that data to be ready. This will cause the
|
|
49
|
+
// `render` function to return a promise, so that the component is only usable
|
|
50
|
+
// once the data is ready.
|
|
51
|
+
|
|
52
|
+
await wrapper.act(async () => {
|
|
53
|
+
await wrapper.context.graphql.resolveAll();
|
|
54
|
+
|
|
55
|
+
// react-query needs an extra tick to set state in response to GraphQL queries.
|
|
56
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type {createTestRouter} from '@quilted/quilt/testing';
|
|
2
|
+
import type {QueryClient} from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
import type {AppContext} from '~/shared/context.ts';
|
|
5
|
+
|
|
6
|
+
import type {GraphQLController} from '../graphql.ts';
|
|
7
|
+
|
|
8
|
+
type Router = ReturnType<typeof createTestRouter>;
|
|
9
|
+
|
|
10
|
+
export interface RenderOptions {
|
|
11
|
+
/**
|
|
12
|
+
* A custom router to use for this component test. You can use a
|
|
13
|
+
* custom router to simulate a particular URL, and you can spy on
|
|
14
|
+
* its navigation method to check that components navigate as
|
|
15
|
+
* you expect.
|
|
16
|
+
*/
|
|
17
|
+
readonly router?: Router;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An object that controls the responses to GraphQL queries and mutations
|
|
21
|
+
* for the component under test. You can customize the responses using
|
|
22
|
+
* the `fillGraphQL` and `createGraphQLController` utilities provided
|
|
23
|
+
* by this module.
|
|
24
|
+
*
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import {renderWithAppContext, fillGraphQL, createGraphQLController} from '~/tests/render.tsx';
|
|
27
|
+
*
|
|
28
|
+
* import {MyComponent} from './MyComponent.tsx';
|
|
29
|
+
* import myComponentQuery from './MyComponentQuery.graphql';
|
|
30
|
+
*
|
|
31
|
+
* const myComponent = await renderWithAppContext(<MyComponent />, {
|
|
32
|
+
* graphql: createGraphQLController(
|
|
33
|
+
* fillGraphQL(myComponentQuery, {user: {name: 'Winston'}}),
|
|
34
|
+
* ),
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
readonly graphql?: GraphQLController;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A custom locale to use for this component test.
|
|
42
|
+
*/
|
|
43
|
+
readonly locale?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RenderContext extends AppContext {
|
|
47
|
+
/**
|
|
48
|
+
* The router used for this component test.
|
|
49
|
+
*/
|
|
50
|
+
readonly router: Router;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The GraphQL controller used for this component test.
|
|
54
|
+
*/
|
|
55
|
+
readonly graphql: GraphQLController;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The react-query client used for this component test.
|
|
59
|
+
*/
|
|
60
|
+
readonly queryClient: QueryClient;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RenderActions extends Record<string, never> {}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
QuiltApp,
|
|
3
|
+
useRoutes,
|
|
4
|
+
type PropsWithChildren,
|
|
5
|
+
useInitialUrl,
|
|
6
|
+
} from '@quilted/quilt';
|
|
7
|
+
|
|
8
|
+
import {httpBatchLink} from '@trpc/client';
|
|
9
|
+
import {QueryClient} from '@tanstack/react-query';
|
|
10
|
+
import {ReactQueryContext} from '@quilted/react-query';
|
|
2
11
|
|
|
3
12
|
import {
|
|
4
13
|
AppContextReact,
|
|
5
14
|
type AppContext as AppContextType,
|
|
6
15
|
} from '~/shared/context.ts';
|
|
16
|
+
import {trpc} from '~/shared/trpc.ts';
|
|
7
17
|
|
|
8
18
|
import {Http} from './foundation/Http.tsx';
|
|
9
19
|
import {Head} from './foundation/Head.tsx';
|
|
10
20
|
import {Metrics} from './foundation/Metrics.tsx';
|
|
11
21
|
|
|
12
22
|
import {Start} from './features/Start.tsx';
|
|
23
|
+
import {useMemo} from 'react';
|
|
13
24
|
|
|
14
25
|
export interface Props extends AppContextType {}
|
|
15
26
|
|
|
@@ -38,9 +49,28 @@ function AppContext({
|
|
|
38
49
|
children,
|
|
39
50
|
...appContext
|
|
40
51
|
}: PropsWithChildren<AppContextType>) {
|
|
52
|
+
const initialUrl = useInitialUrl();
|
|
53
|
+
|
|
54
|
+
const {queryClient, trpcClient} = useMemo(() => {
|
|
55
|
+
return {
|
|
56
|
+
queryClient: new QueryClient(),
|
|
57
|
+
trpcClient: trpc.createClient({
|
|
58
|
+
links: [
|
|
59
|
+
// We need to use an absolute URL so that queries will
|
|
60
|
+
// work during server-side rendering
|
|
61
|
+
httpBatchLink({url: new URL('/api', initialUrl).href}),
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
}, [initialUrl]);
|
|
66
|
+
|
|
41
67
|
return (
|
|
42
68
|
<AppContextReact.Provider value={appContext}>
|
|
43
|
-
<Metrics>
|
|
69
|
+
<Metrics>
|
|
70
|
+
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
71
|
+
<ReactQueryContext client={queryClient}>{children}</ReactQueryContext>
|
|
72
|
+
</trpc.Provider>
|
|
73
|
+
</Metrics>
|
|
44
74
|
</AppContextReact.Provider>
|
|
45
75
|
);
|
|
46
76
|
}
|
|
@@ -1,49 +1,20 @@
|
|
|
1
|
-
import '@quilted/quilt/matchers';
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
createRender,
|
|
5
3
|
QuiltAppTesting,
|
|
6
4
|
createTestRouter,
|
|
7
5
|
} from '@quilted/quilt/testing';
|
|
6
|
+
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
|
|
8
7
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
type AppContext as AppContextType,
|
|
12
|
-
} from '~/shared/context.ts';
|
|
13
|
-
|
|
14
|
-
type Router = ReturnType<typeof createTestRouter>;
|
|
15
|
-
|
|
16
|
-
export {createTestRouter};
|
|
17
|
-
|
|
18
|
-
export interface RenderOptions {
|
|
19
|
-
/**
|
|
20
|
-
* A custom router to use for this component test. You can use a
|
|
21
|
-
* custom router to simulate a particular URL, and you can spy on
|
|
22
|
-
* its navigation method to check that components navigate as
|
|
23
|
-
* you expect.
|
|
24
|
-
*/
|
|
25
|
-
router?: Router;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A custom locale to use for this component test.
|
|
29
|
-
*/
|
|
30
|
-
locale?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RenderContext extends AppContextType {
|
|
34
|
-
/**
|
|
35
|
-
* The router used for this component test.
|
|
36
|
-
*/
|
|
37
|
-
router: Router;
|
|
38
|
-
}
|
|
8
|
+
import {trpc} from '~/shared/trpc.ts';
|
|
9
|
+
import {AppContextReact} from '~/shared/context.ts';
|
|
39
10
|
|
|
40
|
-
|
|
11
|
+
import {RenderOptions, RenderContext, RenderActions} from './types.ts';
|
|
41
12
|
|
|
42
13
|
/**
|
|
43
14
|
* Renders a component with test-friendly versions of all global
|
|
44
15
|
* context available to the application.
|
|
45
16
|
*/
|
|
46
|
-
export const
|
|
17
|
+
export const renderApp = createRender<
|
|
47
18
|
RenderOptions,
|
|
48
19
|
RenderContext,
|
|
49
20
|
RenderActions,
|
|
@@ -53,16 +24,20 @@ export const renderWithAppContext = createRender<
|
|
|
53
24
|
// authors on the `root.context` property. Context is used to share data between your
|
|
54
25
|
// React tree and your test code, and is ideal for mocking out global context providers.
|
|
55
26
|
context({router = createTestRouter()}) {
|
|
56
|
-
return {router};
|
|
27
|
+
return {router, trpc: trpc.createClient(), queryClient: new QueryClient()};
|
|
57
28
|
},
|
|
58
29
|
// Render all of our app-wide context providers around each component under test.
|
|
59
30
|
render(element, context, {locale}) {
|
|
60
|
-
const {router} = context;
|
|
31
|
+
const {router, trpc: trpcClient, queryClient} = context;
|
|
61
32
|
|
|
62
33
|
return (
|
|
63
34
|
<QuiltAppTesting routing={router} localization={locale}>
|
|
64
35
|
<AppContextReact.Provider value={context}>
|
|
65
|
-
{
|
|
36
|
+
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
37
|
+
<QueryClientProvider client={queryClient}>
|
|
38
|
+
{element}
|
|
39
|
+
</QueryClientProvider>
|
|
40
|
+
</trpc.Provider>
|
|
66
41
|
</AppContextReact.Provider>
|
|
67
42
|
</QuiltAppTesting>
|
|
68
43
|
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {createTestRouter} from '@quilted/quilt/testing';
|
|
2
|
+
import type {QueryClient} from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
import type {AppContext} from '~/shared/context.ts';
|
|
5
|
+
|
|
6
|
+
type Router = ReturnType<typeof createTestRouter>;
|
|
7
|
+
|
|
8
|
+
export interface RenderOptions {
|
|
9
|
+
/**
|
|
10
|
+
* A custom router to use for this component test. You can use a
|
|
11
|
+
* custom router to simulate a particular URL, and you can spy on
|
|
12
|
+
* its navigation method to check that components navigate as
|
|
13
|
+
* you expect.
|
|
14
|
+
*/
|
|
15
|
+
readonly router?: Router;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A custom locale to use for this component test.
|
|
19
|
+
*/
|
|
20
|
+
readonly locale?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RenderContext extends AppContext {
|
|
24
|
+
/**
|
|
25
|
+
* The router used for this component test.
|
|
26
|
+
*/
|
|
27
|
+
readonly router: Router;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The react-query client used for this component test.
|
|
31
|
+
*/
|
|
32
|
+
readonly queryClient: QueryClient;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RenderActions extends Record<string, never> {}
|