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