(config: ValidatedConfig)
| 18 | import { getAppScriptUrl, getAppStyleUrl } from './testing-utils'; |
| 19 | |
| 20 | export const createTesting = async (config: ValidatedConfig): Promise<Testing> => { |
| 21 | config = setupTestingConfig(config); |
| 22 | |
| 23 | const { createCompiler } = require('../compiler/stencil.js'); |
| 24 | const compiler: Compiler = await createCompiler(config); |
| 25 | |
| 26 | let devServer: DevServer | null; |
| 27 | let puppeteerBrowser: puppeteer.Browser | null; |
| 28 | |
| 29 | /** |
| 30 | * Initiate running spec and/or end-to-end tests with Stencil |
| 31 | * @param opts running options to apply when |
| 32 | * @returns true if all tests passed. Returns false if any tests failed or an error occurred during the test |
| 33 | * setup/running process |
| 34 | */ |
| 35 | const run = async (opts: TestingRunOptions = {}): Promise<boolean> => { |
| 36 | let doScreenshots = false; |
| 37 | let passed = false; |
| 38 | let env: E2EProcessEnv; |
| 39 | let compilerWatcher: CompilerWatcher | null = null; |
| 40 | const msg: string[] = []; |
| 41 | |
| 42 | try { |
| 43 | if (!opts.spec && !opts.e2e) { |
| 44 | config.logger.error( |
| 45 | `Testing requires either the --spec or --e2e command line flags, or both. For example, to run unit tests, use the command: stencil test --spec`, |
| 46 | ); |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | // during E2E tests, we can safely assume that the current environment is a `E2EProcessEnv` |
| 51 | env = process.env as E2EProcessEnv; |
| 52 | |
| 53 | if (opts.e2e) { |
| 54 | msg.push('e2e'); |
| 55 | env.__STENCIL_E2E_TESTS__ = 'true'; |
| 56 | } |
| 57 | |
| 58 | if (opts.spec) { |
| 59 | msg.push('spec'); |
| 60 | env.__STENCIL_SPEC_TESTS__ = 'true'; |
| 61 | } |
| 62 | |
| 63 | config.logger.info(config.logger.magenta(`testing ${msg.join(' and ')} files${config.watch ? ' (watch)' : ''}`)); |
| 64 | |
| 65 | doScreenshots = !!(opts.e2e && opts.screenshot); |
| 66 | if (doScreenshots) { |
| 67 | env.__STENCIL_SCREENSHOT__ = 'true'; |
| 68 | if (config.testing.screenshotTimeout != null) { |
| 69 | env.__STENCIL_SCREENSHOT_TIMEOUT_MS__ = config.testing.screenshotTimeout.toString(); |
| 70 | } |
| 71 | |
| 72 | if (opts.updateScreenshot) { |
| 73 | config.logger.info(config.logger.magenta(`updating master screenshots`)); |
| 74 | } else { |
| 75 | config.logger.info(config.logger.magenta(`comparing against master screenshots`)); |
| 76 | } |
| 77 | } |
no test coverage detected