mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
/**
|
|
* Copyright Microsoft Corporation. All rights reserved.
|
|
*
|
|
* 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, stripAnsi } from './playwright-test-fixtures';
|
|
|
|
test('soft expects should compile', async ({ runTSC }) => {
|
|
const result = await runTSC({
|
|
'a.spec.ts': `
|
|
const { test } = pwt;
|
|
test('should work', () => {
|
|
test.expect.soft(1+1).toBe(3);
|
|
test.expect.soft(1+1, 'custom error message').toBe(3);
|
|
test.expect.soft(1+1, { message: 'custom error message' }).toBe(3);
|
|
});
|
|
`
|
|
});
|
|
expect(result.exitCode).toBe(0);
|
|
});
|
|
|
|
test('soft expects should work', async ({ runInlineTest }) => {
|
|
const result = await runInlineTest({
|
|
'a.spec.ts': `
|
|
const { test } = pwt;
|
|
test('should work', () => {
|
|
test.expect.soft(1+1).toBe(3);
|
|
console.log('woof-woof');
|
|
});
|
|
`
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(stripAnsi(result.output)).toContain('woof-woof');
|
|
});
|
|
|
|
test('should report a mixture of soft and non-soft errors', async ({ runInlineTest }) => {
|
|
const result = await runInlineTest({
|
|
'a.spec.ts': `
|
|
const { test } = pwt;
|
|
test('should work', ({}) => {
|
|
test.expect.soft(1+1, 'one plus one').toBe(3);
|
|
test.expect.soft(2*2, 'two times two').toBe(5);
|
|
test.expect(3/3, 'three div three').toBe(7);
|
|
test.expect.soft(6-4, { message: 'six minus four' }).toBe(3);
|
|
});
|
|
`
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(stripAnsi(result.output)).toContain('Error: one plus one');
|
|
expect(stripAnsi(result.output)).toContain('Error: two times two');
|
|
expect(stripAnsi(result.output)).toContain('Error: three div three');
|
|
expect(stripAnsi(result.output)).not.toContain('Error: six minus four');
|
|
});
|
|
|
|
test('testInfo should contain all soft expect errors', async ({ runInlineTest }) => {
|
|
const result = await runInlineTest({
|
|
'a.spec.ts': `
|
|
const { test } = pwt;
|
|
test('should work', ({}, testInfo) => {
|
|
test.expect.soft(1+1, 'one plus one').toBe(3);
|
|
test.expect.soft(2*2, 'two times two').toBe(5);
|
|
test.expect(testInfo.errors.length, 'must be exactly two errors').toBe(2);
|
|
});
|
|
`
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(stripAnsi(result.output)).toContain('Error: one plus one');
|
|
expect(stripAnsi(result.output)).toContain('Error: two times two');
|
|
expect(stripAnsi(result.output)).not.toContain('Error: must be exactly two errors');
|
|
});
|