Skip to content

Commit

Permalink
test: move remaining files from old test/ directory (microsoft#6081)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Apr 5, 2021
1 parent 8e6639b commit 5afe282
Show file tree
Hide file tree
Showing 196 changed files with 109 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Wrap `npm run` in a subshell to redirect STDERR to file.
# Enable core dumps in the subshell.
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && npm run test -- ${{ matrix.browser }} --reporter=dot,json"
- run: node test/checkCoverage.js ${{ matrix.browser }}
- run: node tests/config/checkCoverage.js ${{ matrix.browser }}
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always() && github.repository == 'microsoft/playwright' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-'))
- uses: actions/upload-artifact@v1
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules/
/test-results/
/test/coverage-report
/tests/coverage-report
.local-browsers/
/.dev_profile*
Expand All @@ -9,13 +8,11 @@
*.pyc
.vscode
yarn.lock
/node6
/src/generated/*
lib/
jest-report.json
drivers/
.android-sdk/
.gradle/
nohup.out
api.json
.trace
.trace
2 changes: 1 addition & 1 deletion src/utils/stackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function captureStackTrace(): { stack: string, frames: StackFrame[] } {
// for tests.
if (isUnderTest() && fileName.includes(path.join('playwright', 'src')))
continue;
if (isUnderTest() && fileName.includes(path.join('playwright', 'test', 'coverage.js')))
if (isUnderTest() && fileName.includes(path.join('playwright', 'tests', 'config', 'coverage.js')))
continue;
frames.push({
file: fileName,
Expand Down
13 changes: 0 additions & 13 deletions test/tsconfig.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions tests/browsercontext-add-init-script.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import { contextTest as it, expect } from './config/browserTest';
import path from 'path';

it('should work with browser context scripts', async ({ context, server }) => {
await context.addInitScript(() => window['temp'] = 123);
Expand Down Expand Up @@ -53,8 +52,8 @@ it('should work without navigation in popup', async ({ context }) => {
expect(await popup.evaluate(() => window['temp'])).toBe(123);
});

it('should work with browser context scripts with a path', async ({ context, server }) => {
await context.addInitScript({ path: path.join(__dirname, '../test/assets/injectedfile.js') });
it('should work with browser context scripts with a path', async ({ context, server, asset }) => {
await context.addInitScript({ path: asset('injectedfile.js') });
const page = await context.newPage();
await page.goto(server.PREFIX + '/tamperable.html');
expect(await page.evaluate(() => window['result'])).toBe(123);
Expand Down
2 changes: 1 addition & 1 deletion tests/browsercontext-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/browserTest';
import { verifyViewport } from '../test/utils';
import { verifyViewport } from './config/utils';

it('should create new context', async function({browser}) {
expect(browser.contexts().length).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion tests/browsercontext-csp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/browserTest';
import { attachFrame } from '../test/utils';
import { attachFrame } from './config/utils';

it('should bypass CSP meta tag', async ({browser, server}) => {
// Make sure CSP prohibits addScriptTag.
Expand Down
2 changes: 1 addition & 1 deletion tests/browsercontext-user-agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/browserTest';
import { attachFrame } from '../test/utils';
import { attachFrame } from './config/utils';

it('should work', async ({browser, server}) => {
{
Expand Down
2 changes: 1 addition & 1 deletion tests/browsercontext-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { test as it, expect } from './config/pageTest';
import { test as browserTest } from './config/browserTest';
import { verifyViewport } from '../test/utils';
import { verifyViewport } from './config/utils';

it.beforeEach(async () => {
it.skip(!!process.env.PW_ANDROID_TESTS);
Expand Down
5 changes: 2 additions & 3 deletions tests/browsertype-launch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import path from 'path';
import { test as it, slowTest, expect } from './config/playwrightTest';

it('should reject all promises when browser is closed', async ({browserType, browserOptions}) => {
Expand Down Expand Up @@ -64,8 +63,8 @@ it('should throw if page argument is passed', async ({browserType, browserOption
expect(waitError.message).toContain('can not specify page');
});

it('should reject if launched browser fails immediately', async ({browserType, browserOptions}) => {
const options = Object.assign({}, browserOptions, {executablePath: path.join(__dirname, '..', 'test', 'assets', 'dummy_bad_browser_executable.js')});
it('should reject if launched browser fails immediately', async ({browserType, browserOptions, asset}) => {
const options = Object.assign({}, browserOptions, {executablePath: asset('dummy_bad_browser_executable.js')});
let waitError = null;
await browserType.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('== logs ==');
Expand Down
9 changes: 4 additions & 5 deletions tests/chromium/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { test as it, expect } from '../config/playwrightTest';
import path from 'path';

it.beforeEach(async ({ browserName }) => {
it.skip(browserName !== 'chromium');
Expand Down Expand Up @@ -57,9 +56,9 @@ it('should open devtools when "devtools: true" option is given', async ({browser
await browser.close();
});

it('should return background pages', async ({browserType, browserOptions, createUserDataDir}) => {
it('should return background pages', async ({browserType, browserOptions, createUserDataDir, asset}) => {
const userDataDir = await createUserDataDir();
const extensionPath = path.join(__dirname, '..', '..', 'test', 'assets', 'simple-extension');
const extensionPath = asset('simple-extension');
const extensionOptions = {...browserOptions,
headless: false,
args: [
Expand All @@ -78,9 +77,9 @@ it('should return background pages', async ({browserType, browserOptions, create
await context.close();
});

it('should return background pages when recording video', async ({browserType, browserOptions, createUserDataDir}, testInfo) => {
it('should return background pages when recording video', async ({browserType, browserOptions, createUserDataDir, asset}, testInfo) => {
const userDataDir = await createUserDataDir();
const extensionPath = path.join(__dirname, '..', '..', 'test', 'assets', 'simple-extension');
const extensionPath = asset('simple-extension');
const extensionOptions = {...browserOptions,
headless: false,
args: [
Expand Down
12 changes: 6 additions & 6 deletions tests/cli/cli-codegen-2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ await page.CloseAsync();`);
expect(errors.length).toBe(0);
});

test('should upload a single file', async ({ page, openRecorder, browserName }) => {
test('should upload a single file', async ({ page, openRecorder, browserName, asset }) => {
test.fixme(browserName === 'firefox', 'Hangs');

const recorder = await openRecorder();
Expand All @@ -128,7 +128,7 @@ await page.CloseAsync();`);
`);

await page.focus('input[type=file]');
await page.setInputFiles('input[type=file]', 'test/assets/file-to-upload.txt');
await page.setInputFiles('input[type=file]', asset('file-to-upload.txt'));
await page.click('input[type=file]');

const sources = await recorder.waitForOutput('<javascript>', 'setInputFiles');
Expand All @@ -155,7 +155,7 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", \"file-to-upload.txt

});

test('should upload multiple files', async ({ page, openRecorder, browserName }) => {
test('should upload multiple files', async ({ page, openRecorder, browserName, asset }) => {
test.fixme(browserName === 'firefox', 'Hangs');

const recorder = await openRecorder();
Expand All @@ -166,7 +166,7 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", \"file-to-upload.txt
`);

await page.focus('input[type=file]');
await page.setInputFiles('input[type=file]', ['test/assets/file-to-upload.txt', 'test/assets/file-to-upload-2.txt']);
await page.setInputFiles('input[type=file]', [asset('file-to-upload.txt'), asset('file-to-upload-2.txt')]);
await page.click('input[type=file]');

const sources = await recorder.waitForOutput('<javascript>', 'setInputFiles');
Expand All @@ -192,7 +192,7 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", \"file-to-upload.txt
await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", new[] { \"file-to-upload.txt\", \"file-to-upload-2.txt\" });`);
});

test('should clear files', async ({ page, openRecorder, browserName }) => {
test('should clear files', async ({ page, openRecorder, browserName, asset }) => {
test.fixme(browserName === 'firefox', 'Hangs');

const recorder = await openRecorder();
Expand All @@ -202,7 +202,7 @@ await page.SetInputFilesAsync(\"input[type=\\\"file\\\"]\", new[] { \"file-to-up
</form>
`);
await page.focus('input[type=file]');
await page.setInputFiles('input[type=file]', 'test/assets/file-to-upload.txt');
await page.setInputFiles('input[type=file]', asset('file-to-upload.txt'));
await page.setInputFiles('input[type=file]', []);
await page.click('input[type=file]');

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli-codegen-csharp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import path from 'path';
import fs from 'fs';
import { test, expect } from '../config/cliTest';

const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'test', 'assets', 'empty.html')).toString();
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {
return channel ? `headless: false,\n channel: "${channel}"` : 'headless: false';
};
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli-codegen-java.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import { test, expect } from '../config/cliTest';

const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'test', 'assets', 'empty.html')).toString();
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {
return channel ? `.setHeadless(false)\n .setChannel("${channel}")` : '.setHeadless(false)';
};
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli-codegen-javascript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import { test, expect } from '../config/cliTest';

const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'test', 'assets', 'empty.html')).toString();
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();

const launchOptions = (channel: string) => {
return channel ? `headless: false,\n channel: '${channel}'` : 'headless: false';
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli-codegen-python-async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import { test, expect } from '../config/cliTest';

const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'test', 'assets', 'empty.html')).toString();
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {
return channel ? `headless=False, channel="${channel}"` : 'headless=False';
};
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli-codegen-python.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import fs from 'fs';
import path from 'path';
import { test, expect } from '../config/cliTest';

const emptyHTML = new URL('file://' + path.join(__dirname, '..', '..', 'test', 'assets', 'empty.html')).toString();
const emptyHTML = new URL('file://' + path.join(__dirname, '..', 'assets', 'empty.html')).toString();
const launchOptions = (channel: string) => {
return channel ? `headless=False, channel="${channel}"` : 'headless=False';
};
Expand Down
4 changes: 2 additions & 2 deletions tests/config/browserEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { Env, WorkerInfo, TestInfo } from 'folio';
import type { Browser, BrowserContext, BrowserContextOptions, BrowserType, LaunchOptions } from '../../index';
import { installCoverageHooks } from '../../test/coverage';
import { installCoverageHooks } from './coverage';
import { start } from '../../lib/outofprocess';
import { PlaywrightClient } from '../../lib/remote/playwrightClient';
import { removeFolders } from '../../lib/utils/utils';
Expand Down Expand Up @@ -202,7 +202,7 @@ export class PlaywrightEnv implements Env<PlaywrightTestArgs> {
await this._mode.teardown();
const { coverage, uninstall } = this._coverage!;
uninstall();
const coveragePath = path.join(__dirname, '..', '..', 'test', 'coverage-report', workerInfo.workerIndex + '.json');
const coveragePath = path.join(__dirname, '..', 'coverage-report', workerInfo.workerIndex + '.json');
const coverageJSON = Array.from(coverage.keys()).filter(key => coverage.get(key));
await fs.promises.mkdir(path.dirname(coveragePath), { recursive: true });
await fs.promises.writeFile(coveragePath, JSON.stringify(coverageJSON, undefined, 2), 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion test/checkCoverage.js → tests/config/checkCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (browserName === 'webkit')
// Android coverage is abysmal.
api = new Set(Array.from(api).filter(name => !name.toLowerCase().startsWith('android')));

const coverageDir = path.join(__dirname, 'coverage-report');
const coverageDir = path.join(__dirname, '..', 'coverage-report');

const coveredMethods = new Set();
for (const file of getCoverageFiles(coverageDir)) {
Expand Down
4 changes: 2 additions & 2 deletions test/coverage.js → tests/config/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function traceAPICoverage(apiCoverage, api, events) {
* @param {string} browserName
*/
function apiForBrowser(browserName) {
const events = require('../lib/client/events').Events;
const api = require('../lib/client/api');
const events = require('../../lib/client/events').Events;
const api = require('../../lib/client/api');
const otherBrowsers = ['chromium', 'webkit', 'firefox'].filter(name => name.toLowerCase() !== browserName.toLowerCase());
const filteredKeys = Object.keys(api).filter(apiName => {
if (apiName.toLowerCase().startsWith('electron'))
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/config/serverEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class ServerEnv implements Env<ServerTestArgs> {
private _socksPort: number;

async beforeAll(workerInfo: WorkerInfo) {
const assetsPath = path.join(__dirname, '..', '..', 'test', 'assets');
const cachedPath = path.join(__dirname, '..', '..', 'test', 'assets', 'cached');
const assetsPath = path.join(__dirname, '..', 'assets');
const cachedPath = path.join(__dirname, '..', 'assets', 'cached');

const port = 8907 + workerInfo.workerIndex * 3;
this._server = await TestServer.create(assetsPath, port);
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ServerEnv implements Env<ServerTestArgs> {
this._server.reset();
this._httpsServer.reset();
return {
asset: (p: string) => path.join(__dirname, '..', '..', 'test', 'assets', p),
asset: (p: string) => path.join(__dirname, '..', 'assets', ...p.split('/')),
server: this._server,
httpsServer: this._httpsServer,
socksPort: this._socksPort,
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts → tests/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { expect } from 'folio';
import type { Frame, Page } from '../index';
import type { Frame, Page } from '../../index';

export async function attachFrame(page: Page, frameId: string, url: string): Promise<Frame> {
const handle = await page.evaluateHandle(async ({ frameId, url }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/defaultbrowsercontext-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/playwrightTest';
import { verifyViewport } from '../test/utils';
import { verifyViewport } from './config/utils';
import fs from 'fs';

it('context.cookies() should work', async ({server, launchPersistent}) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/elementhandle-content-frame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/pageTest';
import { attachFrame } from '../test/utils';
import { attachFrame } from './config/utils';

it('should work', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
Expand Down
2 changes: 1 addition & 1 deletion tests/elementhandle-owner-frame.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { test as it, expect } from './config/pageTest';
import { attachFrame } from '../test/utils';
import { attachFrame } from './config/utils';

it('should work', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
Expand Down
2 changes: 1 addition & 1 deletion tests/elementhandle-screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { test as it, expect } from './config/pageTest';
import { test as browserTest } from './config/browserTest';
import { verifyViewport } from '../test/utils';
import { verifyViewport } from './config/utils';
import {PNG} from 'pngjs';
import path from 'path';
import fs from 'fs';
Expand Down
2 changes: 1 addition & 1 deletion tests/emulation-focus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { test as it, expect } from './config/pageTest';
import { test as browserTest } from './config/browserTest';
import { attachFrame } from '../test/utils';
import { attachFrame } from './config/utils';

it('should think that it is focused by default', async ({page}) => {
expect(await page.evaluate('document.hasFocus()')).toBe(true);
Expand Down
5 changes: 2 additions & 3 deletions tests/favicon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
* limitations under the License.
*/

import path from 'path';
import { test as it } from './config/browserTest';

it('should load svg favicon with prefer-color-scheme', async ({contextFactory, server, browserName, browserChannel, headful}) => {
it('should load svg favicon with prefer-color-scheme', async ({contextFactory, server, browserName, browserChannel, headful, asset}) => {
it.skip(!headful && browserName !== 'firefox', 'headless browsers, except firefox, do not request favicons');
it.skip(headful && browserName === 'webkit' && !browserChannel, 'playwright headful webkit does not have a favicon feature');

Expand All @@ -29,7 +28,7 @@ it('should load svg favicon with prefer-color-scheme', async ({contextFactory, s
// `d` parameter to make iterating on this test more predictable and isolated.
const favicon = `/favicon.svg?d=${Date.now()}`;
server.setRoute(favicon, (req, res) => {
server.serveFile(req, res, path.join(__dirname, 'assets', 'media-query-prefers-color-scheme.svg'));
server.serveFile(req, res, asset('media-query-prefers-color-scheme.svg'));
});

server.setRoute('/page.html', (_, res) => {
Expand Down
Loading

0 comments on commit 5afe282

Please sign in to comment.