@servicetitan/startup 31.5.0 → 31.6.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.
Files changed (143) hide show
  1. package/dist/cli/commands/build.d.ts +1 -1
  2. package/dist/cli/commands/build.d.ts.map +1 -1
  3. package/dist/cli/commands/build.js.map +1 -1
  4. package/dist/cli/commands/bundle-package.d.ts +1 -1
  5. package/dist/cli/commands/bundle-package.d.ts.map +1 -1
  6. package/dist/cli/commands/bundle-package.js.map +1 -1
  7. package/dist/cli/commands/eslint.d.ts +1 -1
  8. package/dist/cli/commands/eslint.d.ts.map +1 -1
  9. package/dist/cli/commands/eslint.js.map +1 -1
  10. package/dist/cli/commands/get-command.js +2 -2
  11. package/dist/cli/commands/get-command.js.map +1 -1
  12. package/dist/cli/commands/index.d.ts +1 -1
  13. package/dist/cli/commands/index.d.ts.map +1 -1
  14. package/dist/cli/commands/index.js +1 -1
  15. package/dist/cli/commands/index.js.map +1 -1
  16. package/dist/cli/commands/init.d.ts +1 -1
  17. package/dist/cli/commands/init.d.ts.map +1 -1
  18. package/dist/cli/commands/init.js.map +1 -1
  19. package/dist/cli/commands/lint.d.ts +1 -1
  20. package/dist/cli/commands/lint.d.ts.map +1 -1
  21. package/dist/cli/commands/lint.js.map +1 -1
  22. package/dist/cli/commands/mfe-publish.d.ts +1 -1
  23. package/dist/cli/commands/mfe-publish.d.ts.map +1 -1
  24. package/dist/cli/commands/mfe-publish.js.map +1 -1
  25. package/dist/cli/commands/prepare-package.d.ts +1 -1
  26. package/dist/cli/commands/prepare-package.d.ts.map +1 -1
  27. package/dist/cli/commands/prepare-package.js.map +1 -1
  28. package/dist/cli/commands/review/rules/index.d.ts.map +1 -1
  29. package/dist/cli/commands/review/rules/index.js +4 -0
  30. package/dist/cli/commands/review/rules/index.js.map +1 -1
  31. package/dist/cli/commands/review/rules/require-all-react-dependencies.d.ts +14 -0
  32. package/dist/cli/commands/review/rules/require-all-react-dependencies.d.ts.map +1 -0
  33. package/dist/cli/commands/review/rules/require-all-react-dependencies.js +64 -0
  34. package/dist/cli/commands/review/rules/require-all-react-dependencies.js.map +1 -0
  35. package/dist/cli/commands/review/rules/require-one-react-version.d.ts +5 -0
  36. package/dist/cli/commands/review/rules/require-one-react-version.d.ts.map +1 -0
  37. package/dist/cli/commands/review/rules/require-one-react-version.js +25 -0
  38. package/dist/cli/commands/review/rules/require-one-react-version.js.map +1 -0
  39. package/dist/cli/commands/review/rules/require-one-uikit-version.d.ts.map +1 -1
  40. package/dist/cli/commands/review/rules/require-one-uikit-version.js +1 -0
  41. package/dist/cli/commands/review/rules/require-one-uikit-version.js.map +1 -1
  42. package/dist/cli/commands/review/utils/format-depends-on.d.ts +1 -0
  43. package/dist/cli/commands/review/utils/format-depends-on.d.ts.map +1 -1
  44. package/dist/cli/commands/review/utils/format-depends-on.js +15 -8
  45. package/dist/cli/commands/review/utils/format-depends-on.js.map +1 -1
  46. package/dist/cli/commands/review/utils/set-version.d.ts +2 -1
  47. package/dist/cli/commands/review/utils/set-version.d.ts.map +1 -1
  48. package/dist/cli/commands/review/utils/set-version.js +4 -2
  49. package/dist/cli/commands/review/utils/set-version.js.map +1 -1
  50. package/dist/cli/commands/start.d.ts +1 -1
  51. package/dist/cli/commands/start.d.ts.map +1 -1
  52. package/dist/cli/commands/start.js.map +1 -1
  53. package/dist/cli/commands/test/index.d.ts +2 -0
  54. package/dist/cli/commands/test/index.d.ts.map +1 -0
  55. package/dist/cli/commands/test/index.js +20 -0
  56. package/dist/cli/commands/test/index.js.map +1 -0
  57. package/dist/cli/commands/test/runners/index.d.ts +3 -0
  58. package/dist/cli/commands/test/runners/index.d.ts.map +1 -0
  59. package/dist/cli/commands/test/runners/index.js +21 -0
  60. package/dist/cli/commands/test/runners/index.js.map +1 -0
  61. package/dist/cli/commands/test/runners/jest.d.ts +7 -0
  62. package/dist/cli/commands/test/runners/jest.d.ts.map +1 -0
  63. package/dist/cli/commands/test/runners/jest.js +43 -0
  64. package/dist/cli/commands/test/runners/jest.js.map +1 -0
  65. package/dist/cli/commands/test/runners/vitest.d.ts +4 -0
  66. package/dist/cli/commands/test/runners/vitest.d.ts.map +1 -0
  67. package/dist/cli/commands/test/runners/vitest.js +86 -0
  68. package/dist/cli/commands/test/runners/vitest.js.map +1 -0
  69. package/dist/cli/commands/test/tests.d.ts +18 -0
  70. package/dist/cli/commands/test/tests.d.ts.map +1 -0
  71. package/dist/cli/commands/{tests.js → test/tests.js} +10 -9
  72. package/dist/cli/commands/test/tests.js.map +1 -0
  73. package/dist/cli/utils/bundle.d.ts.map +1 -1
  74. package/dist/cli/utils/bundle.js +7 -4
  75. package/dist/cli/utils/bundle.js.map +1 -1
  76. package/dist/cli/utils/set-node-options.d.ts.map +1 -1
  77. package/dist/cli/utils/set-node-options.js.map +1 -1
  78. package/dist/index.d.ts +0 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +0 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/utils/get-configuration.d.ts +8 -2
  83. package/dist/utils/get-configuration.d.ts.map +1 -1
  84. package/dist/utils/get-configuration.js +10 -2
  85. package/dist/utils/get-configuration.js.map +1 -1
  86. package/dist/utils/get-jest-config.d.ts +1 -7
  87. package/dist/utils/get-jest-config.d.ts.map +1 -1
  88. package/dist/utils/get-jest-config.js +49 -58
  89. package/dist/utils/get-jest-config.js.map +1 -1
  90. package/dist/webpack/create-webpack-config.js +1 -2
  91. package/dist/webpack/create-webpack-config.js.map +1 -1
  92. package/dist/webpack/utils/testing/get-compiler.js.map +1 -1
  93. package/package.json +16 -14
  94. package/src/cli/commands/build.ts +1 -1
  95. package/src/cli/commands/bundle-package.ts +1 -1
  96. package/src/cli/commands/eslint.ts +1 -1
  97. package/src/cli/commands/get-command.ts +1 -1
  98. package/src/cli/commands/index.ts +1 -1
  99. package/src/cli/commands/init.ts +1 -1
  100. package/src/cli/commands/lint.ts +1 -1
  101. package/src/cli/commands/mfe-publish.ts +1 -1
  102. package/src/cli/commands/prepare-package.ts +1 -1
  103. package/src/cli/commands/review/rules/__tests__/require-all-react-dependencies.test.ts +132 -0
  104. package/src/cli/commands/review/rules/__tests__/require-one-package-version.test.ts +0 -1
  105. package/src/cli/commands/review/rules/__tests__/require-one-react-version.test.ts +22 -0
  106. package/src/cli/commands/review/rules/__tests__/{require-one-uikit-version.ts → require-one-uikit-version.test.ts} +1 -0
  107. package/src/cli/commands/review/rules/index.ts +4 -0
  108. package/src/cli/commands/review/rules/require-all-react-dependencies.ts +53 -0
  109. package/src/cli/commands/review/rules/require-one-react-version.ts +9 -0
  110. package/src/cli/commands/review/rules/require-one-uikit-version.ts +1 -0
  111. package/src/cli/commands/review/utils/__tests__/set-version.test.ts +18 -8
  112. package/src/cli/commands/review/utils/format-depends-on.ts +8 -5
  113. package/src/cli/commands/review/utils/set-version.ts +10 -2
  114. package/src/cli/commands/start.ts +1 -1
  115. package/src/cli/commands/test/__tests__/tests.test.ts +78 -0
  116. package/src/cli/commands/test/index.ts +1 -0
  117. package/src/cli/commands/{__tests__/tests.test.ts → test/runners/__tests__/jest.test.ts} +10 -13
  118. package/src/cli/commands/test/runners/__tests__/vitest.test.ts +150 -0
  119. package/src/cli/commands/test/runners/index.ts +2 -0
  120. package/src/cli/commands/{tests.ts → test/runners/jest.ts} +5 -16
  121. package/src/cli/commands/test/runners/vitest.ts +70 -0
  122. package/src/cli/commands/test/tests.ts +34 -0
  123. package/src/cli/utils/__tests__/bundle.test.ts +1 -1
  124. package/src/cli/utils/bundle.ts +8 -3
  125. package/src/cli/utils/set-node-options.ts +2 -2
  126. package/src/index.ts +0 -1
  127. package/src/utils/__tests__/get-configuration.test.ts +48 -11
  128. package/src/utils/__tests__/get-jest-config.test.ts +35 -61
  129. package/src/utils/get-configuration.ts +14 -3
  130. package/src/utils/get-jest-config.ts +39 -47
  131. package/src/webpack/__tests__/create-webpack-config-shared-dependencies.test.ts +1 -1
  132. package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +1 -1
  133. package/src/webpack/__tests__/create-webpack-config.test.ts +1 -1
  134. package/src/webpack/create-webpack-config.ts +1 -2
  135. package/src/webpack/utils/testing/get-compiler.ts +1 -1
  136. package/dist/cli/commands/tests.d.ts +0 -13
  137. package/dist/cli/commands/tests.d.ts.map +0 -1
  138. package/dist/cli/commands/tests.js.map +0 -1
  139. package/dist/jest/index.d.ts +0 -2
  140. package/dist/jest/index.d.ts.map +0 -1
  141. package/dist/jest/index.js +0 -16
  142. package/dist/jest/index.js.map +0 -1
  143. package/src/jest/index.ts +0 -5
@@ -1,22 +1,11 @@
1
- import { Config } from '@jest/types';
2
1
  import { runCLI } from '@jest/core';
3
- import { getJestConfigCLI, logErrors } from '../../utils';
4
- import { Command } from '.';
5
-
6
- /**
7
- * Named as tests to exclude it from the Jest pattern
8
- */
9
- export class Tests implements Command {
10
- readonly greedy = true;
11
-
12
- constructor(private args: Config.Argv) {}
2
+ import { Config } from '@jest/types';
3
+ import { getJestConfigCLI } from '../../../../utils';
13
4
 
14
- description() {
15
- return 'run tests';
16
- }
5
+ export class Jest {
6
+ constructor(private readonly args: Config.Argv) {}
17
7
 
18
- @logErrors
19
- async execute() {
8
+ async run() {
20
9
  const jestConfig = getJestConfigCLI(this.args);
21
10
  const {
22
11
  results: { success },
@@ -0,0 +1,70 @@
1
+ import { configDefaults, coverageConfigDefaults, mergeConfig, ViteUserConfig } from 'vitest/config';
2
+ import { startVitest, parseCLI, resolveConfig } from 'vitest/node';
3
+ import { getVitestConfiguration, log } from '../../../../utils';
4
+
5
+ type VitestConfig = NonNullable<ViteUserConfig['test']>;
6
+
7
+ export class Vitest {
8
+ async run() {
9
+ const cliOptions = getCliOptions();
10
+ const userConfig = await getUserConfig();
11
+
12
+ // startVitest sets process.exitCode to 1 when tests fail
13
+ const vitest = await startVitest('test', cliOptions.filter, cliOptions.options, userConfig);
14
+ await vitest.close();
15
+ }
16
+ }
17
+
18
+ const RUNNER_OPTION = '--runner';
19
+
20
+ function excludeRunnerOption(args: string[]) {
21
+ return args.reduce<string[]>((result, item, index) => {
22
+ if (!item.startsWith(RUNNER_OPTION) && (index === 0 || args[index - 1] !== RUNNER_OPTION)) {
23
+ result.push(item);
24
+ }
25
+ return result;
26
+ }, []);
27
+ }
28
+
29
+ function getCliOptions() {
30
+ // parseCLI requires the first element to be "vitest"
31
+ const result = parseCLI(['vitest', ...excludeRunnerOption(process.argv.slice(3))]);
32
+
33
+ /* istanbul ignore next: debug only */
34
+ log.debug('vitest:cliOptions', () => JSON.stringify(result, null, 2));
35
+
36
+ return result;
37
+ }
38
+
39
+ function getDefaultConfig(): VitestConfig {
40
+ return {
41
+ coverage: {
42
+ exclude: [
43
+ ...coverageConfigDefaults.exclude,
44
+ '**/__mocks__/**',
45
+ '**/*.stories.*',
46
+ '\\.yalc',
47
+ ],
48
+ include: ['**/*.{ts,tsx}'],
49
+ reporter: ['html-spa', 'text', 'json', 'cobertura', 'lcov'],
50
+ },
51
+ environment: 'jsdom',
52
+ exclude: [...configDefaults.exclude, '\\.yalc'],
53
+ restoreMocks: true,
54
+ server: { deps: { inline: ['@servicetitan/anvil2'] } }, // fixes css parser errors
55
+ };
56
+ }
57
+
58
+ async function getUserConfig(): Promise<ViteUserConfig> {
59
+ const { viteConfig } = await resolveConfig();
60
+
61
+ const result = mergeConfig(
62
+ mergeConfig(getDefaultConfig(), getVitestConfiguration()),
63
+ viteConfig.test ?? {}
64
+ );
65
+
66
+ /* istanbul ignore next: debug only */
67
+ log.debug('vitest:userConfig', () => JSON.stringify(result, null, 2));
68
+
69
+ return { test: result };
70
+ }
@@ -0,0 +1,34 @@
1
+ import { Config } from '@jest/types';
2
+ import { getConfiguration, logErrors } from '../../../utils';
3
+ import { Command } from '../types';
4
+ import { Jest, Vitest } from './runners';
5
+
6
+ type Args = Config.Argv & {
7
+ runner?: 'jest' | 'vitest';
8
+ };
9
+
10
+ /**
11
+ * This class is named "Tests" instead of "Test" because the corresponding
12
+ * "test.ts" would be interpreted as a test file.
13
+ */
14
+ export class Tests implements Command {
15
+ readonly greedy = true;
16
+
17
+ constructor(private readonly args: Args) {}
18
+
19
+ description() {
20
+ return 'run tests';
21
+ }
22
+
23
+ @logErrors
24
+ async execute() {
25
+ const { runner = getConfiguration().testRunner ?? 'jest', ...restArgs } = this.args;
26
+ if (runner === 'jest') {
27
+ await new Jest(restArgs).run();
28
+ } else if (runner === 'vitest') {
29
+ await new Vitest().run();
30
+ } else {
31
+ throw new Error(`unrecognized runner "${runner}"`);
32
+ }
33
+ }
34
+ }
@@ -34,7 +34,7 @@ jest.mock('../../../webpack', () => ({ createWebpackConfig: jest.fn() }));
34
34
  describe('[startup] Cli Utils', () => {
35
35
  const pkg = createPackage({});
36
36
  const createWebpackResult = { stats: { all: true } };
37
- let compiler: Partial<ReturnType<typeof webpack>>;
37
+ let compiler: Partial<NonNullable<ReturnType<typeof webpack>>>;
38
38
 
39
39
  beforeEach(() => {
40
40
  jest.resetAllMocks();
@@ -57,6 +57,7 @@ export async function bundle(options: Options = {}) {
57
57
  const customConfig = readWebpackConfig({ ...options, fallback });
58
58
  const webpackOptions = getWebpackOptions(options, customConfig);
59
59
 
60
+ /* istanbul ignore next: debug only */
60
61
  log.debug('custom-webpack-config', () => stringifyConfig(customConfig));
61
62
 
62
63
  if (isWebComponent()) {
@@ -135,7 +136,7 @@ function readConfig(relativePath?: string): Record<string, any> | undefined {
135
136
  }
136
137
 
137
138
  async function run(config: Configuration) {
138
- const compiler = webpack(config);
139
+ const compiler = createWebpackCompiler(config);
139
140
 
140
141
  const stats = await new Promise<webpack.Stats>((resolve, reject) => {
141
142
  compiler.run((error, stats) => {
@@ -155,7 +156,7 @@ async function run(config: Configuration) {
155
156
  }
156
157
 
157
158
  async function runServe({ devServer = {}, ...config }: Configuration) {
158
- const compiler = webpack(config);
159
+ const compiler = createWebpackCompiler(config);
159
160
  const host = devServer.host ?? 'localhost';
160
161
  const port = await getPortPromise({
161
162
  port: Number(devServer.port) || 8080,
@@ -175,7 +176,7 @@ async function runServe({ devServer = {}, ...config }: Configuration) {
175
176
  }
176
177
 
177
178
  async function runWatch(config: Configuration) {
178
- const compiler = webpack(config);
179
+ const compiler = createWebpackCompiler(config);
179
180
  return new Promise<void>((_0, reject) => {
180
181
  const watching = compiler.watch({}, e => {
181
182
  if (e) {
@@ -186,3 +187,7 @@ async function runWatch(config: Configuration) {
186
187
  });
187
188
  });
188
189
  }
190
+
191
+ function createWebpackCompiler(config: Configuration) {
192
+ return webpack(config)!; // webpack only potentially returns null when given a callback argument
193
+ }
@@ -1,5 +1,5 @@
1
1
  import os from 'os';
2
- import { CommandName, NodeConfiguration, getConfigurationSafe } from '../../utils';
2
+ import { CommandName, getConfigurationSafe } from '../../utils';
3
3
  import { Command } from '../commands';
4
4
 
5
5
  const MAX_OLD_SPACE_SIZE_OPTION = 'max_old_space_size';
@@ -13,7 +13,7 @@ const MIN_REMAINING_MEMORY_MB = 512;
13
13
  */
14
14
  export function setNodeOptions(commandName: CommandName, command: Command) {
15
15
  const cliConfig = getConfigurationSafe();
16
- const cmdConfig: NodeConfiguration = cliConfig[commandName];
16
+ const cmdConfig = cliConfig[commandName];
17
17
 
18
18
  const cliNodeOptions = cliConfig.NODE_OPTIONS ?? [];
19
19
  const cmdNodeOptions = cmdConfig?.NODE_OPTIONS ?? [];
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './webpack';
2
- export * from './jest';
3
2
  export * from './utils/get-packages';
@@ -8,6 +8,7 @@ import {
8
8
  getJestConfiguration,
9
9
  getReviewConfiguration,
10
10
  getStylelintConfiguration,
11
+ getVitestConfiguration,
11
12
  getWebComponentBranchConfigs,
12
13
  getWebComponentConfiguration,
13
14
  hasHeadlessBundle,
@@ -43,8 +44,8 @@ describe('[startup] Utils', () => {
43
44
 
44
45
  afterEach(() => jest.resetAllMocks());
45
46
 
46
- describe(`${getConfiguration.name}`, () => {
47
- let locationOrJson: string | Record<string, any> | undefined;
47
+ describe(getConfiguration.name, () => {
48
+ let locationOrJson: Parameters<typeof getConfiguration>[0];
48
49
 
49
50
  beforeEach(() => (locationOrJson = undefined));
50
51
 
@@ -94,7 +95,7 @@ describe('[startup] Utils', () => {
94
95
  });
95
96
  });
96
97
 
97
- describe(`${getConfigurationSafe.name}`, () => {
98
+ describe(getConfigurationSafe.name, () => {
98
99
  let locationOrJson: string | Record<string, any> | undefined;
99
100
 
100
101
  beforeEach(() => (locationOrJson = undefined));
@@ -141,7 +142,7 @@ describe('[startup] Utils', () => {
141
142
  });
142
143
  });
143
144
 
144
- describe(`${getESLintConfiguration.name}`, () => {
145
+ describe(getESLintConfiguration.name, () => {
145
146
  const subject = () => getESLintConfiguration();
146
147
 
147
148
  itReturns(subject, {});
@@ -157,7 +158,7 @@ describe('[startup] Utils', () => {
157
158
  });
158
159
  });
159
160
 
160
- describe(`${getJestConfiguration.name}`, () => {
161
+ describe(getJestConfiguration.name, () => {
161
162
  const subject = () => getJestConfiguration();
162
163
 
163
164
  itReturns(subject, {});
@@ -171,9 +172,29 @@ describe('[startup] Utils', () => {
171
172
  expect(subject()).toEqual(content.cli.test);
172
173
  });
173
174
  });
175
+
176
+ describe('with "cli.jest"', () => {
177
+ const content = { cli: { jest: { baz: 'qux' } } };
178
+
179
+ beforeEach(() => mockPackageJson(content));
180
+
181
+ test('returns "cli.jest"', () => {
182
+ expect(subject()).toEqual(content.cli.jest);
183
+ });
184
+ });
185
+
186
+ describe('with both "cli.test" and "cli.jest"', () => {
187
+ const content = { cli: { test: { foo: 'bar' }, jest: { baz: 'qux' } } };
188
+
189
+ beforeEach(() => mockPackageJson(content));
190
+
191
+ test('returns "cli.jest"', () => {
192
+ expect(subject()).toEqual(content.cli.jest);
193
+ });
194
+ });
174
195
  });
175
196
 
176
- describe(`${getReviewConfiguration.name}`, () => {
197
+ describe(getReviewConfiguration.name, () => {
177
198
  const subject = () => getReviewConfiguration();
178
199
 
179
200
  itReturns(subject, {});
@@ -189,7 +210,7 @@ describe('[startup] Utils', () => {
189
210
  });
190
211
  });
191
212
 
192
- describe(`${getStylelintConfiguration.name}`, () => {
213
+ describe(getStylelintConfiguration.name, () => {
193
214
  const subject = () => getStylelintConfiguration();
194
215
 
195
216
  itReturns(subject, {});
@@ -205,7 +226,23 @@ describe('[startup] Utils', () => {
205
226
  });
206
227
  });
207
228
 
208
- describe(`${getWebComponentConfiguration.name}`, () => {
229
+ describe(getVitestConfiguration.name, () => {
230
+ const subject = () => getVitestConfiguration();
231
+
232
+ itReturns(subject, {});
233
+
234
+ describe('with "cli.vitest"', () => {
235
+ const content = { cli: { vitest: { foo: 'bar' } } };
236
+
237
+ beforeEach(() => mockPackageJson(content));
238
+
239
+ test('return "cli.vitest"', () => {
240
+ expect(subject()).toEqual(content.cli.vitest);
241
+ });
242
+ });
243
+ });
244
+
245
+ describe(getWebComponentConfiguration.name, () => {
209
246
  let locationOrJson: string | Record<string, any> | undefined;
210
247
 
211
248
  beforeEach(() => (locationOrJson = undefined));
@@ -317,7 +354,7 @@ describe('[startup] Utils', () => {
317
354
  });
318
355
  });
319
356
 
320
- describe(`${getWebComponentBranchConfigs.name}`, () => {
357
+ describe(getWebComponentBranchConfigs.name, () => {
321
358
  const subject = () => getWebComponentBranchConfigs();
322
359
 
323
360
  itReturns(subject, undefined);
@@ -333,7 +370,7 @@ describe('[startup] Utils', () => {
333
370
  });
334
371
  });
335
372
 
336
- describe(`${hasHeadlessBundle.name}`, () => {
373
+ describe(hasHeadlessBundle.name, () => {
337
374
  const subject = () => hasHeadlessBundle();
338
375
 
339
376
  itReturns(subject, false);
@@ -410,7 +447,7 @@ describe('[startup] Utils', () => {
410
447
  });
411
448
  });
412
449
 
413
- describe(`${isLegacy.name}`, () => {
450
+ describe(isLegacy.name, () => {
414
451
  const trigger = { cli: { legacy: true } };
415
452
  let location: string | undefined;
416
453
 
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import { getJestConfiguration } from '../get-configuration';
4
4
  import { getDestinationFolders } from '../get-destination-folders';
5
5
 
6
- import { getJestConfig, getJestConfigCLI } from '../get-jest-config';
6
+ import { getJestConfigCLI } from '../get-jest-config';
7
7
 
8
8
  jest.mock('../get-destination-folders');
9
9
  jest.mock('../get-configuration', () => ({
@@ -14,20 +14,21 @@ jest.mock('../get-configuration', () => ({
14
14
  describe('[startup] Utils', () => {
15
15
  const destinationFolders = ['dist'];
16
16
  const defaultConfig: Record<string, any> = {
17
- verbose: true,
18
- testEnvironment: 'jsdom',
19
- testRunner: 'jest-circus/runner',
20
- transformIgnorePatterns: ['node_modules/(?!(@servicetitan|@react-hook|nanoid|axios)/)'],
21
- modulePathIgnorePatterns: ['<rootDir>/.*/__mocks__'],
22
- moduleNameMapper: {
23
- '\\.(css|scss|less|png|svg|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$': 'identity-obj-proxy',
24
- },
25
- testPathIgnorePatterns: ['\\.yalc', ...destinationFolders],
26
- setupFiles: [expect.stringContaining(path.join('jest', 'setup.js'))],
17
+ collectCoverageFrom: ['**/*.{ts,tsx}'],
27
18
  coveragePathIgnorePatterns: ['^.+\\.d\\.ts$'],
28
19
  coverageReporters: ['html-spa', 'text', 'json', 'cobertura', 'lcov'],
29
- collectCoverageFrom: ['**/*.{ts,tsx}'],
20
+ moduleNameMapper: {
21
+ '\\.(css|scss|less|png|svg|svg\\?\\w+|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$':
22
+ 'identity-obj-proxy',
23
+ },
24
+ modulePathIgnorePatterns: ['<rootDir>/.*/__mocks__'],
30
25
  preset: expect.stringMatching(/startup[\\\/]+jest/),
26
+ setupFiles: [expect.stringContaining(path.join('jest', 'setup.js'))],
27
+ testEnvironment: 'jsdom',
28
+ testPathIgnorePatterns: ['\\.yalc', ...destinationFolders],
29
+ testRunner: 'jest-circus/runner',
30
+ transformIgnorePatterns: ['node_modules/(?!(@servicetitan|@react-hook|nanoid|axios)/)'],
31
+ verbose: true,
31
32
  };
32
33
 
33
34
  beforeEach(() => {
@@ -35,62 +36,15 @@ describe('[startup] Utils', () => {
35
36
  jest.mocked(getJestConfiguration).mockReturnValue({});
36
37
  });
37
38
 
38
- describe(`${getJestConfig.name}`, () => {
39
- const subject = () => getJestConfig();
40
-
41
- test('returns default config', () => {
42
- expect(subject()).toEqual(defaultConfig);
43
- });
44
-
45
- describe.each(['coveragePathIgnorePatterns', 'setupFiles', 'testPathIgnorePatterns'])(
46
- 'with custom "%s"',
47
- (
48
- option: keyof Pick<
49
- typeof defaultConfig,
50
- 'coveragePathIgnorePatterns' | 'setupFiles' | 'testPathIgnorePatterns'
51
- >
52
- ) => {
53
- const customValue = ['foo', 'bar'];
54
-
55
- beforeEach(() => {
56
- jest.mocked(getJestConfiguration).mockReturnValue({ [option]: customValue });
57
- });
58
-
59
- test(`appends custom value to "${option}"`, () => {
60
- expect(subject()).toEqual(
61
- expect.objectContaining({
62
- [option]: [...defaultConfig[option], ...customValue],
63
- })
64
- );
65
- });
66
- }
67
- );
68
-
69
- describe('with other custom options', () => {
70
- const customOptions = { resetMocks: true, testEnvironment: 'node' };
71
-
72
- beforeEach(() => jest.mocked(getJestConfiguration).mockReturnValue(customOptions));
73
-
74
- test('merges custom options with default config', () => {
75
- expect(subject()).toEqual({ ...defaultConfig, ...customOptions });
76
- });
77
- });
78
- });
79
-
80
39
  describe(`${getJestConfigCLI.name}`, () => {
81
40
  // eslint-disable-next-line @typescript-eslint/naming-convention
82
41
  const args: Config.Argv = { _: [], $0: '', runInBand: true };
83
- const globals = { foo: 'bar' };
84
42
 
85
43
  const subject = () => getJestConfigCLI(args);
86
44
 
87
- beforeEach(() => {
88
- jest.mocked(getJestConfiguration).mockReturnValue({ globals });
89
- });
90
-
91
- const stringified = ['collectCoverageFrom', 'moduleNameMapper', 'transform'].reduce(
45
+ const stringified = ['collectCoverageFrom', 'moduleNameMapper'].reduce(
92
46
  (result, key) => ({ ...result, [key]: JSON.stringify(defaultConfig[key]) }),
93
- { globals: JSON.stringify(globals) }
47
+ {}
94
48
  );
95
49
 
96
50
  test(`merges command line args with default config and stringifies "${Object.keys(
@@ -102,5 +56,25 @@ describe('[startup] Utils', () => {
102
56
  ...stringified,
103
57
  });
104
58
  });
59
+
60
+ test('stringifies globals config', () => {
61
+ const globals = { foo: 'bar' };
62
+
63
+ jest.mocked(getJestConfiguration).mockReturnValue({ globals });
64
+
65
+ expect(subject()).toEqual(
66
+ expect.objectContaining({ globals: JSON.stringify(globals) })
67
+ );
68
+ });
69
+
70
+ test('stringifies transform config', () => {
71
+ const transform = { '\\.css$': 'some-css-transformer' };
72
+
73
+ jest.mocked(getJestConfiguration).mockReturnValue({ transform });
74
+
75
+ expect(subject()).toEqual(
76
+ expect.objectContaining({ transform: JSON.stringify(transform) })
77
+ );
78
+ });
105
79
  });
106
80
  });
@@ -4,6 +4,7 @@ import { ESLint } from 'eslint';
4
4
  import fs from 'fs';
5
5
  import path from 'path';
6
6
  import { LinterOptions } from 'stylelint';
7
+ import { ViteUserConfig } from 'vitest/config';
7
8
  import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
8
9
 
9
10
  import { ReviewConfiguration } from '../cli/commands/review';
@@ -81,6 +82,8 @@ export enum CommandName {
81
82
  }
82
83
  /* eslint-enable @typescript-eslint/naming-convention */
83
84
 
85
+ export type VitestConfiguration = ViteUserConfig['test'];
86
+
84
87
  export interface WebComponentBranchConfigs {
85
88
  publishTag?: string;
86
89
  uploadSourcemaps?: boolean;
@@ -96,15 +99,18 @@ interface WebComponentOptions {
96
99
  }
97
100
 
98
101
  type Configuration = {
102
+ 'jest'?: JestConfiguration;
99
103
  'legacy'?: boolean;
100
104
  'lint'?: { eslint: ESLintConfiguration; stylelint: StylelintConfiguration };
101
105
  'review'?: ReviewConfiguration;
102
106
  'swc-compile-package'?: Parameters<typeof swcDir>[0];
103
- 'test'?: JestConfiguration;
107
+ 'test'?: JestConfiguration; // for backward-compatibility
108
+ 'testRunner'?: string;
109
+ 'vitest'?: VitestConfiguration;
104
110
  'web-component'?: boolean | string | WebComponentOptions;
105
111
  'webpack'?: false | WebpackConfiguration;
106
112
  } & {
107
- [key in CommandName]: NodeConfiguration;
113
+ [key in CommandName]?: NodeConfiguration;
108
114
  } & NodeConfiguration;
109
115
 
110
116
  type LocationOrJson = string | Record<string, any>;
@@ -130,7 +136,8 @@ export function getESLintConfiguration() {
130
136
  }
131
137
 
132
138
  export function getJestConfiguration() {
133
- return getConfiguration().test ?? {};
139
+ const configuration = getConfiguration();
140
+ return configuration.jest ?? configuration.test ?? {};
134
141
  }
135
142
 
136
143
  export function getReviewConfiguration() {
@@ -141,6 +148,10 @@ export function getStylelintConfiguration() {
141
148
  return getConfiguration().lint?.stylelint ?? {};
142
149
  }
143
150
 
151
+ export function getVitestConfiguration() {
152
+ return getConfiguration().vitest ?? {};
153
+ }
154
+
144
155
  export function getWebpackConfiguration(locationOrJson?: LocationOrJson) {
145
156
  const { webpack } = getConfiguration(locationOrJson);
146
157
  return typeof webpack === 'object' ? webpack : {};
@@ -1,10 +1,10 @@
1
- import path from 'path';
2
1
  import { Config } from '@jest/types';
3
- import { JestConfiguration, getJestConfiguration } from './get-configuration';
2
+ import path from 'path';
3
+ import { getJestConfiguration } from './get-configuration';
4
4
  import { getDestinationFolders } from './get-destination-folders';
5
5
  import { toArray } from './to-array';
6
6
 
7
- const getJestConfigBase = ({
7
+ function getDefaultJestConfiguration({
8
8
  coveragePathIgnorePatterns = [],
9
9
  setupFiles = [],
10
10
  testPathIgnorePatterns = [],
@@ -12,68 +12,60 @@ const getJestConfigBase = ({
12
12
  coveragePathIgnorePatterns?: string[];
13
13
  setupFiles?: string[];
14
14
  testPathIgnorePatterns?: string[];
15
- }) => {
15
+ }) {
16
16
  const moduleNameMapper = {
17
- '\\.(css|scss|less|png|svg|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$': 'identity-obj-proxy',
17
+ '\\.(css|scss|less|png|svg|svg\\?\\w+|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$':
18
+ 'identity-obj-proxy',
18
19
  };
19
20
 
20
21
  return {
21
- verbose: true,
22
- testEnvironment: 'jsdom',
23
- testRunner: 'jest-circus/runner',
24
- transformIgnorePatterns: ['node_modules/(?!(@servicetitan|@react-hook|nanoid|axios)/)'],
25
- modulePathIgnorePatterns: ['<rootDir>/.*/__mocks__'],
22
+ collectCoverageFrom: ['**/*.{ts,tsx}'],
23
+ coveragePathIgnorePatterns: ['^.+\\.d\\.ts$', ...coveragePathIgnorePatterns],
24
+ coverageReporters: ['html-spa', 'text', 'json', 'cobertura', 'lcov'],
26
25
  moduleNameMapper,
26
+ modulePathIgnorePatterns: ['<rootDir>/.*/__mocks__'],
27
+ preset: path.join(__dirname, '../../jest'),
28
+ setupFiles: [path.join(__dirname, '../../jest/setup.js'), ...toArray(setupFiles)],
29
+ testEnvironment: 'jsdom',
27
30
  testPathIgnorePatterns: [
28
31
  '\\.yalc',
29
32
  ...getDestinationFolders(),
30
33
  ...toArray(testPathIgnorePatterns),
31
34
  ],
32
- setupFiles: [path.join(__dirname, '../../jest/setup.js'), ...toArray(setupFiles)],
33
- coveragePathIgnorePatterns: ['^.+\\.d\\.ts$', ...coveragePathIgnorePatterns],
34
- coverageReporters: ['html-spa', 'text', 'json', 'cobertura', 'lcov'],
35
- collectCoverageFrom: ['**/*.{ts,tsx}'],
36
- preset: path.join(__dirname, '../../jest'),
37
- };
38
- };
39
-
40
- /**
41
- * Get Jest clean config for running tests. This config could be used to export Jest configuration into the
42
- * Jest config files.
43
- */
44
- export const getJestConfig = (): JestConfiguration => {
45
- const { coveragePathIgnorePatterns, setupFiles, testPathIgnorePatterns, ...config } =
46
- getJestConfiguration() as Record<string, any>;
47
- return {
48
- ...getJestConfigBase({
49
- coveragePathIgnorePatterns,
50
- setupFiles,
51
- testPathIgnorePatterns,
52
- }),
53
- ...config,
35
+ testRunner: 'jest-circus/runner',
36
+ transformIgnorePatterns: ['node_modules/(?!(@servicetitan|@react-hook|nanoid|axios)/)'],
37
+ verbose: true,
54
38
  };
55
- };
39
+ }
56
40
 
57
41
  /**
58
42
  * Get Jest config for running it using jest CLI (see jest runCLI function)
59
43
  */
60
- export const getJestConfigCLI = (args: Config.Argv): Config.Argv => {
61
- const { coveragePathIgnorePatterns, setupFiles, testPathIgnorePatterns, globals, ...config } = {
44
+ export function getJestConfigCLI(args: Config.Argv): Config.Argv {
45
+ const { coveragePathIgnorePatterns, setupFiles, testPathIgnorePatterns, ...config } = {
62
46
  ...getJestConfiguration(),
63
47
  ...args,
64
48
  };
65
49
 
66
- const { collectCoverageFrom, moduleNameMapper, ...rest } = getJestConfigBase({
67
- coveragePathIgnorePatterns,
68
- setupFiles,
69
- testPathIgnorePatterns,
50
+ return stringifyForCLI({
51
+ ...getDefaultJestConfiguration({
52
+ coveragePathIgnorePatterns,
53
+ setupFiles,
54
+ testPathIgnorePatterns,
55
+ }),
56
+ ...config,
70
57
  });
58
+ }
71
59
 
72
- return {
73
- collectCoverageFrom: JSON.stringify(collectCoverageFrom),
74
- globals: JSON.stringify(globals),
75
- moduleNameMapper: JSON.stringify(moduleNameMapper),
76
- ...rest,
77
- ...config,
78
- };
79
- };
60
+ function stringifyForCLI(config: any): Config.Argv {
61
+ return ['collectCoverageFrom', 'globals', 'moduleNameMapper', 'transform'].reduce(
62
+ (result, key) => {
63
+ const value = result[key];
64
+ if (value && typeof value !== 'string') {
65
+ result[key] = JSON.stringify(result[key]);
66
+ }
67
+ return result;
68
+ },
69
+ config
70
+ );
71
+ }
@@ -34,8 +34,8 @@ jest.mock('mini-css-extract-plugin', () =>
34
34
  );
35
35
  jest.mock('moment-locales-webpack-plugin', () => jest.fn());
36
36
  jest.mock('webpack', () => ({
37
- ...jest.requireActual('webpack'),
38
37
  DefinePlugin: jest.fn(),
38
+ IgnorePlugin: jest.fn(),
39
39
  }));
40
40
  jest.mock('webpack-assets-manifest', () => ({ WebpackAssetsManifest: jest.fn() }));
41
41
  jest.mock('webpack-remove-empty-scripts', () => jest.fn());
@@ -28,8 +28,8 @@ jest.mock('mini-css-extract-plugin', () =>
28
28
  );
29
29
  jest.mock('moment-locales-webpack-plugin', () => jest.fn());
30
30
  jest.mock('webpack', () => ({
31
- ...jest.requireActual('webpack'),
32
31
  DefinePlugin: jest.fn(),
32
+ IgnorePlugin: jest.fn(),
33
33
  }));
34
34
  jest.mock('webpack-assets-manifest', () => ({ WebpackAssetsManifest: jest.fn() }));
35
35
  jest.mock('webpack-virtual-modules', () => jest.fn());