2021-06-07 03:09:53 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-07-05 20:46:30 +03:00
|
|
|
import type { JSONReport, JSONReportSuite, JSONReportTest, JSONReportTestResult } from '@playwright/test/reporter';
|
2021-06-07 03:09:53 +03:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as os from 'os';
|
2021-10-15 01:48:05 +03:00
|
|
|
import * as path from 'path';
|
2022-04-19 06:20:49 +03:00
|
|
|
import { rimraf, PNG } from 'playwright-core/lib/utilsBundle';
|
2021-06-07 03:09:53 +03:00
|
|
|
import { promisify } from 'util';
|
2022-04-07 00:57:14 +03:00
|
|
|
import type { CommonFixtures } from '../config/commonFixtures';
|
|
|
|
import { commonFixtures } from '../config/commonFixtures';
|
|
|
|
import type { ServerFixtures, ServerWorkerOptions } from '../config/serverFixtures';
|
|
|
|
import { serverFixtures } from '../config/serverFixtures';
|
|
|
|
import type { TestInfo } from './stable-test-runner';
|
2022-07-05 20:46:30 +03:00
|
|
|
import { expect } from './stable-test-runner';
|
2022-04-07 00:57:14 +03:00
|
|
|
import { test as base } from './stable-test-runner';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
const removeFolderAsync = promisify(rimraf);
|
|
|
|
|
2022-11-18 03:31:04 +03:00
|
|
|
export type CliRunResult = {
|
|
|
|
exitCode: number,
|
|
|
|
output: string,
|
|
|
|
};
|
|
|
|
|
2022-07-05 20:46:30 +03:00
|
|
|
export type RunResult = {
|
2021-06-07 03:09:53 +03:00
|
|
|
exitCode: number,
|
|
|
|
output: string,
|
|
|
|
passed: number,
|
|
|
|
failed: number,
|
|
|
|
flaky: number,
|
|
|
|
skipped: number,
|
2022-08-02 22:55:43 +03:00
|
|
|
interrupted: number,
|
2021-07-09 03:16:36 +03:00
|
|
|
report: JSONReport,
|
2021-06-07 03:09:53 +03:00
|
|
|
results: any[],
|
|
|
|
};
|
|
|
|
|
|
|
|
type TSCResult = {
|
|
|
|
output: string;
|
|
|
|
exitCode: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
type Files = { [key: string]: string | Buffer };
|
|
|
|
type Params = { [key: string]: string | number | boolean | string[] };
|
|
|
|
type Env = { [key: string]: string | number | boolean | undefined };
|
|
|
|
|
|
|
|
async function writeFiles(testInfo: TestInfo, files: Files) {
|
|
|
|
const baseDir = testInfo.outputPath();
|
|
|
|
|
|
|
|
const headerJS = `
|
2021-10-11 17:52:17 +03:00
|
|
|
const pwt = require('@playwright/test');
|
2021-06-07 03:09:53 +03:00
|
|
|
`;
|
|
|
|
const headerTS = `
|
2021-10-11 17:52:17 +03:00
|
|
|
import * as pwt from '@playwright/test';
|
2021-06-07 03:09:53 +03:00
|
|
|
`;
|
2021-11-24 23:42:48 +03:00
|
|
|
const headerESM = `
|
2021-10-11 17:52:17 +03:00
|
|
|
import * as pwt from '@playwright/test';
|
2021-06-30 01:28:41 +03:00
|
|
|
`;
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
const hasConfig = Object.keys(files).some(name => name.includes('.config.'));
|
|
|
|
if (!hasConfig) {
|
|
|
|
files = {
|
|
|
|
...files,
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [ {} ] };
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
}
|
2022-03-24 02:05:49 +03:00
|
|
|
if (!Object.keys(files).some(name => name.includes('package.json'))) {
|
|
|
|
files = {
|
|
|
|
...files,
|
|
|
|
'package.json': `{ "name": "test-project" }`,
|
|
|
|
};
|
|
|
|
}
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
await Promise.all(Object.keys(files).map(async name => {
|
|
|
|
const fullName = path.join(baseDir, name);
|
|
|
|
await fs.promises.mkdir(path.dirname(fullName), { recursive: true });
|
2021-06-30 01:28:41 +03:00
|
|
|
const isTypeScriptSourceFile = name.endsWith('.ts') && !name.endsWith('.d.ts');
|
2021-11-24 23:42:48 +03:00
|
|
|
const isJSModule = name.endsWith('.mjs') || name.includes('esm');
|
|
|
|
const header = isTypeScriptSourceFile ? headerTS : (isJSModule ? headerESM : headerJS);
|
2021-07-12 19:59:58 +03:00
|
|
|
if (typeof files[name] === 'string' && files[name].includes('//@no-header')) {
|
|
|
|
await fs.promises.writeFile(fullName, files[name]);
|
2022-10-18 22:45:33 +03:00
|
|
|
} else if (/(spec|test)\.(js|ts|jsx|tsx|mjs)$/.test(name)) {
|
2021-06-07 08:07:07 +03:00
|
|
|
const fileHeader = header + 'const { expect } = pwt;\n';
|
2021-06-07 03:09:53 +03:00
|
|
|
await fs.promises.writeFile(fullName, fileHeader + files[name]);
|
|
|
|
} else if (/\.(js|ts)$/.test(name) && !name.endsWith('d.ts')) {
|
|
|
|
await fs.promises.writeFile(fullName, header + files[name]);
|
|
|
|
} else {
|
|
|
|
await fs.promises.writeFile(fullName, files[name]);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
return baseDir;
|
|
|
|
}
|
|
|
|
|
2021-10-11 22:07:40 +03:00
|
|
|
const cliEntrypoint = path.join(__dirname, '../../packages/playwright-core/cli.js');
|
|
|
|
|
2021-09-22 02:24:48 +03:00
|
|
|
async function runPlaywrightTest(childProcess: CommonFixtures['childProcess'], baseDir: string, params: any, env: Env, options: RunOptions): Promise<RunResult> {
|
2022-06-19 01:47:26 +03:00
|
|
|
const paramList: string[] = [];
|
2021-06-07 03:09:53 +03:00
|
|
|
for (const key of Object.keys(params)) {
|
|
|
|
for (const value of Array.isArray(params[key]) ? params[key] : [params[key]]) {
|
|
|
|
const k = key.startsWith('-') ? key : '--' + key;
|
|
|
|
paramList.push(params[key] === true ? `${k}` : `${k}=${value}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const outputDir = path.join(baseDir, 'test-results');
|
|
|
|
const reportFile = path.join(outputDir, 'report.json');
|
2022-11-18 03:31:04 +03:00
|
|
|
const args = ['test'];
|
2021-09-21 03:17:12 +03:00
|
|
|
if (!options.usesCustomOutputDir)
|
2021-06-23 12:08:35 +03:00
|
|
|
args.push('--output=' + outputDir);
|
2022-06-19 01:47:26 +03:00
|
|
|
if (!options.usesCustomReporters)
|
|
|
|
args.push('--reporter=dot,json');
|
2021-06-07 03:09:53 +03:00
|
|
|
args.push(
|
|
|
|
'--workers=2',
|
|
|
|
...paramList
|
|
|
|
);
|
2021-09-21 03:17:12 +03:00
|
|
|
if (options.additionalArgs)
|
|
|
|
args.push(...options.additionalArgs);
|
2021-06-07 03:09:53 +03:00
|
|
|
|
2022-11-18 03:31:04 +03:00
|
|
|
const cwd = options.cwd ? path.resolve(baseDir, options.cwd) : baseDir;
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
let { exitCode, output } = await runPlaywrightCommand(childProcess, cwd, args, {
|
|
|
|
PLAYWRIGHT_JSON_OUTPUT_NAME: reportFile,
|
|
|
|
...env,
|
|
|
|
}, options.sendSIGINTAfter);
|
|
|
|
|
2021-06-07 03:09:53 +03:00
|
|
|
const summary = (re: RegExp) => {
|
|
|
|
let result = 0;
|
2022-11-18 03:31:04 +03:00
|
|
|
let match = re.exec(output);
|
2021-06-07 03:09:53 +03:00
|
|
|
while (match) {
|
|
|
|
result += (+match[1]);
|
2022-11-18 03:31:04 +03:00
|
|
|
match = re.exec(output);
|
2021-06-07 03:09:53 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
const passed = summary(/(\d+) passed/g);
|
|
|
|
const failed = summary(/(\d+) failed/g);
|
|
|
|
const flaky = summary(/(\d+) flaky/g);
|
|
|
|
const skipped = summary(/(\d+) skipped/g);
|
2022-08-02 22:55:43 +03:00
|
|
|
const interrupted = summary(/(\d+) interrupted/g);
|
2021-06-07 03:09:53 +03:00
|
|
|
let report;
|
|
|
|
try {
|
|
|
|
report = JSON.parse(fs.readFileSync(reportFile).toString());
|
|
|
|
} catch (e) {
|
2022-11-18 03:31:04 +03:00
|
|
|
output += '\n' + e.toString();
|
2021-06-07 03:09:53 +03:00
|
|
|
}
|
|
|
|
|
2022-06-19 01:47:26 +03:00
|
|
|
const results: JSONReportTestResult[] = [];
|
2021-07-09 03:16:36 +03:00
|
|
|
function visitSuites(suites?: JSONReportSuite[]) {
|
2021-06-07 03:09:53 +03:00
|
|
|
if (!suites)
|
|
|
|
return;
|
|
|
|
for (const suite of suites) {
|
|
|
|
for (const spec of suite.specs) {
|
|
|
|
for (const test of spec.tests)
|
|
|
|
results.push(...test.results);
|
|
|
|
}
|
|
|
|
visitSuites(suite.suites);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (report)
|
|
|
|
visitSuites(report.suites);
|
|
|
|
|
|
|
|
return {
|
2021-09-21 03:17:12 +03:00
|
|
|
exitCode,
|
2022-11-18 03:31:04 +03:00
|
|
|
output,
|
2021-06-07 03:09:53 +03:00
|
|
|
passed,
|
|
|
|
failed,
|
|
|
|
flaky,
|
|
|
|
skipped,
|
2022-08-02 22:55:43 +03:00
|
|
|
interrupted,
|
2021-06-07 03:09:53 +03:00
|
|
|
report,
|
|
|
|
results,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-18 03:31:04 +03:00
|
|
|
async function runPlaywrightCommand(childProcess: CommonFixtures['childProcess'], cwd: string, commandWithArguments: string[], env: Env, sendSIGINTAfter?: number): Promise<CliRunResult> {
|
|
|
|
const command = ['node', cliEntrypoint];
|
|
|
|
command.push(...commandWithArguments);
|
|
|
|
const cacheDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-test-cache-'));
|
|
|
|
const testProcess = childProcess({
|
|
|
|
command,
|
|
|
|
env: {
|
|
|
|
...process.env,
|
|
|
|
PWTEST_CACHE_DIR: cacheDir,
|
|
|
|
// BEGIN: Reserved CI
|
|
|
|
CI: undefined,
|
|
|
|
BUILD_URL: undefined,
|
|
|
|
CI_COMMIT_SHA: undefined,
|
|
|
|
CI_JOB_URL: undefined,
|
|
|
|
CI_PROJECT_URL: undefined,
|
|
|
|
GITHUB_REPOSITORY: undefined,
|
|
|
|
GITHUB_RUN_ID: undefined,
|
|
|
|
GITHUB_SERVER_URL: undefined,
|
|
|
|
GITHUB_SHA: undefined,
|
|
|
|
// END: Reserved CI
|
|
|
|
PW_TEST_HTML_REPORT_OPEN: undefined,
|
|
|
|
PW_TEST_REPORTER: undefined,
|
|
|
|
PW_TEST_REPORTER_WS_ENDPOINT: undefined,
|
|
|
|
PW_TEST_SOURCE_TRANSFORM: undefined,
|
|
|
|
PW_TEST_SOURCE_TRANSFORM_SCOPE: undefined,
|
|
|
|
PW_OUT_OF_PROCESS_DRIVER: undefined,
|
|
|
|
NODE_OPTIONS: undefined,
|
|
|
|
...env,
|
|
|
|
},
|
|
|
|
cwd,
|
|
|
|
});
|
|
|
|
let didSendSigint = false;
|
|
|
|
testProcess.onOutput = () => {
|
|
|
|
if (sendSIGINTAfter && !didSendSigint && countTimes(testProcess.output, '%%SEND-SIGINT%%') >= sendSIGINTAfter) {
|
|
|
|
didSendSigint = true;
|
|
|
|
process.kill(testProcess.process.pid!, 'SIGINT');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const { exitCode } = await testProcess.exited;
|
|
|
|
await removeFolderAsync(cacheDir);
|
|
|
|
|
|
|
|
return { exitCode, output: testProcess.output.toString() };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-07 22:04:43 +03:00
|
|
|
type RunOptions = {
|
|
|
|
sendSIGINTAfter?: number;
|
2021-09-21 03:17:12 +03:00
|
|
|
usesCustomOutputDir?: boolean;
|
2022-06-19 01:47:26 +03:00
|
|
|
usesCustomReporters?: boolean;
|
2021-09-21 03:17:12 +03:00
|
|
|
additionalArgs?: string[];
|
2022-03-24 02:05:49 +03:00
|
|
|
cwd?: string,
|
2021-07-07 22:04:43 +03:00
|
|
|
};
|
2021-06-07 03:09:53 +03:00
|
|
|
type Fixtures = {
|
|
|
|
writeFiles: (files: Files) => Promise<string>;
|
2022-03-23 02:28:04 +03:00
|
|
|
runInlineTest: (files: Files, params?: Params, env?: Env, options?: RunOptions, beforeRunPlaywrightTest?: ({ baseDir }: { baseDir: string }) => Promise<void>) => Promise<RunResult>;
|
2021-06-07 03:09:53 +03:00
|
|
|
runTSC: (files: Files) => Promise<TSCResult>;
|
2022-09-24 06:01:27 +03:00
|
|
|
nodeVersion: { major: number, minor: number, patch: number };
|
|
|
|
runGroups: (files: Files, params?: Params, env?: Env, options?: RunOptions) => Promise<{ timeline: { titlePath: string[], event: 'begin' | 'end' }[] } & RunResult>;
|
2022-11-18 03:31:04 +03:00
|
|
|
runCommand: (files: Files, args: string[]) => Promise<CliRunResult>;
|
2021-06-07 03:09:53 +03:00
|
|
|
};
|
|
|
|
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
export const test = base
|
2021-12-18 21:12:35 +03:00
|
|
|
.extend<CommonFixtures>(commonFixtures)
|
2022-01-06 20:29:05 +03:00
|
|
|
.extend<ServerFixtures, ServerWorkerOptions>(serverFixtures)
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
.extend<Fixtures>({
|
|
|
|
writeFiles: async ({}, use, testInfo) => {
|
|
|
|
await use(files => writeFiles(testInfo, files));
|
|
|
|
},
|
2021-06-07 03:09:53 +03:00
|
|
|
|
2022-05-04 00:25:56 +03:00
|
|
|
runInlineTest: async ({ childProcess }, use, testInfo: TestInfo) => {
|
2022-03-23 02:28:04 +03:00
|
|
|
await use(async (files: Files, params: Params = {}, env: Env = {}, options: RunOptions = {}, beforeRunPlaywrightTest?: ({ baseDir: string }) => Promise<void>) => {
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
const baseDir = await writeFiles(testInfo, files);
|
2022-03-23 02:28:04 +03:00
|
|
|
if (beforeRunPlaywrightTest)
|
|
|
|
await beforeRunPlaywrightTest({ baseDir });
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
return await runPlaywrightTest(childProcess, baseDir, params, env, options);
|
|
|
|
});
|
|
|
|
},
|
2021-06-07 03:09:53 +03:00
|
|
|
|
2022-11-18 03:31:04 +03:00
|
|
|
runCommand: async ({ childProcess }, use, testInfo: TestInfo) => {
|
|
|
|
await use(async (files: Files, args: string[]) => {
|
|
|
|
const baseDir = await writeFiles(testInfo, files);
|
|
|
|
return await runPlaywrightCommand(childProcess, baseDir, args, { });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
feat(test runner): replace declare/define with "options" (#10293)
1. Fixtures defined in test.extend() can now have `{ option: true }` configuration that makes them overridable in the config. Options support all other properties of fixtures - value/function, scope, auto.
```
const test = base.extend<MyOptions>({
foo: ['default', { option: true }],
});
```
2. test.declare() and project.define are removed.
3. project.use applies overrides to default option values and nothing else. Any test.extend() and test.use() calls take priority over config options.
Required user changes: if someone used to define fixture options with test.extend(), overriding them in config will stop working. The solution is to add `{ option: true }`.
```
// Old code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: 123,
myFixture: ({ myOption }, use) => use(2 * myOption),
});
// New code
export const test = base.extend<{ myOption: number, myFixture: number }>({
myOption: [123, { option: true }],
myFixture: ({ myOption }, use) => use(2 * myOption),
});
```
2021-11-19 02:45:52 +03:00
|
|
|
runTSC: async ({ childProcess }, use, testInfo) => {
|
|
|
|
await use(async files => {
|
|
|
|
const baseDir = await writeFiles(testInfo, { 'tsconfig.json': JSON.stringify(TSCONFIG), ...files });
|
|
|
|
const tsc = childProcess({
|
|
|
|
command: ['npx', 'tsc', '-p', baseDir],
|
|
|
|
cwd: baseDir,
|
|
|
|
shell: true,
|
|
|
|
});
|
|
|
|
const { exitCode } = await tsc.exited;
|
|
|
|
return { exitCode, output: tsc.output };
|
|
|
|
});
|
|
|
|
},
|
2022-06-02 02:50:23 +03:00
|
|
|
|
|
|
|
nodeVersion: async ({}, use) => {
|
|
|
|
const [major, minor, patch] = process.versions.node.split('.');
|
|
|
|
await use({ major: +major, minor: +minor, patch: +patch });
|
|
|
|
},
|
2022-09-24 06:01:27 +03:00
|
|
|
|
|
|
|
runGroups: async ({ runInlineTest }, use, testInfo) => {
|
|
|
|
const timelinePath = testInfo.outputPath('timeline.json');
|
|
|
|
await use(async (files, params, env, options) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
...files,
|
|
|
|
'reporter.ts': `
|
|
|
|
import { Reporter, TestCase } from '@playwright/test/reporter';
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
class TimelineReporter implements Reporter {
|
|
|
|
private _timeline: {titlePath: string, event: 'begin' | 'end'}[] = [];
|
|
|
|
onTestBegin(test: TestCase) {
|
|
|
|
this._timeline.push({ titlePath: test.titlePath(), event: 'begin' });
|
|
|
|
}
|
|
|
|
onTestEnd(test: TestCase) {
|
|
|
|
this._timeline.push({ titlePath: test.titlePath(), event: 'end' });
|
|
|
|
}
|
|
|
|
onEnd() {
|
|
|
|
fs.writeFileSync(path.join(${JSON.stringify(timelinePath)}), JSON.stringify(this._timeline, null, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default TimelineReporter;
|
|
|
|
`
|
|
|
|
}, { ...params, reporter: 'list,json,./reporter.ts', workers: 2 }, env, options);
|
|
|
|
|
|
|
|
let timeline;
|
|
|
|
try {
|
|
|
|
timeline = JSON.parse((await fs.promises.readFile(timelinePath, 'utf8')).toString('utf8'));
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...result,
|
|
|
|
timeline
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
2021-09-21 03:17:12 +03:00
|
|
|
});
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
const TSCONFIG = {
|
|
|
|
'compilerOptions': {
|
|
|
|
'target': 'ESNext',
|
|
|
|
'moduleResolution': 'node',
|
|
|
|
'module': 'commonjs',
|
|
|
|
'strict': true,
|
|
|
|
'esModuleInterop': true,
|
|
|
|
'allowSyntheticDefaultImports': true,
|
|
|
|
'rootDir': '.',
|
2022-03-16 23:34:41 +03:00
|
|
|
'lib': ['esnext', 'dom', 'DOM.Iterable'],
|
|
|
|
'noEmit': true,
|
2021-06-07 03:09:53 +03:00
|
|
|
},
|
|
|
|
'exclude': [
|
|
|
|
'node_modules'
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2021-09-03 21:22:25 +03:00
|
|
|
export { expect } from './stable-test-runner';
|
2021-06-07 03:09:53 +03:00
|
|
|
|
|
|
|
const asciiRegex = new RegExp('[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))', 'g');
|
2022-02-01 04:14:59 +03:00
|
|
|
export function stripAnsi(str: string): string {
|
2021-06-07 03:09:53 +03:00
|
|
|
return str.replace(asciiRegex, '');
|
|
|
|
}
|
2021-07-07 22:04:43 +03:00
|
|
|
|
2022-01-13 21:38:47 +03:00
|
|
|
export function countTimes(s: string, sub: string): number {
|
2021-07-07 22:04:43 +03:00
|
|
|
let result = 0;
|
|
|
|
for (let index = 0; index !== -1;) {
|
|
|
|
index = s.indexOf(sub, index);
|
|
|
|
if (index !== -1) {
|
|
|
|
result++;
|
|
|
|
index += sub.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-02-24 00:17:37 +03:00
|
|
|
|
2022-02-28 23:25:59 +03:00
|
|
|
export function createImage(width: number, height: number, r: number = 0, g: number = 0, b: number = 0, a: number = 255): Buffer {
|
2022-02-24 00:17:37 +03:00
|
|
|
const image = new PNG({ width, height });
|
|
|
|
// Make both images red.
|
|
|
|
for (let i = 0; i < width * height; ++i) {
|
|
|
|
image.data[i * 4 + 0] = r;
|
|
|
|
image.data[i * 4 + 1] = g;
|
|
|
|
image.data[i * 4 + 2] = b;
|
2022-02-28 23:25:59 +03:00
|
|
|
image.data[i * 4 + 3] = a;
|
2022-02-24 00:17:37 +03:00
|
|
|
}
|
|
|
|
return PNG.sync.write(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createWhiteImage(width: number, height: number) {
|
|
|
|
return createImage(width, height, 255, 255, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function paintBlackPixels(image: Buffer, blackPixelsCount: number): Buffer {
|
2022-03-09 07:29:31 +03:00
|
|
|
const png = PNG.sync.read(image);
|
2022-02-24 00:17:37 +03:00
|
|
|
for (let i = 0; i < blackPixelsCount; ++i) {
|
|
|
|
for (let j = 0; j < 3; ++j)
|
2022-03-09 07:29:31 +03:00
|
|
|
png.data[i * 4 + j] = 0;
|
2022-02-24 00:17:37 +03:00
|
|
|
}
|
2022-03-09 07:29:31 +03:00
|
|
|
return PNG.sync.write(png);
|
2022-02-24 00:17:37 +03:00
|
|
|
}
|
2022-07-05 20:46:30 +03:00
|
|
|
|
|
|
|
export function allTests(result: RunResult) {
|
|
|
|
const tests: { title: string; expectedStatus: JSONReportTest['expectedStatus'], actualStatus: JSONReportTest['status'], annotations: string[] }[] = [];
|
|
|
|
const visit = (suite: JSONReportSuite) => {
|
|
|
|
for (const spec of suite.specs)
|
|
|
|
spec.tests.forEach(t => tests.push({ title: spec.title, expectedStatus: t.expectedStatus, actualStatus: t.status, annotations: t.annotations.map(a => a.type) }));
|
|
|
|
suite.suites?.forEach(s => visit(s));
|
|
|
|
};
|
|
|
|
visit(result.report.suites[0]);
|
|
|
|
return tests;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function expectTestHelper(result: RunResult) {
|
|
|
|
return (title: string, expectedStatus: string, status: string, annotations: any) => {
|
|
|
|
const tests = allTests(result).filter(t => t.title === title);
|
|
|
|
for (const test of tests) {
|
|
|
|
expect(test.expectedStatus, `title: ${title}`).toBe(expectedStatus);
|
|
|
|
expect(test.actualStatus, `title: ${title}`).toBe(status);
|
|
|
|
expect(test.annotations, `title: ${title}`).toEqual(annotations);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|