MCPcopy
hub / github.com/stenciljs/core / taskTest

Function taskTest

src/cli/task-test.ts:8–75  ·  view source on GitHub ↗
(config: ValidatedConfig)

Source from the content-addressed store, hash-verified

6 * @returns a void promise
7 */
8export const taskTest = async (config: ValidatedConfig): Promise<void> => {
9 config.logger.warn(
10 config.logger.yellow(
11 `[DEPRECATION] Stencil's integrated testing (the 'test' task, --spec and --e2e flags) is deprecated and will be removed in Stencil v5. ` +
12 `Migrate spec tests to @stencil/vitest (https://github.com/stenciljs/vitest) and ` +
13 `e2e / browser tests to either @stencil/vitest (https://github.com/stenciljs/vitest) or ` +
14 `@stencil/playwright (https://github.com/stenciljs/playwright). ` +
15 `See https://github.com/stenciljs/core/issues/6584 for full details.`,
16 ),
17 );
18 config.buildDocs = false;
19 const testingRunOpts: TestingRunOptions = {
20 e2e: !!config.flags.e2e,
21 screenshot: !!config.flags.screenshot,
22 spec: !!config.flags.spec,
23 updateScreenshot: !!config.flags.updateScreenshot,
24 };
25
26 // always ensure we have jest modules installed
27 const ensureModuleIds = ['@types/jest', 'jest', 'jest-cli'];
28
29 if (testingRunOpts.e2e) {
30 // if it's an e2e test, also make sure we're got
31 // puppeteer modules installed and if browserExecutablePath is provided don't download Chromium use only puppeteer-core instead
32 const puppeteer = config.testing.browserExecutablePath ? 'puppeteer-core' : 'puppeteer';
33
34 ensureModuleIds.push(puppeteer);
35
36 if (testingRunOpts.screenshot) {
37 // ensure we've got pixelmatch for screenshots
38 config.logger.warn(
39 config.logger.yellow(
40 `EXPERIMENTAL: screenshot visual diff testing is currently under heavy development and has not reached a stable status. However, any assistance testing would be appreciated.`,
41 ),
42 );
43 }
44 }
45
46 // ensure we've got the required modules installed
47 const diagnostics = await config.sys.lazyRequire?.ensure(config.rootDir, ensureModuleIds);
48 if (diagnostics && diagnostics.length > 0) {
49 config.logger.printDiagnostics(diagnostics);
50 return config.sys.exit(1);
51 }
52
53 try {
54 /**
55 * We dynamically import the testing submodule here in order for Stencil's lazy module checking to work properly.
56 *
57 * Prior to this call, we create a collection of string-based node module names and ensure that they're installed &
58 * on disk. The testing submodule includes `jest` (amongst other) testing libraries in its dependency chain. We need
59 * to run the lazy module check _before_ we include `jest` et al. in our dependency chain otherwise, the lazy module
60 * checking would fail to run properly (because we'd import `jest`, which wouldn't exist, before we even checked if
61 * it was installed).
62 */
63 const { createTesting } = await import('@stencil/core/testing');
64 const testing = await createTesting(config);
65 const passed = await testing.run(testingRunOpts);

Callers 1

runTaskFunction · 0.90

Calls 10

createTestingFunction · 0.85
warnMethod · 0.80
yellowMethod · 0.80
pushMethod · 0.80
printDiagnosticsMethod · 0.80
exitMethod · 0.80
errorMethod · 0.80
ensureMethod · 0.65
runMethod · 0.65
destroyMethod · 0.65

Tested by

no test coverage detected