Skip to content

Commit

Permalink
fixup types
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed Aug 20, 2020
1 parent 4712b55 commit 10b86cd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
18 changes: 9 additions & 9 deletions test-runner/src/builtin.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ declare global {
const describe: DescribeFunction;
const fdescribe: DescribeFunction;
const xdescribe: DescribeFunction;
const it: ItFunction<FixtureState & WorkerState>;
const fit: ItFunction<FixtureState & WorkerState>;
const dit: ItFunction<FixtureState & WorkerState>;
const xit: ItFunction<FixtureState & WorkerState>;
const it: ItFunction<TestState & WorkerState & FixtureParameters>;
const fit: ItFunction<TestState & WorkerState & FixtureParameters>;
const dit: ItFunction<TestState & WorkerState & FixtureParameters>;
const xit: ItFunction<TestState & WorkerState & FixtureParameters>;

const beforeEach: (inner: (state: FixtureState & WorkerState) => Promise<void>) => void;
const afterEach: (inner: (state: FixtureState & WorkerState) => Promise<void>) => void;
const beforeAll: (inner: (state: WorkerState) => Promise<void>) => void;
const afterAll: (inner: (state: WorkerState) => Promise<void>) => void;
const beforeEach: (inner: (state: TestState & WorkerState & FixtureParameters) => Promise<void>) => void;
const afterEach: (inner: (state: TestState & WorkerState & FixtureParameters) => Promise<void>) => void;
const beforeAll: (inner: (state: WorkerState & FixtureParameters) => Promise<void>) => void;
const afterAll: (inner: (state: WorkerState & FixtureParameters) => Promise<void>) => void;
}

const mkdtempAsync = promisify(fs.mkdtemp);
Expand All @@ -58,7 +58,7 @@ declare global {
interface FixtureParameters {
parallelIndex: number;
}
interface FixtureState {
interface TestState {
tmpDir: string;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test-runner/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ let beforeFunction;
let afterFunction;
let matrix = {};

global.before = (fn => beforeFunction = fn);
global.after = (fn => afterFunction = fn);
global.matrix = (m => matrix = m);
global['before'] = (fn => beforeFunction = fn);
global['after'] = (fn => afterFunction = fn);
global['matrix'] = (m => matrix = m);

program
.version('Version ' + /** @type {any} */ (require)('../package.json').version)
Expand Down
14 changes: 7 additions & 7 deletions test-runner/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ declare global {
interface WorkerState {
}

interface FixtureState {
interface TestState {
}

interface FixtureParameters {
Expand All @@ -32,10 +32,10 @@ const registrationsByFile = new Map();
export let parameters: FixtureParameters = {} as FixtureParameters;
export const parameterRegistrations = new Map();

export function setParameters(params) {
export function setParameters(params: any) {
parameters = Object.assign(parameters, params);
for (const name of Object.keys(params))
registerWorkerFixture(name, async ({}, test) => await test(parameters[name]));
registerWorkerFixture(name as keyof WorkerState, async ({}, test) => await test(parameters[name] as never));
}


Expand Down Expand Up @@ -159,8 +159,8 @@ export class FixturePool {
}
}

export function fixturesForCallback(callback: any) {
const names = new Set();
export function fixturesForCallback(callback: any): string[] {
const names = new Set<string>();
const visit = (callback: any) => {
for (const name of fixtureParameterNames(callback)) {
if (name in names)
Expand Down Expand Up @@ -210,11 +210,11 @@ function innerRegisterFixture(name: any, scope: string, fn: any, caller: Functio
registrationsByFile.get(file).push(registration);
};

export function registerFixture<T extends keyof FixtureState>(name: T, fn: (params: WorkerState & FixtureState, test: (arg: FixtureState[T]) => Promise<void>) => Promise<void>) {
export function registerFixture<T extends keyof TestState>(name: T, fn: (params: FixtureParameters & WorkerState & TestState, test: (arg: TestState[T]) => Promise<void>) => Promise<void>) {
innerRegisterFixture(name, 'test', fn, registerFixture);
};

export function registerWorkerFixture<T extends keyof WorkerState>(name: T, fn: (params: WorkerState, test: (arg: WorkerState[T]) => Promise<void>) => Promise<void>) {
export function registerWorkerFixture<T extends keyof (WorkerState & FixtureParameters)>(name: T, fn: (params: FixtureParameters & WorkerState, test: (arg: (WorkerState & FixtureParameters)[T]) => Promise<void>) => Promise<void>) {
innerRegisterFixture(name, 'worker', fn, registerWorkerFixture);
};

Expand Down
1 change: 1 addition & 0 deletions test-runner/src/testCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestCollector {
constructor(files, matrix, options) {
this._matrix = matrix;
for (const name of Object.keys(matrix))
//@ts-ignore
registerWorkerFixture(name, async ({}, test) => test());
this._options = options;
this.suite = new Mocha.Suite('', new Mocha.Context(), true);
Expand Down
1 change: 1 addition & 0 deletions test-runner/src/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class TestRunner extends EventEmitter {
this._parsedGeneratorConfiguration = {};
for (const {name, value} of this._configurationObject) {
this._parsedGeneratorConfiguration[name] = value;
// @ts-ignore
registerWorkerFixture(name, async ({}, test) => await test(value));
}
this._parsedGeneratorConfiguration['parallelIndex'] = workerId;
Expand Down
1 change: 1 addition & 0 deletions test-runner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"declaration": true,
"allowJs": true,
"checkJs": true,
"declarationMap": true
},
"compileOnSave": true,
"include": ["src"],
Expand Down
1 change: 1 addition & 0 deletions test/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import './playwright.fixtures';

import { globToRegex } from '../lib/rpc/client/clientHelper';
import vm from 'vm';
import { options } from './playwright.fixtures';

it('should work with navigation', async({page, server}) => {
const requests = new Map();
Expand Down
2 changes: 1 addition & 1 deletion test/playwright.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ declare global {
browserName: string;
headless: boolean;
wire: boolean;
slowMo: boolean;
slowMo: number;
}
}

Expand Down

0 comments on commit 10b86cd

Please sign in to comment.