mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 05:37:20 +03:00
92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
|
/**
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
|
import { test, expect } from './playwright-test-fixtures';
|
||
|
|
||
|
test('should work with custom reporter', async ({ runInlineTest }) => {
|
||
|
const result = await runInlineTest({
|
||
|
'reporter.ts': `
|
||
|
class Reporter {
|
||
|
constructor(options) {
|
||
|
this.options = options;
|
||
|
}
|
||
|
onBegin(config, suite) {
|
||
|
console.log('\\n%%reporter-begin-' + this.options.begin + '-' + suite.suites.length + '%%');
|
||
|
}
|
||
|
onTestBegin(test) {
|
||
|
console.log('\\n%%reporter-testbegin-' + test.title + '-' + test.projectName + '%%');
|
||
|
}
|
||
|
onStdOut() {
|
||
|
console.log('\\n%%reporter-stdout%%');
|
||
|
}
|
||
|
onStdErr() {
|
||
|
console.log('\\n%%reporter-stderr%%');
|
||
|
}
|
||
|
onTestEnd(test) {
|
||
|
console.log('\\n%%reporter-testend-' + test.title + '-' + test.projectName + '%%');
|
||
|
}
|
||
|
onTimeout() {
|
||
|
console.log('\\n%%reporter-timeout%%');
|
||
|
}
|
||
|
onError() {
|
||
|
console.log('\\n%%reporter-error%%');
|
||
|
}
|
||
|
async onEnd() {
|
||
|
await new Promise(f => setTimeout(f, 500));
|
||
|
console.log('\\n%%reporter-end-' + this.options.end + '%%');
|
||
|
}
|
||
|
}
|
||
|
export default Reporter;
|
||
|
`,
|
||
|
'playwright.config.ts': `
|
||
|
module.exports = {
|
||
|
reporter: [
|
||
|
[ './reporter.ts', { begin: 'begin', end: 'end' } ]
|
||
|
],
|
||
|
projects: [
|
||
|
{ name: 'foo', repeatEach: 2 },
|
||
|
{ name: 'bar' },
|
||
|
],
|
||
|
};
|
||
|
`,
|
||
|
'a.test.ts': `
|
||
|
const { test } = pwt;
|
||
|
test('pass', async ({}) => {
|
||
|
console.log('log');
|
||
|
console.error('error');
|
||
|
});
|
||
|
`
|
||
|
}, { reporter: '', workers: 1 });
|
||
|
|
||
|
expect(result.exitCode).toBe(0);
|
||
|
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
|
||
|
'%%reporter-begin-begin-3%%',
|
||
|
'%%reporter-testbegin-pass-foo%%',
|
||
|
'%%reporter-stdout%%',
|
||
|
'%%reporter-stderr%%',
|
||
|
'%%reporter-testend-pass-foo%%',
|
||
|
'%%reporter-testbegin-pass-foo%%',
|
||
|
'%%reporter-stdout%%',
|
||
|
'%%reporter-stderr%%',
|
||
|
'%%reporter-testend-pass-foo%%',
|
||
|
'%%reporter-testbegin-pass-bar%%',
|
||
|
'%%reporter-stdout%%',
|
||
|
'%%reporter-stderr%%',
|
||
|
'%%reporter-testend-pass-bar%%',
|
||
|
'%%reporter-end-end%%',
|
||
|
]);
|
||
|
});
|