import type { Config , TestingRunOptions } from '../declarations' ; import { IS_NODE_ENV } from '../compiler/sys/environment' ; export const taskTest = async ( config ) => { if ( ! IS_NODE_ENV ) { config . logger . error ( `"test" command is currently only implemented for a NodeJS environment` ) ; return config . sys . exit ( 1 ) ; } try { config . buildDocs = false ; const testingRunOpts = { e2e : ! ! config . flags . e2e , screenshot : ! ! config . flags . screenshot , spec : ! ! config . flags . spec , updateScreenshot : ! ! config . flags . updateScreenshot , } ; const ensureModuleIds = [ '@types/jest' , 'jest' , 'jest-cli' ] ; if ( testingRunOpts . e2e ) { const puppeteer = config . testing . browserExecutablePath ? 'puppeteer-core' : 'puppeteer' ; ensureModuleIds . push ( puppeteer ) ; if ( testingRunOpts . screenshot ) { 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.` ) ) ; } } const diagnostics = await config . sys . lazyRequire . ensure ( config . rootDir , ensureModuleIds ) ; if ( diagnostics . length > 0 ) { config . logger . printDiagnostics ( diagnostics ) ; return config . sys . exit ( 1 ) ; } 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 ) ; } } ;