@web/test-runner-core
Advanced tools
Comparing version 0.6.15 to 0.6.16
# @web/test-runner-core | ||
## 0.6.16 | ||
### Patch Changes | ||
- 5fada4a: improve logging and error reporting | ||
## 0.6.15 | ||
@@ -4,0 +10,0 @@ |
@@ -8,2 +8,6 @@ import { CoverageMapData } from 'istanbul-lib-coverage'; | ||
} | ||
export interface SessionResult { | ||
testCoverage?: CoverageMapData; | ||
browserLogs: any[][]; | ||
} | ||
export interface BrowserLauncher { | ||
@@ -36,9 +40,4 @@ /** | ||
*/ | ||
stopSession(session: TestSession): void; | ||
stopSession(session: TestSession): SessionResult | Promise<SessionResult>; | ||
/** | ||
* Gets the test coverage for the test session if the browser launcher implementation | ||
* supports it. | ||
*/ | ||
getTestCoverage?(): undefined | Promise<CoverageMapData[] | undefined>; | ||
/** | ||
* Starts a debug session. This should start a session like startSession, but | ||
@@ -45,0 +44,0 @@ * without headless. If the implementation does not support debugging, |
@@ -19,18 +19,21 @@ import { BrowserLauncher } from '../browser-launcher/BrowserLauncher.js'; | ||
} | ||
export declare type LogLevel = 'log' | 'warn' | 'error' | 'debug'; | ||
export interface TestRunnerCoreConfig { | ||
rootDir: string; | ||
files: string | string[]; | ||
concurrency?: number; | ||
protocol: string; | ||
hostname: string; | ||
port: number; | ||
browsers: BrowserLauncher | BrowserLauncher[]; | ||
testFramework?: TestFramework; | ||
browsers: BrowserLauncher | BrowserLauncher[]; | ||
logger: Logger; | ||
reporters: Reporter[]; | ||
server: Server; | ||
logger: Logger; | ||
protocol: string; | ||
hostname: string; | ||
port: number; | ||
rootDir: string; | ||
testRunnerHtml?: (testRunnerImport: string, config: TestRunnerCoreConfig) => string; | ||
watch: boolean; | ||
logBrowserLogs?: boolean | LogLevel[]; | ||
logUncaughtErrors?: boolean; | ||
coverage?: boolean; | ||
coverageConfig?: CoverageConfig; | ||
concurrency?: number; | ||
browserStartTimeout?: number; | ||
@@ -37,0 +40,0 @@ sessionStartTimeout?: number; |
@@ -1,2 +0,2 @@ | ||
import { CoverageSummaryData, CoverageMap, CoverageMapData } from 'istanbul-lib-coverage'; | ||
import { CoverageSummaryData, CoverageMap } from 'istanbul-lib-coverage'; | ||
import { TestSession } from '../test-session/TestSession'; | ||
@@ -10,3 +10,3 @@ import { CoverageConfig } from '../config/TestRunnerCoreConfig'; | ||
} | ||
export declare function getTestCoverage(browserCoverage: CoverageMapData[], sessions: Iterable<TestSession>, config?: CoverageConfig): TestCoverage; | ||
export declare function getTestCoverage(sessions: Iterable<TestSession>, config?: CoverageConfig): TestCoverage; | ||
//# sourceMappingURL=getTestCoverage.d.ts.map |
@@ -67,3 +67,3 @@ "use strict"; | ||
} | ||
function getTestCoverage(browserCoverage, sessions, config) { | ||
function getTestCoverage(sessions, config) { | ||
const coverageMap = istanbul_lib_coverage_1.createCoverageMap(); | ||
@@ -73,3 +73,2 @@ let coverages = Array.from(sessions) | ||
.filter(c => c); | ||
coverages.push(...browserCoverage); | ||
// istanbul mutates the coverage objects, which pollutes coverage in watch mode | ||
@@ -76,0 +75,0 @@ // cloning prevents this. JSON stringify -> parse is faster than a fancy library |
import * as constants from './browser-launcher/constants'; | ||
export { constants }; | ||
export { BrowserLauncher, Viewport } from './browser-launcher/BrowserLauncher'; | ||
export { IndentedReportEntry, ReportEntry, Report, Reporter, ReportTestResultsArgs, ReportTestProgressArgs, ReporterArgs, TestRunArgs, TestRunStartedArgs, TestRunFinishedArgs, } from './reporter/Reporter'; | ||
export { BrowserLauncher, Viewport, SessionResult } from './browser-launcher/BrowserLauncher'; | ||
export { Reporter, ReportTestResultsArgs, GetTestProgressArgs, ReporterArgs, TestRunArgs, TestRunStartedArgs, TestRunFinishedArgs, } from './reporter/Reporter'; | ||
export { TestRunner } from './runner/TestRunner'; | ||
@@ -6,0 +6,0 @@ export { TestFramework } from './test-framework/TestFramework'; |
@@ -14,4 +14,6 @@ export interface ErrorWithLocation { | ||
warn(...messages: unknown[]): void; | ||
group(): void; | ||
groupEnd(): void; | ||
logSyntaxError(error: ErrorWithLocation): void; | ||
} | ||
//# sourceMappingURL=Logger.d.ts.map |
@@ -5,8 +5,3 @@ import { TestSession } from '../test-session/TestSession'; | ||
import { TestCoverage } from '../coverage/getTestCoverage'; | ||
export interface IndentedReportEntry { | ||
text: string; | ||
indent: number; | ||
} | ||
export declare type ReportEntry = string | IndentedReportEntry; | ||
export declare type Report = ReportEntry[] | undefined | void; | ||
import { Logger } from '../logger/Logger'; | ||
export interface ReporterArgs { | ||
@@ -20,2 +15,3 @@ config: TestRunnerCoreConfig; | ||
export interface ReportTestResultsArgs { | ||
logger: Logger; | ||
sessionsForTestFile: TestSession[]; | ||
@@ -25,6 +21,10 @@ testFile: string; | ||
} | ||
export interface ReportTestProgressArgs { | ||
export interface GetTestProgressArgs { | ||
config: TestRunnerCoreConfig; | ||
sessions: TestSession[]; | ||
startTime: number; | ||
testRun: number; | ||
focusedTestFile?: string; | ||
testCoverage?: TestCoverage; | ||
testFiles: string[]; | ||
} | ||
@@ -41,4 +41,4 @@ export interface TestRunArgs { | ||
export interface Reporter { | ||
reportTestFileResult?(args: ReportTestResultsArgs): Report | Promise<Report>; | ||
reportTestProgress?(args: ReportTestProgressArgs): Report; | ||
reportTestFileResults?(args: ReportTestResultsArgs): void | Promise<void>; | ||
getTestProgress?(args: GetTestProgressArgs): string | string[]; | ||
onTestRunStarted?(args: TestRunStartedArgs): void; | ||
@@ -45,0 +45,0 @@ onTestRunFinished?(args: TestRunFinishedArgs): void; |
@@ -37,3 +37,3 @@ import { TestRunnerCoreConfig } from '../config/TestRunnerCoreConfig'; | ||
stop(error?: any): Promise<void>; | ||
startDebugBrowser(testFile: string): Promise<void[]>; | ||
startDebugBrowser(testFile: string): void; | ||
private onSessionFinished; | ||
@@ -40,0 +40,0 @@ } |
@@ -30,3 +30,3 @@ "use strict"; | ||
if (session.status === TestSessionStatus_1.SESSION_STATUS.FINISHED) { | ||
this.onSessionFinished(session); | ||
this.onSessionFinished(); | ||
} | ||
@@ -117,16 +117,12 @@ }); | ||
startDebugBrowser(testFile) { | ||
const startPromises = []; | ||
for (const session of this.sessions.forTestFile(testFile)) { | ||
startPromises.push(session.browserLauncher | ||
session.browserLauncher | ||
.startDebugSession(session, createSessionUrl_1.createSessionUrl(this.config, session, true)) | ||
.catch(error => { | ||
console.error(error); | ||
})); | ||
}); | ||
} | ||
return Promise.all(startPromises); | ||
} | ||
async onSessionFinished(session) { | ||
var _a; | ||
async onSessionFinished() { | ||
try { | ||
session.browserLauncher.stopSession(session); | ||
this.scheduler.runScheduled(this.testRun); | ||
@@ -138,10 +134,3 @@ const finishedAll = Array.from(this.sessions.all()).every(s => s.status === TestSessionStatus_1.SESSION_STATUS.FINISHED); | ||
if (this.config.coverage) { | ||
const rawBrowserCoverage = []; | ||
for (const launcher of this.browserLaunchers) { | ||
const coverage = await ((_a = launcher.getTestCoverage) === null || _a === void 0 ? void 0 : _a.call(launcher)); | ||
if (coverage) { | ||
rawBrowserCoverage.push(...coverage); | ||
} | ||
} | ||
testCoverage = getTestCoverage_1.getTestCoverage(rawBrowserCoverage, this.sessions.all(), this.config.coverageConfig); | ||
testCoverage = getTestCoverage_1.getTestCoverage(this.sessions.all(), this.config.coverageConfig); | ||
passedCoverage = testCoverage.passed; | ||
@@ -148,0 +137,0 @@ } |
import { TestRunnerCoreConfig } from '../config/TestRunnerCoreConfig'; | ||
import { TestSessionManager } from '../test-session/TestSessionManager'; | ||
import { TestSession } from '../test-session/TestSession'; | ||
import { TestSession, TestResultError } from '../test-session/TestSession'; | ||
export declare class TestScheduler { | ||
@@ -14,7 +14,8 @@ private config; | ||
runScheduled(testRun: number): void; | ||
private runSession; | ||
private startSession; | ||
private setSessionFailed; | ||
private setSessionStartedTimeout; | ||
private setSessionFinishedTimeout; | ||
stopSession(session: TestSession, errors?: TestResultError[]): Promise<void>; | ||
} | ||
//# sourceMappingURL=TestScheduler.d.ts.map |
@@ -12,2 +12,6 @@ "use strict"; | ||
sessions.on('session-status-updated', session => { | ||
if (session.status === TestSessionStatus_1.SESSION_STATUS.TEST_FINISHED) { | ||
this.stopSession(session); | ||
return; | ||
} | ||
const timeoutIds = this.timeoutIdsPerSession.get(session.id); | ||
@@ -45,3 +49,3 @@ if (timeoutIds && session.status === TestSessionStatus_1.SESSION_STATUS.FINISHED) { | ||
const scheduledIt = this.sessions.forStatus(TestSessionStatus_1.SESSION_STATUS.SCHEDULED); | ||
const runningCount = Array.from(this.sessions.forStatus(TestSessionStatus_1.SESSION_STATUS.INITIALIZING, TestSessionStatus_1.SESSION_STATUS.STARTED)).length; | ||
const runningCount = Array.from(this.sessions.forStatus(TestSessionStatus_1.SESSION_STATUS.INITIALIZING, TestSessionStatus_1.SESSION_STATUS.TEST_STARTED, TestSessionStatus_1.SESSION_STATUS.TEST_FINISHED)).length; | ||
const count = this.config.concurrency - runningCount; | ||
@@ -53,6 +57,6 @@ for (let i = 0; i < count; i += 1) { | ||
} | ||
this.runSession(testRun, value); | ||
this.startSession(testRun, value); | ||
} | ||
} | ||
async runSession(testRun, session) { | ||
async startSession(testRun, session) { | ||
this.sessions.update(Object.assign(Object.assign({}, session), { testRun, status: TestSessionStatus_1.SESSION_STATUS.INITIALIZING })); | ||
@@ -64,3 +68,3 @@ let browserStartResponded = false; | ||
this.setSessionFailed(this.sessions.get(session.id), { | ||
message: `Browser did not start after ${this.config.browserStartTimeout}ms.`, | ||
message: `The browser was unable to open the test page after ${this.config.browserStartTimeout}ms.`, | ||
}); | ||
@@ -83,3 +87,3 @@ } | ||
setSessionFailed(session, ...errors) { | ||
this.sessions.updateStatus(Object.assign(Object.assign({}, session), { passed: false, errors }), TestSessionStatus_1.SESSION_STATUS.FINISHED); | ||
this.stopSession(session, errors); | ||
} | ||
@@ -95,7 +99,7 @@ setSessionStartedTimeout(testRun, sessionId) { | ||
this.setSessionFailed(session, { | ||
message: `Did not receive a start signal from browser after ${this.config.sessionStartTimeout}ms.`, | ||
message: `Browser tests did not start after ${this.config.sessionStartTimeout}ms. Check the browser logs or open the browser in debug mode for more information.`, | ||
}); | ||
return; | ||
} | ||
if (session.status === TestSessionStatus_1.SESSION_STATUS.FINISHED) { | ||
if ([TestSessionStatus_1.SESSION_STATUS.TEST_FINISHED, TestSessionStatus_1.SESSION_STATUS.FINISHED].includes(session.status)) { | ||
// The session finished by now | ||
@@ -117,3 +121,3 @@ return; | ||
this.setSessionFailed(session, { | ||
message: `Browser did not finish within ${this.config.sessionStartTimeout}ms.`, | ||
message: `Browser tests did not finish within ${this.config.sessionStartTimeout}ms. Check the browser logs or open the browser in debug mode for more information.`, | ||
}); | ||
@@ -124,4 +128,15 @@ } | ||
} | ||
async stopSession(session, errors = []) { | ||
var _a; | ||
const { testCoverage, browserLogs: logs } = await session.browserLauncher.stopSession(session); | ||
const updatedSession = Object.assign(Object.assign({}, session), { testCoverage, logs }); | ||
if (errors.length > 0) { | ||
// merge with existing erors | ||
updatedSession.errors = [...((_a = updatedSession.errors) !== null && _a !== void 0 ? _a : []), ...errors]; | ||
updatedSession.passed = false; | ||
} | ||
this.sessions.updateStatus(updatedSession, TestSessionStatus_1.SESSION_STATUS.FINISHED); | ||
} | ||
} | ||
exports.TestScheduler = TestScheduler; | ||
//# sourceMappingURL=TestScheduler.js.map |
@@ -25,3 +25,3 @@ import { CoverageMapData } from 'istanbul-lib-coverage'; | ||
tests: TestResult[]; | ||
logs: string[]; | ||
logs: any[][]; | ||
request404s: string[]; | ||
@@ -28,0 +28,0 @@ testCoverage?: CoverageMapData; |
@@ -5,5 +5,6 @@ export declare type TestSessionStatus = 'SCHEDULED' | 'INITIALIZING' | 'STARTED' | 'FINISHED'; | ||
INITIALIZING: TestSessionStatus; | ||
STARTED: TestSessionStatus; | ||
TEST_STARTED: TestSessionStatus; | ||
TEST_FINISHED: TestSessionStatus; | ||
FINISHED: TestSessionStatus; | ||
}; | ||
//# sourceMappingURL=TestSessionStatus.d.ts.map |
@@ -10,6 +10,8 @@ "use strict"; | ||
// browser has started, running the actual tests | ||
STARTED: 'STARTED', | ||
// finished running tests | ||
TEST_STARTED: 'TEST_STARTED', | ||
// browser has collected the test results, but not yet results, logs or coverage | ||
TEST_FINISHED: 'TEST_FINISHED', | ||
// finished running tests and collecting tests results, logs, coverage etc. | ||
FINISHED: 'FINISHED', | ||
}; | ||
//# sourceMappingURL=TestSessionStatus.js.map |
{ | ||
"name": "@web/test-runner-core", | ||
"version": "0.6.15", | ||
"version": "0.6.16", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -25,2 +25,10 @@ # Web Test Runner Core | ||
[Read more here](./docs/reporter.md) to learn more about setting up a custom test reporter. | ||
## Reporters | ||
Reporters report test results and/or progress. The CLI ships a default reporter. Implementations: | ||
- [@web/test-runner-cli](https://github.com/modernweb-dev/web/tree/master/packages/test-runner-cli) | ||
[Read more here](https://github.com/modernweb-dev/web/tree/master/packages/test-runner-browser-lib) to learn more about using the browser library without a testing framework, or to implement your own testing framework. | ||
@@ -27,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77221
925
42