chore: fix only for skipped tests (#9964)

This commit is contained in:
Nikolay Vitkov 2023-04-04 09:37:15 +02:00 committed by GitHub
parent 449d1f1ead
commit fe934ad092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 34 deletions

View File

@ -27,7 +27,7 @@ import {
setupTestBrowserHooks, setupTestBrowserHooks,
setupTestPageAndContextHooks, setupTestPageAndContextHooks,
} from './mocha-utils.js'; } from './mocha-utils.js';
import utils from './utils.js'; import {attachFrame, isFavicon} from './utils.js';
describe('network', function () { describe('network', function () {
setupTestBrowserHooks(); setupTestBrowserHooks();
@ -39,9 +39,9 @@ describe('network', function () {
const requests: HTTPRequest[] = []; const requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(requests.length).toBe(1); expect(requests.length).toBe(1);
}); });
it('should fire for iframes', async () => { it('should fire for iframes', async () => {
@ -49,10 +49,10 @@ describe('network', function () {
const requests: HTTPRequest[] = []; const requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); await attachFrame(page, 'frame1', server.EMPTY_PAGE);
expect(requests.length).toBe(2); expect(requests.length).toBe(2);
}); });
it('should fire for fetches', async () => { it('should fire for fetches', async () => {
@ -60,9 +60,9 @@ describe('network', function () {
const requests: HTTPRequest[] = []; const requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => { await page.evaluate(() => {
return fetch('/empty.html'); return fetch('/empty.html');
}); });
@ -75,31 +75,31 @@ describe('network', function () {
const requests: HTTPRequest[] = []; const requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(requests.length).toBe(1); expect(requests.length).toBe(1);
expect(requests[0]!.frame()).toBe(page.mainFrame()); expect(requests[0]!.frame()).toBe(page.mainFrame());
}); });
it('should work for subframe navigation request', async () => { it('should work for subframe navigation request', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
const requests: HTTPRequest[] = []; const requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); await attachFrame(page, 'frame1', server.EMPTY_PAGE);
expect(requests.length).toBe(1); expect(requests.length).toBe(1);
expect(requests[0]!.frame()).toBe(page.frames()[1]!); expect(requests[0]!.frame()).toBe(page.frames()[1]!);
}); });
it('should work for fetch requests', async () => { it('should work for fetch requests', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
let requests: HTTPRequest[] = []; let requests: HTTPRequest[] = [];
page.on('request', request => { page.on('request', request => {
return !utils.isFavicon(request) && requests.push(request); return !isFavicon(request) && requests.push(request);
}); });
await page.evaluate(() => { await page.evaluate(() => {
return fetch('/digits/1.png'); return fetch('/digits/1.png');
@ -199,8 +199,7 @@ describe('network', function () {
const responses = new Map(); const responses = new Map();
page.on('response', r => { page.on('response', r => {
return ( return (
!utils.isFavicon(r.request()) && !isFavicon(r.request()) && responses.set(r.url().split('/').pop(), r)
responses.set(r.url().split('/').pop(), r)
); );
}); });
@ -229,9 +228,7 @@ describe('network', function () {
const responses = new Map(); const responses = new Map();
page.on('response', r => { page.on('response', r => {
return ( return !isFavicon(r) && responses.set(r.url().split('/').pop(), r);
!utils.isFavicon(r) && responses.set(r.url().split('/').pop(), r)
);
}); });
// Load and re-load to make sure serviceworker is installed and running. // Load and re-load to make sure serviceworker is installed and running.
@ -255,13 +252,13 @@ describe('network', function () {
it('should work', async () => { it('should work', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
server.setRoute('/post', (_req, res) => { server.setRoute('/post', (_req, res) => {
return res.end(); return res.end();
}); });
let request!: HTTPRequest; let request!: HTTPRequest;
page.on('request', r => { page.on('request', r => {
if (!utils.isFavicon(r)) { if (!isFavicon(r)) {
request = r; request = r;
} }
}); });
@ -319,7 +316,7 @@ describe('network', function () {
it('should wait until response completes', async () => { it('should wait until response completes', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
// Setup server to trap request. // Setup server to trap request.
let serverResponse!: ServerResponse; let serverResponse!: ServerResponse;
server.setRoute('/get', (_req, res) => { server.setRoute('/get', (_req, res) => {
@ -337,7 +334,7 @@ describe('network', function () {
// send request and wait for server response // send request and wait for server response
const [pageResponse] = await Promise.all([ const [pageResponse] = await Promise.all([
page.waitForResponse(r => { page.waitForResponse(r => {
return !utils.isFavicon(r.request()); return !isFavicon(r.request());
}), }),
page.evaluate(() => { page.evaluate(() => {
return fetch('./get', {method: 'GET'}); return fetch('./get', {method: 'GET'});
@ -466,7 +463,7 @@ describe('network', function () {
page.on('response', response => { page.on('response', response => {
return responses.push(response); return responses.push(response);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(responses.length).toBe(1); expect(responses.length).toBe(1);
expect(responses[0]!.timing()!.receiveHeadersEnd).toBeGreaterThan(0); expect(responses[0]!.timing()!.receiveHeadersEnd).toBeGreaterThan(0);
}); });
@ -480,7 +477,7 @@ describe('network', function () {
page.on('request', request => { page.on('request', request => {
return requests.push(request); return requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(requests.length).toBe(1); expect(requests.length).toBe(1);
expect(requests[0]!.url()).toBe(server.EMPTY_PAGE); expect(requests[0]!.url()).toBe(server.EMPTY_PAGE);
expect(requests[0]!.resourceType()).toBe('document'); expect(requests[0]!.resourceType()).toBe('document');
@ -510,7 +507,7 @@ describe('network', function () {
page.on('response', response => { page.on('response', response => {
return responses.push(response); return responses.push(response);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(responses.length).toBe(1); expect(responses.length).toBe(1);
expect(responses[0]!.url()).toBe(server.EMPTY_PAGE); expect(responses[0]!.url()).toBe(server.EMPTY_PAGE);
expect(responses[0]!.status()).toBe(200); expect(responses[0]!.status()).toBe(200);
@ -560,7 +557,7 @@ describe('network', function () {
page.on('requestfinished', request => { page.on('requestfinished', request => {
return requests.push(request); return requests.push(request);
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(requests.length).toBe(1); expect(requests.length).toBe(1);
expect(requests[0]!.url()).toBe(server.EMPTY_PAGE); expect(requests[0]!.url()).toBe(server.EMPTY_PAGE);
expect(requests[0]!.response()).toBeTruthy(); expect(requests[0]!.response()).toBeTruthy();
@ -580,7 +577,7 @@ describe('network', function () {
page.on('requestfinished', () => { page.on('requestfinished', () => {
return events.push('requestfinished'); return events.push('requestfinished');
}); });
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
expect(events).toEqual(['request', 'response', 'requestfinished']); expect(events).toEqual(['request', 'response', 'requestfinished']);
}); });
it('should support redirects', async () => { it('should support redirects', async () => {
@ -661,7 +658,7 @@ describe('network', function () {
page.on('request', request => { page.on('request', request => {
return requests.push(request); return requests.push(request);
}); });
(await page.goto(server.PREFIX + '/pptr.png'))!; await page.goto(server.PREFIX + '/pptr.png');
expect(requests[0]!.isNavigationRequest()).toBe(true); expect(requests[0]!.isNavigationRequest()).toBe(true);
}); });
}); });
@ -807,7 +804,7 @@ describe('network', function () {
it('Same-origin set-cookie subresource', async () => { it('Same-origin set-cookie subresource', async () => {
const {page, server} = getTestState(); const {page, server} = getTestState();
(await page.goto(server.EMPTY_PAGE))!; await page.goto(server.EMPTY_PAGE);
const setCookieString = 'foo=bar'; const setCookieString = 'foo=bar';
server.setRoute('/foo', (_req, res) => { server.setRoute('/foo', (_req, res) => {

View File

@ -66,6 +66,7 @@ function customBDDInterface(suite: Mocha.Suite) {
title: title, title: title,
file: file, file: file,
fn: fn, fn: fn,
isOnly: true,
}); });
}; };
@ -81,12 +82,21 @@ function customBDDInterface(suite: Mocha.Suite) {
// @ts-ignore // @ts-ignore
context['describe'] = describe; context['describe'] = describe;
function it(title: string, fn: Mocha.TestFunction) { function it(title: string, fn: Mocha.TestFunction, itOnly = false) {
const suite = suites[0]!; const suite = suites[0]!;
const test = new Mocha.Test(title, suite.isPending() ? undefined : fn); const test = new Mocha.Test(title, suite.isPending() ? undefined : fn);
test.file = file; test.file = file;
test.parent = suite; test.parent = suite;
if (shouldSkipTest(test)) {
const describeOnly = Boolean(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
suite.parent?._onlySuites.find(child => {
return child === suite;
})
);
if (shouldSkipTest(test) && !(itOnly || describeOnly)) {
const test = new Mocha.Test(title); const test = new Mocha.Test(title);
test.file = file; test.file = file;
suite.addTest(test); suite.addTest(test);
@ -98,7 +108,10 @@ function customBDDInterface(suite: Mocha.Suite) {
} }
it.only = function (title: string, fn: Mocha.TestFunction) { it.only = function (title: string, fn: Mocha.TestFunction) {
return common.test.only(mocha, context['it'](title, fn)); return common.test.only(
mocha,
(context['it'] as typeof it)(title, fn, true)
);
}; };
it.skip = function (title: string) { it.skip = function (title: string) {