mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00

This patch moves fixtures.js to base.fixtures.ts that sits next to tests. All tests get an extra import to get the base fixtures (both types and implementations).
60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
* Modifications 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.
|
|
*/
|
|
require('./base.fixture');
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const utils = require('./utils');
|
|
const {FFOX, CHROMIUM, WEBKIT, MAC, WIN} = testOptions;
|
|
|
|
it('should fire for navigation requests', async({page, server}) => {
|
|
const requests = [];
|
|
page.on('request', request => requests.push(request));
|
|
await page.goto(server.EMPTY_PAGE);
|
|
expect(requests.length).toBe(1);
|
|
});
|
|
|
|
it('should fire for iframes', async({page, server}) => {
|
|
const requests = [];
|
|
page.on('request', request => requests.push(request));
|
|
await page.goto(server.EMPTY_PAGE);
|
|
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
|
expect(requests.length).toBe(2);
|
|
});
|
|
|
|
it('should fire for fetches', async({page, server}) => {
|
|
const requests = [];
|
|
page.on('request', request => requests.push(request));
|
|
await page.goto(server.EMPTY_PAGE);
|
|
await page.evaluate(() => fetch('/empty.html'));
|
|
expect(requests.length).toBe(2);
|
|
});
|
|
|
|
it('should report requests and responses handled by service worker', async({page, server}) => {
|
|
await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html');
|
|
await page.evaluate(() => window.activationPromise);
|
|
const [swResponse, request] = await Promise.all([
|
|
page.evaluate(() => fetchDummy('foo')),
|
|
page.waitForEvent('request'),
|
|
]);
|
|
expect(swResponse).toBe('responseFromServiceWorker:foo');
|
|
expect(request.url()).toBe(server.PREFIX + '/serviceworkers/fetchdummy/foo');
|
|
const response = await request.response();
|
|
expect(response.url()).toBe(server.PREFIX + '/serviceworkers/fetchdummy/foo');
|
|
expect(await response.text()).toBe('responseFromServiceWorker:foo');
|
|
});
|