2021-09-01 22:20:28 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-15 01:48:05 +03:00
|
|
|
|
import { test as baseTest, expect } from './playwright-test-fixtures';
|
2021-10-22 22:59:52 +03:00
|
|
|
|
import { HttpServer } from 'playwright-core/lib/utils/httpServer';
|
2021-10-23 21:23:39 +03:00
|
|
|
|
import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html';
|
2021-09-01 22:20:28 +03:00
|
|
|
|
|
2021-10-15 01:48:05 +03:00
|
|
|
|
const test = baseTest.extend<{ showReport: () => Promise<void> }>({
|
|
|
|
|
showReport: async ({ page }, use, testInfo) => {
|
2021-10-23 21:23:39 +03:00
|
|
|
|
let server: HttpServer;
|
2021-10-15 01:48:05 +03:00
|
|
|
|
await use(async () => {
|
|
|
|
|
const reportFolder = testInfo.outputPath('playwright-report');
|
2021-10-23 21:23:39 +03:00
|
|
|
|
server = startHtmlReportServer(reportFolder);
|
2021-10-15 01:48:05 +03:00
|
|
|
|
const location = await server.start();
|
|
|
|
|
await page.goto(location);
|
|
|
|
|
});
|
|
|
|
|
await server.stop();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-10 02:12:37 +03:00
|
|
|
|
test.use({ channel: 'chrome' });
|
|
|
|
|
|
2021-11-02 02:14:52 +03:00
|
|
|
|
test('should generate report', async ({ runInlineTest, showReport, page }) => {
|
2021-09-15 02:26:31 +03:00
|
|
|
|
await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { name: 'project-name' };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({}) => {});
|
|
|
|
|
test('fails', async ({}) => {
|
|
|
|
|
expect(1).toBe(2);
|
|
|
|
|
});
|
2021-11-02 02:14:52 +03:00
|
|
|
|
test('skipped', async ({}) => {
|
2021-09-15 02:26:31 +03:00
|
|
|
|
test.skip('Does not work')
|
|
|
|
|
});
|
|
|
|
|
test('flaky', async ({}, testInfo) => {
|
|
|
|
|
expect(testInfo.retry).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
`,
|
2021-10-15 01:48:05 +03:00
|
|
|
|
}, { reporter: 'dot,html', retries: 1 });
|
2021-09-15 02:26:31 +03:00
|
|
|
|
|
2021-11-02 02:14:52 +03:00
|
|
|
|
await showReport();
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('4');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('1');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('1');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Flaky") .counter')).toHaveText('1');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Skipped") .counter')).toHaveText('1');
|
|
|
|
|
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.test-file-test-outcome-unexpected >> text=fails')).toBeVisible();
|
|
|
|
|
await expect(page.locator('.test-file-test-outcome-flaky >> text=flaky')).toBeVisible();
|
|
|
|
|
await expect(page.locator('.test-file-test-outcome-expected >> text=passes')).toBeVisible();
|
|
|
|
|
await expect(page.locator('.test-file-test-outcome-skipped >> text=skipped')).toBeVisible();
|
2021-09-15 02:26:31 +03:00
|
|
|
|
});
|
|
|
|
|
|
2021-11-18 05:03:13 +03:00
|
|
|
|
test('should not throw when attachment is missing', async ({ runInlineTest, page, showReport }, testInfo) => {
|
2021-09-01 22:20:28 +03:00
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { preserveOutput: 'failures-only' };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({ page }, testInfo) => {
|
|
|
|
|
const screenshot = testInfo.outputPath('screenshot.png');
|
|
|
|
|
await page.screenshot({ path: screenshot });
|
|
|
|
|
testInfo.attachments.push({ name: 'screenshot', path: screenshot, contentType: 'image/png' });
|
|
|
|
|
});
|
|
|
|
|
`,
|
2021-10-15 01:48:05 +03:00
|
|
|
|
}, { reporter: 'dot,html' });
|
2021-09-01 22:20:28 +03:00
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
2021-11-18 05:03:13 +03:00
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=passes');
|
|
|
|
|
await page.locator('text=Missing attachment "screenshot"').click();
|
|
|
|
|
const screenshotFile = testInfo.outputPath('test-results' , 'a-passes', 'screenshot.png');
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.attachment-link')).toHaveText(`Attachment file ${screenshotFile} is missing`);
|
2021-09-01 22:20:28 +03:00
|
|
|
|
});
|
2021-10-15 01:48:05 +03:00
|
|
|
|
|
|
|
|
|
test('should include image diff', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const expected = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAAhVJREFUeJzt07ERwCAQwLCQ/Xd+FuDcQiFN4MZrZuYDjv7bAfAyg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAgEg0AwCASDQDAIBINAMAiEDVPZBYx6ffy+AAAAAElFTkSuQmCC', 'base64');
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = { use: { viewport: { width: 200, height: 200 }} };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js-snapshots/expected-linux.png': expected,
|
|
|
|
|
'a.test.js-snapshots/expected-darwin.png': expected,
|
|
|
|
|
'a.test.js-snapshots/expected-win32.png': expected,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('fails', async ({ page }, testInfo) => {
|
|
|
|
|
await page.setContent('<html>Hello World</html>');
|
|
|
|
|
const screenshot = await page.screenshot();
|
|
|
|
|
await expect(screenshot).toMatchSnapshot('expected.png');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=fails');
|
2021-12-13 01:56:12 +03:00
|
|
|
|
const imageDiff = page.locator('data-testid=test-result-image-mismatch');
|
2021-10-15 01:48:05 +03:00
|
|
|
|
const image = imageDiff.locator('img');
|
|
|
|
|
await expect(image).toHaveAttribute('src', /.*png/);
|
|
|
|
|
const actualSrc = await image.getAttribute('src');
|
|
|
|
|
await imageDiff.locator('text=Expected').click();
|
|
|
|
|
const expectedSrc = await image.getAttribute('src');
|
|
|
|
|
await imageDiff.locator('text=Diff').click();
|
|
|
|
|
const diffSrc = await image.getAttribute('src');
|
|
|
|
|
const set = new Set([expectedSrc, actualSrc, diffSrc]);
|
|
|
|
|
expect(set.size).toBe(3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should include screenshot on failure', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.ts': `
|
|
|
|
|
module.exports = {
|
|
|
|
|
use: {
|
|
|
|
|
viewport: { width: 200, height: 200 },
|
|
|
|
|
screenshot: 'only-on-failure',
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('fails', async ({ page }) => {
|
|
|
|
|
await page.setContent('<html>Failed state</html>');
|
|
|
|
|
await expect(true).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=fails');
|
|
|
|
|
await expect(page.locator('text=Screenshots')).toBeVisible();
|
|
|
|
|
await expect(page.locator('img')).toBeVisible();
|
|
|
|
|
const src = await page.locator('img').getAttribute('src');
|
|
|
|
|
expect(src).toBeTruthy();
|
|
|
|
|
});
|
2021-10-16 02:15:06 +03:00
|
|
|
|
|
|
|
|
|
test('should include stdio', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('fails', async ({ page }) => {
|
|
|
|
|
console.log('First line');
|
|
|
|
|
console.log('Second line');
|
|
|
|
|
console.error('Third line');
|
|
|
|
|
await expect(true).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=fails');
|
|
|
|
|
await page.locator('text=stdout').click();
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.attachment-link')).toHaveText('First line\nSecond line');
|
2021-10-16 02:15:06 +03:00
|
|
|
|
await page.locator('text=stderr').click();
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.attachment-link').nth(1)).toHaveText('Third line');
|
2021-10-16 02:15:06 +03:00
|
|
|
|
});
|
2021-10-19 07:37:19 +03:00
|
|
|
|
|
|
|
|
|
test('should highlight error', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('fails', async ({ page }) => {
|
|
|
|
|
await expect(true).toBeFalsy();
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=fails');
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.test-result-error-message span:has-text("received")').nth(1)).toHaveCSS('color', 'rgb(204, 0, 0)');
|
2021-10-19 07:37:19 +03:00
|
|
|
|
});
|
2021-10-23 21:23:39 +03:00
|
|
|
|
|
|
|
|
|
test('should show trace source', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = { use: { trace: 'on' } };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({ page }) => {
|
|
|
|
|
await page.evaluate('2 + 2');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=passes');
|
|
|
|
|
await page.click('img');
|
|
|
|
|
await page.click('.action-title >> text=page.evaluate');
|
|
|
|
|
await page.click('text=Source');
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('.source-line')).toContainText([
|
|
|
|
|
/const.*pwt;/,
|
|
|
|
|
/page\.evaluate/
|
|
|
|
|
]);
|
|
|
|
|
await expect(page.locator('.source-line-running')).toContainText('page.evaluate');
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('.stack-trace-frame')).toContainText([
|
|
|
|
|
/a.test.js:[\d]+/,
|
|
|
|
|
]);
|
|
|
|
|
await expect(page.locator('.stack-trace-frame.selected')).toContainText('a.test.js');
|
|
|
|
|
});
|
2021-11-02 07:23:35 +03:00
|
|
|
|
|
|
|
|
|
test('should show trace title', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = { use: { trace: 'on' } };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passes', async ({ page }) => {
|
|
|
|
|
await page.evaluate('2 + 2');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=passes');
|
|
|
|
|
await page.click('img');
|
|
|
|
|
await expect(page.locator('.workbench .title')).toHaveText('a.test.js:6 › passes');
|
|
|
|
|
});
|
2021-12-08 03:47:47 +03:00
|
|
|
|
|
|
|
|
|
test('should show timed out steps', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
2021-12-14 00:32:53 +03:00
|
|
|
|
module.exports = { timeout: 3000 };
|
2021-12-08 03:47:47 +03:00
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('fails', async ({ page }) => {
|
|
|
|
|
await test.step('outer step', async () => {
|
|
|
|
|
await test.step('inner step', async () => {
|
|
|
|
|
await new Promise(() => {});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=fails');
|
|
|
|
|
await page.click('text=outer step');
|
|
|
|
|
await expect(page.locator('.tree-item:has-text("outer step") svg.color-text-danger')).toHaveCount(2);
|
|
|
|
|
await expect(page.locator('.tree-item:has-text("inner step") svg.color-text-danger')).toHaveCount(2);
|
|
|
|
|
});
|
2021-12-08 05:35:06 +03:00
|
|
|
|
|
|
|
|
|
test('should render annotations', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'playwright.config.js': `
|
|
|
|
|
module.exports = { timeout: 1500 };
|
|
|
|
|
`,
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('skipped test', async ({ page }) => {
|
|
|
|
|
test.skip(true, 'I am not interested in this test');
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
expect(result.skipped).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=skipped test');
|
|
|
|
|
await expect(page.locator('.test-case-annotation')).toHaveText('skip: I am not interested in this test');
|
|
|
|
|
});
|
2021-12-08 19:51:44 +03:00
|
|
|
|
|
2021-12-15 21:39:49 +03:00
|
|
|
|
test('should render beforeAll/afterAll hooks', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
2021-12-16 03:06:10 +03:00
|
|
|
|
test.use({ trace: 'on' });
|
2021-12-15 21:39:49 +03:00
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
|
});
|
2021-12-16 03:06:10 +03:00
|
|
|
|
test.afterAll(async ({ browser }) => {
|
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
await page.close();
|
2021-12-15 21:39:49 +03:00
|
|
|
|
await test.step('after step', () => {
|
|
|
|
|
throw new Error('oh!');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
test('test', async ({}) => {
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("All") .counter')).toHaveText('1');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Passed") .counter')).toHaveText('1');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Failed") .counter')).toHaveText('0');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Flaky") .counter')).toHaveText('0');
|
|
|
|
|
await expect(page.locator('.subnav-item:has-text("Skipped") .counter')).toHaveText('0');
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('text=beforeAll')).toBeVisible();
|
|
|
|
|
await expect(page.locator('.test-file-test:has-text("beforeAll") svg.color-icon-success')).toHaveCount(1);
|
|
|
|
|
|
|
|
|
|
await expect(page.locator('text=afterAll')).toBeVisible();
|
|
|
|
|
await expect(page.locator('.test-file-test:has-text("afterAll") svg.color-text-danger')).toHaveCount(1);
|
|
|
|
|
|
|
|
|
|
await page.click('text=afterAll');
|
|
|
|
|
await expect(page.locator('.tree-item:has-text("after step") svg.color-text-danger')).toHaveCount(1);
|
2021-12-16 03:06:10 +03:00
|
|
|
|
await expect(page.locator('img')).toBeVisible();
|
2021-12-15 21:39:49 +03:00
|
|
|
|
});
|
|
|
|
|
|
2021-12-08 19:51:44 +03:00
|
|
|
|
test('should render text attachments as text', async ({ runInlineTest, page, showReport }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'a.test.js': `
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
test('passing', async ({ page }, testInfo) => {
|
|
|
|
|
testInfo.attachments.push({
|
|
|
|
|
name: 'example.txt',
|
|
|
|
|
contentType: 'text/plain',
|
|
|
|
|
body: Buffer.from('foo'),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInfo.attachments.push({
|
|
|
|
|
name: 'example.json',
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
body: Buffer.from(JSON.stringify({ foo: 1 })),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInfo.attachments.push({
|
|
|
|
|
name: 'example-utf16.txt',
|
|
|
|
|
contentType: 'text/plain, charset=utf16le',
|
|
|
|
|
body: Buffer.from('utf16 encoded', 'utf16le'),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
testInfo.attachments.push({
|
|
|
|
|
name: 'example-null.txt',
|
|
|
|
|
contentType: 'text/plain, charset=utf16le',
|
|
|
|
|
body: null,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
|
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text=passing');
|
|
|
|
|
await page.click('text=example.txt');
|
|
|
|
|
await page.click('text=example.json');
|
|
|
|
|
await page.click('text=example-utf16.txt');
|
2021-12-13 01:56:12 +03:00
|
|
|
|
await expect(page.locator('.attachment-link')).toHaveText(['foo', '{"foo":1}', 'utf16 encoded']);
|
2021-12-08 19:51:44 +03:00
|
|
|
|
});
|
2021-12-28 20:56:34 +03:00
|
|
|
|
|
|
|
|
|
test('should strikethough textual diff', async ({ runInlineTest, showReport, page }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
|
|
|
|
export const test = pwt.test.extend({
|
|
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
|
testInfo.snapshotSuffix = '';
|
|
|
|
|
await run();
|
|
|
|
|
}, { auto: true } ]
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'a.spec.js-snapshots/snapshot.txt': `old`,
|
|
|
|
|
'a.spec.js': `
|
|
|
|
|
const { test } = require('./helper');
|
|
|
|
|
test('is a test', ({}) => {
|
|
|
|
|
expect('new').toMatchSnapshot('snapshot.txt');
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text="is a test"');
|
|
|
|
|
const stricken = await page.locator('css=strike').innerText();
|
|
|
|
|
expect(stricken).toBe('old');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should strikethough textual diff with commonalities', async ({ runInlineTest, showReport, page }) => {
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
|
'helper.ts': `
|
|
|
|
|
export const test = pwt.test.extend({
|
|
|
|
|
auto: [ async ({}, run, testInfo) => {
|
|
|
|
|
testInfo.snapshotSuffix = '';
|
|
|
|
|
await run();
|
|
|
|
|
}, { auto: true } ]
|
|
|
|
|
});
|
|
|
|
|
`,
|
|
|
|
|
'a.spec.js-snapshots/snapshot.txt': `oldcommon`,
|
|
|
|
|
'a.spec.js': `
|
|
|
|
|
const { test } = require('./helper');
|
|
|
|
|
test('is a test', ({}) => {
|
|
|
|
|
expect('newcommon').toMatchSnapshot('snapshot.txt');
|
|
|
|
|
});
|
|
|
|
|
`
|
|
|
|
|
}, { reporter: 'dot,html' });
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
|
await showReport();
|
|
|
|
|
await page.click('text="is a test"');
|
|
|
|
|
const stricken = await page.locator('css=strike').innerText();
|
|
|
|
|
expect(stricken).toBe('old');
|
|
|
|
|
});
|