@servicetitan/docs-uikit 32.0.1 → 32.2.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/docs/BREAKING_CHANGES.mdx +1 -0
- package/docs/launchdarkly-service.mdx +1 -1
- package/docs/microfrontends/developing/authentication.mdx +91 -0
- package/docs/microfrontends/developing/developing.mdx +124 -0
- package/docs/microfrontends/developing/headless-bundle.mdx +62 -0
- package/docs/microfrontends/hosting.mdx +84 -0
- package/docs/microfrontends/microfrontends.mdx +45 -0
- package/docs/microfrontends/publishing.mdx +93 -0
- package/docs/microfrontends/sharing-dependencies.mdx +96 -0
- package/docs/microfrontends/troubleshooting.mdx +55 -0
- package/docs/startup/build.mdx +281 -8
- package/docs/startup/lint.mdx +23 -0
- package/docs/startup/mfe-publish.mdx +48 -11
- package/docs/startup/review.mdx +143 -0
- package/docs/startup/start.mdx +46 -1
- package/docs/startup/startup.mdx +5 -375
- package/docs/startup/test/jest.mdx +114 -0
- package/docs/startup/test/test.mdx +72 -0
- package/docs/startup/test/vitest.mdx +117 -0
- package/docs/web-components/headless-loader.mdx +2 -47
- package/docs/web-components/loader.mdx +2 -2
- package/package.json +2 -2
- package/docs/startup/test.mdx +0 -205
package/docs/startup/startup.mdx
CHANGED
|
@@ -34,125 +34,14 @@ Updating build tooling is typically a daunting and time-consuming task. When new
|
|
|
34
34
|
- [start](./start) run project in development mode
|
|
35
35
|
- [test](./test) run tests
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## Configuration
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Use the `cli` key in `package.json` to customize `startup` behavior. The following options apply to all commands. See the [commands](#commands) for command-specific options.
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```json title="package.json"
|
|
44
|
-
{
|
|
45
|
-
"exports": "./dist/index.js",
|
|
46
|
-
"main": "./dist/index.js",
|
|
47
|
-
"typings": "./dist/index.d.ts"
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
And, [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html) should be used to describe the dependencies between components.
|
|
52
|
-
|
|
53
|
-
```json title="tsconfig.json"
|
|
54
|
-
{
|
|
55
|
-
"references": [
|
|
56
|
-
{ "path": "../component-a" },
|
|
57
|
-
{ "path": "../component-b" },
|
|
58
|
-
{ "path": "../component-c" }
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## CSS Modules
|
|
64
|
-
|
|
65
|
-
This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the `[name].module.{css,less,scss}` file naming convention. It allows the scoping of CSS by automatically creating a unique class name.
|
|
66
|
-
|
|
67
|
-
## SVG Transformation
|
|
68
|
-
|
|
69
|
-
:::caution
|
|
70
|
-
Type definitions are provided for the various ways of importing SVGs via the base tsconfig's
|
|
71
|
-
`"files"` property within `startup`. If you override the `"files"` property
|
|
72
|
-
within your tsconfig, you may lose access to these type definitions, and will need to add them
|
|
73
|
-
manually.
|
|
74
|
-
:::
|
|
75
|
-
|
|
76
|
-
By default, SVGs are loaded as assets. Depending on the file size, the asset is converted to a base64 URI string, or emitted as separate file.
|
|
77
|
-
|
|
78
|
-
```tsx
|
|
79
|
-
import MySVG from './my.svg';
|
|
80
|
-
...
|
|
81
|
-
<img src={MySVG} />
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
When importing SVGs from Anvil 2 (`@servicetitan/anvil2`), [SVGR](https://react-svgr.com/) is used to transform SVGs into React components.
|
|
85
|
-
|
|
86
|
-
```tsx
|
|
87
|
-
import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg';
|
|
88
|
-
...
|
|
89
|
-
<CheckIcon />
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
In order to use SVGR with SVGs outside of Anvil 2, you can import them as components by passing the `?component` query to the important statement. For example:
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
import CheckIcon from './assets/check.svg?component';
|
|
96
|
-
...
|
|
97
|
-
<CheckIcon />
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
If you'd like to use SVGs imported from Anvil 2 as assets, you can pass the `?asset` query to the import statement. For example:
|
|
101
|
-
|
|
102
|
-
```tsx
|
|
103
|
-
import CheckIcon from '@servicetitan/anvil2/assets/icons/material/round/check.svg?asset';
|
|
104
|
-
...
|
|
105
|
-
<img src={CheckIcon} />
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Configuration Customization
|
|
109
|
-
|
|
110
|
-
The zero-configuration approach is a good fit for most use cases, but sometimes applications need to extend or override configurations.
|
|
111
|
-
Use the `cli` node in `package.json` to customize `startup` behavior.
|
|
112
|
-
|
|
113
|
-
### Project-wide settings
|
|
114
|
-
|
|
115
|
-
#### Jest
|
|
116
|
-
|
|
117
|
-
Use `cli.test` to set or override Jest options. E.g.,
|
|
118
|
-
|
|
119
|
-
```json title="package.json"
|
|
120
|
-
{
|
|
121
|
-
"cli": {
|
|
122
|
-
"test": {
|
|
123
|
-
// Jest options (https://jestjs.io/docs/next/configuration)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
#### Linting
|
|
130
|
-
|
|
131
|
-
Use `cli.lint` to set or override `ESLint` and `Stylelint` options. E.g,
|
|
132
|
-
|
|
133
|
-
```json title="package.json"
|
|
134
|
-
{
|
|
135
|
-
"cli": {
|
|
136
|
-
"lint": {
|
|
137
|
-
"eslint": {
|
|
138
|
-
// ESLint options (https://eslint.org/docs/user-guide/configuring)
|
|
139
|
-
},
|
|
140
|
-
"stylelint": {
|
|
141
|
-
// Stylelint options (https://stylelint.io/user-guide/configure)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
#### NODE_OPTIONS
|
|
41
|
+
### NODE_OPTIONS
|
|
149
42
|
|
|
150
43
|
Use `cli.NODE_OPTIONS` or `cli.*.NODE_OPTIONS` to set or override Node options for some or all commands. E.g.,
|
|
151
44
|
|
|
152
|
-
:::note
|
|
153
|
-
`startup` automatically runs memory intensive commands (e.g., `build`, `start`, `lint` and `test`) with `--max_old_space_size=8192` by default.
|
|
154
|
-
:::
|
|
155
|
-
|
|
156
45
|
```json title="package.json"
|
|
157
46
|
{
|
|
158
47
|
"cli": {
|
|
@@ -171,265 +60,6 @@ Use `cli.NODE_OPTIONS` or `cli.*.NODE_OPTIONS` to set or override Node options f
|
|
|
171
60
|
}
|
|
172
61
|
```
|
|
173
62
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
#### Type checking
|
|
177
|
-
|
|
178
|
-
Use package-specific `tsconfig.json` and `tsconfig.build.json` files to set or override type checking options. E.g.,
|
|
179
|
-
|
|
180
|
-
```json title="tsconfig.json"
|
|
181
|
-
{
|
|
182
|
-
"extends": "@servicetitan/startup/tsconfig/base",
|
|
183
|
-
"compilerOptions": {
|
|
184
|
-
"outDir": "dist",
|
|
185
|
-
"rootDir": "src",
|
|
186
|
-
... // Other type checking options (https://www.typescriptlang.org/tsconfig/)
|
|
187
|
-
},
|
|
188
|
-
"include": ["src/**/*"]
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
`tsconfig.build.json` takes precedence over `tsconfig.json`. Use `tsconfig.build.json` that extends from `tsconfig.json` to exclude tests, stories, and mocks from type checking during development. E.g.,
|
|
193
|
-
|
|
194
|
-
:::caution
|
|
195
|
-
If your `tsconfig.json` configures project references they must be duplicated in `tsconfig.build.json`.
|
|
196
|
-
|
|
197
|
-
See [references are not inherited in tsconfig.json](https://github.com/microsoft/TypeScript/issues/27098).
|
|
63
|
+
:::tip
|
|
64
|
+
`Startup` automatically uses `--max_old_space_size` to increase available memory for memory intensive commands like `build`, `start`, `lint` and `test`.
|
|
198
65
|
:::
|
|
199
|
-
|
|
200
|
-
```json title="tsconfig.build.json"
|
|
201
|
-
{
|
|
202
|
-
"extends": "./tsconfig.json",
|
|
203
|
-
"exclude": ["**/__tests__/*", "**/*.test.*", "**/__mocks__/*", "**/*.stories.*"],
|
|
204
|
-
"references": [
|
|
205
|
-
{ "path": "../feature-a" },
|
|
206
|
-
{ "path": "../feature-b" },
|
|
207
|
-
{ "path": "../feature-c" }
|
|
208
|
-
]
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
#### TypeScript compilation (SWC)
|
|
213
|
-
|
|
214
|
-
Use `cli.swc-compile-package` to set or override SWC options. E.g.,
|
|
215
|
-
|
|
216
|
-
:::note
|
|
217
|
-
SWC uses a subset of the project-specific `tsconfig.json` file to map SWC options. See [cliOptions](https://github.com/search?q=repo%3Aservicetitan%2Fuikit+%22cliOptions%3A%22+-path%3A**%2F*.test.ts&type=code) and [swcOptions](https://github.com/search?q=repo%3Aservicetitan%2Fuikit+%22swcOptions%3A%22+-path%3A**%2F*.test.ts&type=code) for mapping details.
|
|
218
|
-
:::
|
|
219
|
-
|
|
220
|
-
```json title="package.json"
|
|
221
|
-
{
|
|
222
|
-
"cli": {
|
|
223
|
-
"swc-compile-package": {
|
|
224
|
-
"cliOptions": {
|
|
225
|
-
// CLI options (https://swc.rs/docs/usage/cli)
|
|
226
|
-
},
|
|
227
|
-
"swcOptions": {
|
|
228
|
-
// Compilation options (https://swc.rs/docs/configuration/compilation)
|
|
229
|
-
// Module options (https://swc.rs/docs/configuration/modules)
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
#### TypeScript compilation (TSC)
|
|
237
|
-
|
|
238
|
-
:::caution
|
|
239
|
-
Compilation via TSC is deprecated.
|
|
240
|
-
:::
|
|
241
|
-
|
|
242
|
-
Use project-specific `tsconfig.json` and `tsconfig.build.json` files to set or override compiler options. See [Type checking](/docs/startup/#type-checking) for more information.
|
|
243
|
-
|
|
244
|
-
#### Microfrontends (MFEs)
|
|
245
|
-
|
|
246
|
-
Set `cli.web-component` to `true` to create the support files and `light` and `full` bundles for MFE applications. E.g.,
|
|
247
|
-
|
|
248
|
-
```json title="package.json"
|
|
249
|
-
{
|
|
250
|
-
"cli": {
|
|
251
|
-
"web-component": true
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Or you can set an object with detailed configs:
|
|
257
|
-
|
|
258
|
-
```json title="package.json"
|
|
259
|
-
{
|
|
260
|
-
"cli": {
|
|
261
|
-
"web-component": {
|
|
262
|
-
"branches": {
|
|
263
|
-
"qa": { "publishTag": "qa" }
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Or you can use relative path to a file that exports an object with detailed configs (useful to share configs between multiple MFEs in repo):
|
|
271
|
-
|
|
272
|
-
```json title="package.json"
|
|
273
|
-
{
|
|
274
|
-
"cli": {
|
|
275
|
-
"web-component": "../../config/web-component.js"
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
###### Web component config options
|
|
281
|
-
|
|
282
|
-
- `cli.web-component.branches` - Set git branch specific configs, used for publishing. See [Branch configs](./mfe-publish#branch-configs).
|
|
283
|
-
- `cli.web-component.legacyRoot` - Set to opt-out of automatic batching. See [Opting-out of automatic batching](/docs/frontend/react-18#opting-out-of-automatic-batching).
|
|
284
|
-
|
|
285
|
-
See [MFE configuration](/docs/frontend/micro-frontends/#mfe-configuration) for detailed instructions on configuring MFE applications.
|
|
286
|
-
|
|
287
|
-
###### Headless bundle
|
|
288
|
-
|
|
289
|
-
If a file named `headless.ts` is present in the source folder of an MFE package, `startup` automatically generates a headless bundle alongside the `light` and `full` bundles. See [web-components documentation](../web-components/headless-loader) for information on the headless bundle.
|
|
290
|
-
|
|
291
|
-
#### Webpack
|
|
292
|
-
|
|
293
|
-
Use `cli.webpack` to set or override Webpack options.
|
|
294
|
-
|
|
295
|
-
##### Non-application packages
|
|
296
|
-
|
|
297
|
-
Set `cli.webpack` to `false` to disable Webpack bundling for non-application NPM packages, such as component and utility libraries. E.g.,
|
|
298
|
-
|
|
299
|
-
```json title="package.json"
|
|
300
|
-
{
|
|
301
|
-
"cli": {
|
|
302
|
-
"webpack": false
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
##### Minification
|
|
308
|
-
|
|
309
|
-
By default `startup` configures webpack to minify production bundles conservatively,
|
|
310
|
-
so that projects gain the benefits of reduced bundle sizes while retaining the highest
|
|
311
|
-
fidelity for source map debugging.
|
|
312
|
-
|
|
313
|
-
Set `cli.webpack.minify.js` or `cli.webpack.minify.css` to `false` to prevent webpack from minifying JS or CSS bundles.
|
|
314
|
-
|
|
315
|
-
`startup` uses [TerserWebpackPlugin](https://webpack.js.org/plugins/terser-webpack-plugin) to minify JS bundles
|
|
316
|
-
and uses [CssMinimizerWebpackPlugin](https://webpack.js.org/plugins/css-minimizer-webpack-plugin)
|
|
317
|
-
to minify CSS bundles.
|
|
318
|
-
|
|
319
|
-
To override the default Terser options set `cli.webpack.minify.js` to an object containing
|
|
320
|
-
[`terserOptions`](https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptions).
|
|
321
|
-
To override the default CssMinimizerWebpackPlugin options, set `cli.webpack.minify.css` to an object containing
|
|
322
|
-
[CssMinimizerWebpackPlugin options](https://webpack.js.org/plugins/css-minimizer-webpack-plugin/#options).
|
|
323
|
-
E.g.,
|
|
324
|
-
|
|
325
|
-
```json title="package.json"
|
|
326
|
-
{
|
|
327
|
-
"cli": {
|
|
328
|
-
"webpack": {
|
|
329
|
-
"minify": {
|
|
330
|
-
"js": {
|
|
331
|
-
// terser-webpack-plugin terserOptions
|
|
332
|
-
},
|
|
333
|
-
"css": {
|
|
334
|
-
// css-minimizer-webpack-plugin options
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
##### Application Port
|
|
343
|
-
|
|
344
|
-
Use `cli.webpack.port` to set the port that `webpack-dev-server` uses for the application. E.g.,
|
|
345
|
-
|
|
346
|
-
```json title="package.json"
|
|
347
|
-
{
|
|
348
|
-
"cli": {
|
|
349
|
-
"webpack": {
|
|
350
|
-
"port": 8888
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
##### webpack-dev-server
|
|
357
|
-
|
|
358
|
-
Use `cli.webpack.devServer` to set or override `webpack-dev-server` options. E.g.,
|
|
359
|
-
|
|
360
|
-
```json title="package.json"
|
|
361
|
-
{
|
|
362
|
-
"cli": {
|
|
363
|
-
"webpack": {
|
|
364
|
-
"devServer": {
|
|
365
|
-
// webpack-dev-server options (https://webpack.js.org/configuration/dev-server/#devserver)
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
`webpack.devServer` can also be set to `false` in order to disable `webpack-dev-server` altogether.
|
|
373
|
-
|
|
374
|
-
#### Webpack Configuration
|
|
375
|
-
|
|
376
|
-
If you need to add additional rules or change the build output path or make any other customization of the Webpack configuration, you should create `webpack.{env}.config.js` files in the package's root folder. These files should call `createWebpackConfig` with the required configuration.
|
|
377
|
-
|
|
378
|
-
##### createWebpackConfig
|
|
379
|
-
|
|
380
|
-
Accepts an object with two fields: `configuration` and `plugins` with configuration overrides for Webpack and its plugins, and returns the Webpack configuration for the provided `configuration.mode` with applied overrides.
|
|
381
|
-
Currently `plugins` only supports `HtmlWebpackPlugin` and `MiniCssExtractPlugin`, and `MiniCssExtractPlugin` can only be overridden in production builds.
|
|
382
|
-
|
|
383
|
-
```js title="webpack.dev.config.js"
|
|
384
|
-
const path = require('path');
|
|
385
|
-
|
|
386
|
-
const { createWebpackConfig } = require('@servicetitan/startup');
|
|
387
|
-
|
|
388
|
-
module.exports = createWebpackConfig({
|
|
389
|
-
configuration: {
|
|
390
|
-
mode: 'development',
|
|
391
|
-
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
```js title="webpack.prod.config.js"
|
|
397
|
-
const path = require('path');
|
|
398
|
-
|
|
399
|
-
const { createWebpackConfig } = require('@servicetitan/startup');
|
|
400
|
-
|
|
401
|
-
module.exports = createWebpackConfig({
|
|
402
|
-
configuration: {
|
|
403
|
-
mode: 'production',
|
|
404
|
-
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
##### MFE webpack config
|
|
410
|
-
|
|
411
|
-
Since `v22.7.0` providing custom webpack configuration for MFEs is also supported. However, there is a caveat. You can't use the `createWebpackConfig` to create the configuration as MFEs exist in two variants: a full build (includes all dependencies of MFE) and a light build (has shared dependencies with the host app and does not bundle these deps). See the [discussion here](https://github.com/servicetitan/uikit/pull/1721#discussion_r1183007790) for more info. Below are examples of MFE webpack configs. These objects are then internally passed to `createWebpackConfig` (so the same limitation applies meaning only a few `plugins` can be specified in the config file, see the previous section on `createWebpackConfig`).
|
|
412
|
-
|
|
413
|
-
```js title="webpack.dev.config.js"
|
|
414
|
-
const path = require('path');
|
|
415
|
-
|
|
416
|
-
module.exports = {
|
|
417
|
-
configuration: {
|
|
418
|
-
mode: 'development',
|
|
419
|
-
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
420
|
-
},
|
|
421
|
-
plugins: [...]
|
|
422
|
-
};
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
```js title="webpack.prod.config.js"
|
|
426
|
-
const path = require('path');
|
|
427
|
-
|
|
428
|
-
module.exports = {
|
|
429
|
-
configuration: {
|
|
430
|
-
mode: 'production',
|
|
431
|
-
output: { path: path.resolve(__dirname, '../../wwwroot') },
|
|
432
|
-
},
|
|
433
|
-
plugins: [...]
|
|
434
|
-
};
|
|
435
|
-
```
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Jest
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
`Startup test` uses the Jest by default, with a built-in configuration optimized for ServiceTitan workspaces.
|
|
6
|
+
|
|
7
|
+
## Configuration
|
|
8
|
+
|
|
9
|
+
You can override the defaults by specifying [Jest options](https://jestjs.io/docs/configuration) in your workspace `package.json` under the `"cli.jest"` key (the `"cli.test"` key also works, for backward compatibility). For example,
|
|
10
|
+
|
|
11
|
+
```json title="package.json"
|
|
12
|
+
{
|
|
13
|
+
"cli": {
|
|
14
|
+
"jest": {
|
|
15
|
+
// Jest options (https://jestjs.io/docs/next/configuration)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You can also use a standard Jest config file (such as `jest.config.js`) or pass options directly via the command line (e.g., `npx startup test --coverage`).
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
### Package.json
|
|
26
|
+
|
|
27
|
+
Use the workspace `package.json` to set up code that runs before each test file is executed:
|
|
28
|
+
|
|
29
|
+
```json title="package.json"
|
|
30
|
+
{
|
|
31
|
+
"cli": {
|
|
32
|
+
"jest": {
|
|
33
|
+
"setupFilesAfterEnv": ["<rootDir>/jest.setup.ts"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
:::note
|
|
40
|
+
For backward compatibility, you may also use the `ci.test` key:
|
|
41
|
+
:::
|
|
42
|
+
|
|
43
|
+
### Config file
|
|
44
|
+
|
|
45
|
+
Use `jest.config.js` to increase Jest's `testTimeout` on Windows:
|
|
46
|
+
|
|
47
|
+
```js title="jest.config.js"
|
|
48
|
+
module.exports = {
|
|
49
|
+
testTimeout: process.platform === 'win32' ? 60 * 1000 : undefined, // increase timeout on Windows
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
:::caution
|
|
54
|
+
If your project includes a standard Jest config file and also specifies Jest options in the workspace `package.json`, ensure that the configurations are mutually exclusive.
|
|
55
|
+
To avoid confusing or unexpected behavior, do not specify the same setting in both locations.
|
|
56
|
+
:::
|
|
57
|
+
|
|
58
|
+
#### Overriding defaults
|
|
59
|
+
|
|
60
|
+
✨ New in **v32.2.0** ✨
|
|
61
|
+
|
|
62
|
+
Because Jest gives `startup`'s built-in defaults higher precedence than its config files, `startup` allows you to selectively omit built-in defaults so that they don't interfere.
|
|
63
|
+
|
|
64
|
+
Set `cli.jest.omitDefault` to a list of options to omit from `startup`s built-in configuration.
|
|
65
|
+
|
|
66
|
+
For example, to configure `transformIgnorePatterns` in `jest.config.js` omit it from `startup`'s defaults,
|
|
67
|
+
|
|
68
|
+
```json title="package.json"
|
|
69
|
+
{
|
|
70
|
+
"cli": {
|
|
71
|
+
"jest": {
|
|
72
|
+
"omitDefault": ["transformIgnorePatterns"]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
And export it from the Jest config,
|
|
79
|
+
|
|
80
|
+
```js title="jest.config.js"
|
|
81
|
+
const esmPackages = [
|
|
82
|
+
'@servicetitan',
|
|
83
|
+
'@react-hook',
|
|
84
|
+
'nanoid',
|
|
85
|
+
'axios',
|
|
86
|
+
'cpx2',
|
|
87
|
+
'p-map',
|
|
88
|
+
'terminal-link',
|
|
89
|
+
'ansi-escapes',
|
|
90
|
+
'environment',
|
|
91
|
+
'until-async',
|
|
92
|
+
'supports-hyperlinks',
|
|
93
|
+
'supports-color',
|
|
94
|
+
'has-flag',
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
module.exports = {
|
|
98
|
+
transformIgnorePatterns: [`node_modules/(?!(${esmPackages.join('|')})/)`],
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Command line
|
|
103
|
+
|
|
104
|
+
Use the command line to collect test coverage:
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
npx startup test --coverage
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Use the command line to enable Jest's watch mode:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
npx startup test --watch
|
|
114
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: test
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Runs your project's tests.
|
|
6
|
+
|
|
7
|
+
- Supports both Jest and Vitest.
|
|
8
|
+
- Automatically selects the test runner based on your workspace configuration or the `--runner` option.
|
|
9
|
+
- Handles runner-specific arguments and passes them through to the underlying test tool.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Run all tests with Jest (default):
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx startup test
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Run all tests with Vitest:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npx startup test --runner vitest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
:::tip
|
|
26
|
+
Use the double-dash (--) separator to pass arguments to an `npm` script.
|
|
27
|
+
This separator indicates that any arguments following it should be passed directly to the script being executed, rather than being interpreted by `npm` itself.
|
|
28
|
+
For example, given the standard `startup test` script:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"test": "npx startup test"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Running,
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npm run test -- --runner vitest
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Executes,
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npx startup test --runner vitest
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
:::
|
|
49
|
+
|
|
50
|
+
## Running Specific Tests
|
|
51
|
+
|
|
52
|
+
To run specific tests, pass their file names or paths as additional arguments.
|
|
53
|
+
This works just like running Jest and Vitest directly, simply specify the file(s) you want to test:
|
|
54
|
+
|
|
55
|
+
### Examples
|
|
56
|
+
|
|
57
|
+
Run a specific test with Jest (default):
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npx startup test app.test.tsx
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Run a specific test with Vitest:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npx startup test --runner vitest app.test.tsx
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Configuration
|
|
70
|
+
|
|
71
|
+
- [Jest](./jest)
|
|
72
|
+
- [Vitest](./vitest)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Vitest
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
✨ New in **v31.6.0** ✨
|
|
6
|
+
|
|
7
|
+
You can change the default test runner from `jest` to `vitest` in your workspace's `package.json`:
|
|
8
|
+
|
|
9
|
+
```json title="package.json"
|
|
10
|
+
{
|
|
11
|
+
"cli": {
|
|
12
|
+
"testRunner": "vitest"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or, you can override it per invocation with the `--runner` option.
|
|
18
|
+
|
|
19
|
+
## Configuration
|
|
20
|
+
|
|
21
|
+
The Vitest runner uses a layered configuration approach to provide sensible defaults while allowing full customization.
|
|
22
|
+
|
|
23
|
+
- Uses the default, built-in configuration as a base.
|
|
24
|
+
- Merges workspace settings from `package.json`.
|
|
25
|
+
- Merges settings from your Vitest config file.
|
|
26
|
+
- Merges command line options last.
|
|
27
|
+
|
|
28
|
+
1. **Default Configuration:**
|
|
29
|
+
The runner starts with a built-in default configuration optimized for ServiceTitan workspaces. This includes sensible coverage settings, the environment (`jsdom`), file exclusions, and more.
|
|
30
|
+
|
|
31
|
+
2. **Workspace Configuration:**
|
|
32
|
+
You can customize the configuration by specifying [Vitest options](https://vitest.dev/config) in your workspace `package.json` under the `"cli.vitest"` key.
|
|
33
|
+
|
|
34
|
+
3. **Vitest Config File:**
|
|
35
|
+
If your project includes a standard Vitest config file (such as `vitest.config.ts` or `vite.config.ts`), its settings will merged with the defaults and workspace configuration.
|
|
36
|
+
|
|
37
|
+
4. **Command Line Arguments:**
|
|
38
|
+
Any options passed directly via the command line (e.g., `npx startup test --runner vitest --coverage`) take highest precedence over previous configuration layers.
|
|
39
|
+
|
|
40
|
+
## Examples
|
|
41
|
+
|
|
42
|
+
### Package.json
|
|
43
|
+
|
|
44
|
+
Use workspace `package.json` to make `vitest` APIs available [globally](https://vitest.dev/config/#globals) like Jest:
|
|
45
|
+
|
|
46
|
+
```json title="package.json"
|
|
47
|
+
{
|
|
48
|
+
"cli": {
|
|
49
|
+
"vitest": {
|
|
50
|
+
"globals": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Config file
|
|
57
|
+
|
|
58
|
+
Use `vitest.config.mts` to disable watch mode:
|
|
59
|
+
|
|
60
|
+
```ts title="vitest.config.mts"
|
|
61
|
+
import { defineConfig } from 'vitest/config';
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
test: {
|
|
65
|
+
watch: false,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Overriding defaults
|
|
71
|
+
|
|
72
|
+
✨ New in **v32.2.0** ✨
|
|
73
|
+
|
|
74
|
+
Because Vitest merges `startup`'s built-in defaults with its config files,
|
|
75
|
+
`startup` allows you to selectively omit built-in defaults so that they don't interfere.
|
|
76
|
+
|
|
77
|
+
Set `cli.vitest.omitDefault` to a list of options to omit from `startup`'s built-in configuration.
|
|
78
|
+
|
|
79
|
+
For example, to completely customize `coverage.include`, omit it from `startup`s defaults:
|
|
80
|
+
|
|
81
|
+
```json title="package.json"
|
|
82
|
+
{
|
|
83
|
+
"cli": {
|
|
84
|
+
"vitest": {
|
|
85
|
+
"omitDefault": ["coverage.include"]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
And export it from the Vitest config,
|
|
92
|
+
|
|
93
|
+
```js title="vitest.config.mts"
|
|
94
|
+
import { defineConfig } from 'vitest/config';
|
|
95
|
+
|
|
96
|
+
export default defineConfig({
|
|
97
|
+
test: {
|
|
98
|
+
coverage: {
|
|
99
|
+
include: ['apps/*/src/**', 'libraries/*/src/**'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Command line
|
|
106
|
+
|
|
107
|
+
Use the command line to disable watch mode:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
npx startup test --runner vitest --run
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Use the command line to collect code coverage:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
npx startup test --runner vitest --coverage
|
|
117
|
+
```
|