diff --git a/src/node/runner.js b/src/node/runner.js index 3f3124b8..dff0e2d1 100644 --- a/src/node/runner.js +++ b/src/node/runner.js @@ -65,7 +65,6 @@ export class NodeRunner { }) this.stopped = false this.watching = false - this.beforeTestsOutput = undefined /** * @type {import('../types.js').RunnerEnv} */ @@ -122,7 +121,7 @@ export class NodeRunner { }) await this.#setupServer() - this.beforeTestsOutput = await this.options.beforeTests(this.options) + await this.options.beforeTests(this.env) try { const { outName } = await this.runTests() @@ -167,7 +166,7 @@ export class NodeRunner { }) await this.#setupServer() - this.beforeTestsOutput = await this.options.beforeTests(this.options) + await this.options.beforeTests(this.env) const { files, outName } = await this.runTests() try { @@ -208,7 +207,7 @@ export class NodeRunner { async #clean() { // Run after tests hook - await this.options.afterTests(this.options, this.beforeTestsOutput) + await this.options.afterTests(this.env) await premove(this.dir) const serverClose = new Promise((resolve, reject) => { if (this.server) { diff --git a/src/runner.js b/src/runner.js index c5d25774..7def5416 100644 --- a/src/runner.js +++ b/src/runner.js @@ -62,7 +62,6 @@ export class Runner { PW_TEST: this.options, NODE_ENV: 'test', }) - this.beforeTestsOutput = undefined this.tests = testFiles ?? findTests({ @@ -305,11 +304,10 @@ export class Runner { wait: 1000, }) - this.beforeTestsOutput = await this.options.beforeTests(this.options) - try { // Setup the context const context = await this.setupContext() + this.beforeTestsOutput = await this.options.beforeTests(this.env) // Run the before script if (this.options.before) { @@ -396,10 +394,9 @@ export class Runner { wait: 1000, }) - this.beforeTestsOutput = await this.options.beforeTests(this.options) - // Setup the context const context = await this.setupContext() + await this.options.beforeTests(this.env) // Run the before script if (this.options.before) { @@ -436,7 +433,7 @@ export class Runner { async #clean() { // Run after tests hook - await this.options.afterTests(this.options, this.beforeTestsOutput) + await this.options.afterTests(this.env) premove(this.dir) diff --git a/src/types.d.ts b/src/types.d.ts index f840d29e..b487448f 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -24,11 +24,18 @@ export interface RunnerOptions { buildConfig: BuildOptions buildSWConfig: BuildOptions browserContextOptions?: BrowserContextOptions - beforeTests: (opts: RunnerOptions) => Promise - afterTests: ( - opts: RunnerOptions, - beforeTestsOutput: unknown - ) => Promise + /** + * Before tests hook + * + * @param env - Runner environment. Use `env.PW_TEST` to access runner options. + */ + beforeTests: (env: RunnerEnv) => Promise + /** + * After tests hook + * + * @param env - Runner environment. Use `env.PW_TEST` to access runner options. + */ + afterTests: (env: RunnerEnv) => Promise } export interface RunnerEnv extends NodeJS.ProcessEnv { @@ -40,10 +47,10 @@ export interface RunnerEnv extends NodeJS.ProcessEnv { export type PwResult = TBrowser extends 'webkit' ? WebKitBrowser : TBrowser extends 'firefox' - ? FirefoxBrowser - : TBrowser extends 'chromium' - ? ChromiumBrowser - : never + ? FirefoxBrowser + : TBrowser extends 'chromium' + ? ChromiumBrowser + : never export interface CompilerOutput { outName: string