diff --git a/test/download.spec.js b/test/download.spec.js index 2969e73965..7796783b1e 100644 --- a/test/download.spec.js +++ b/test/download.spec.js @@ -62,6 +62,7 @@ describe('Download', function() { expect(fs.existsSync(path)).toBeTruthy(); await download.delete(); expect(fs.existsSync(path)).toBeFalsy(); + await page.close(); }); it('should expose stream', async({browser, server}) => { const page = await browser.newPage({ acceptDownloads: true }); @@ -76,6 +77,7 @@ describe('Download', function() { await new Promise(f => stream.on('end', f)); expect(content).toBe('Hello world'); stream.close(); + await page.close(); }); it('should delete downloads on context destruction', async({browser, server}) => { const page = await browser.newPage({ acceptDownloads: true }); diff --git a/test/playwright.spec.js b/test/playwright.spec.js deleted file mode 100644 index 253ef9cd94..0000000000 --- a/test/playwright.spec.js +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright 2019 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. - */ - -const fs = require('fs'); -const path = require('path'); -const rm = require('rimraf').sync; -const readline = require('readline'); -const {TestServer} = require('../utils/testserver/'); -const {Environment} = require('../utils/testrunner/Test'); - -const serverEnvironment = new Environment('TestServer'); -serverEnvironment.beforeAll(async state => { - const assetsPath = path.join(__dirname, 'assets'); - const cachedPath = path.join(__dirname, 'assets', 'cached'); - - const port = 8907 + state.parallelIndex * 3; - state.server = await TestServer.create(assetsPath, port); - state.server.enableHTTPCache(cachedPath); - state.server.PORT = port; - state.server.PREFIX = `http://localhost:${port}`; - state.server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`; - state.server.EMPTY_PAGE = `http://localhost:${port}/empty.html`; - - const httpsPort = port + 1; - state.httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort); - state.httpsServer.enableHTTPCache(cachedPath); - state.httpsServer.PORT = httpsPort; - state.httpsServer.PREFIX = `https://localhost:${httpsPort}`; - state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`; - state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`; - - const sourcePort = port + 2; - state.sourceServer = await TestServer.create(path.join(__dirname, '..'), sourcePort); - state.sourceServer.PORT = sourcePort; - state.sourceServer.PREFIX = `http://localhost:${sourcePort}`; -}); -serverEnvironment.afterAll(async({server, sourceServer, httpsServer}) => { - await Promise.all([ - server.stop(), - httpsServer.stop(), - sourceServer.stop(), - ]); -}); -serverEnvironment.beforeEach(async({server, httpsServer}) => { - server.reset(); - httpsServer.reset(); -}); - -const goldenEnvironment = new Environment('Golden'); -goldenEnvironment.beforeAll(async ({browserType}) => { - const { OUTPUT_DIR, GOLDEN_DIR } = require('./utils').testOptions(browserType); - if (fs.existsSync(OUTPUT_DIR)) - rm(OUTPUT_DIR); - fs.mkdirSync(OUTPUT_DIR, { recursive: true }); - expect.setupGolden(GOLDEN_DIR, OUTPUT_DIR); -}); - -/** - * @type {TestSuite} - */ -module.exports.addPlaywrightTests = ({testRunner, products}) => { - const dumpProtocolOnFailure = valueFromEnv('DEBUGP', false); - const playwrightPath = require('./utils').projectRoot(); - const playwright = require(playwrightPath); - - const playwrightEnvironment = new Environment('Playwright'); - playwrightEnvironment.beforeAll(async state => { - state.playwright = playwright; - global.playwright = playwright; - }); - playwrightEnvironment.afterAll(async state => { - delete state.playwright; - delete global.playwright; - }); - - testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment. - testRunner.collector().useEnvironment(playwrightEnvironment); - - for (const product of products) { - const browserTypeEnvironment = new Environment('BrowserType'); - browserTypeEnvironment.beforeAll(async state => { - state.browserType = state.playwright[product.toLowerCase()]; - }); - browserTypeEnvironment.afterAll(async state => { - delete state.browserType; - }); - - const browserType = playwright[product.toLowerCase()]; - const executablePath = { - 'chromium': process.env.CRPATH, - 'firefox': process.env.FFPATH, - 'webkit': process.env.WKPATH, - }[browserType.name()]; - if (executablePath) { - const YELLOW_COLOR = '\x1b[33m'; - const RESET_COLOR = '\x1b[0m'; - console.warn(`${YELLOW_COLOR}WARN: running ${product} tests with ${executablePath}${RESET_COLOR}`); - browserType._executablePath = executablePath; - } else { - // Make sure the `npm install` was run after the chromium roll. - if (!fs.existsSync(browserType.executablePath())) - throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`); - } - const launchOptions = { - handleSIGINT: false, - slowMo: valueFromEnv('SLOW_MO', 0), - headless: !!valueFromEnv('HEADLESS', true), - }; - - const browserEnvironment = new Environment(product); - browserEnvironment.beforeAll(async state => { - state.browser = await state.browserType.launch(launchOptions); - state.browserServer = state.browser._ownedServer; - state._stdout = readline.createInterface({ input: state.browserServer.process().stdout }); - state._stderr = readline.createInterface({ input: state.browserServer.process().stderr }); - }); - browserEnvironment.afterAll(async state => { - await state.browserServer.close(); - state.browser = null; - state.browserServer = null; - state._stdout.close(); - state._stderr.close(); - }); - browserEnvironment.beforeEach(async(state, testRun) => { - const dumpout = data => testRun.log(`\x1b[33m[pw:stdio:out]\x1b[0m ${data}`); - const dumperr = data => testRun.log(`\x1b[31m[pw:stdio:err]\x1b[0m ${data}`); - state._stdout.on('line', dumpout); - state._stderr.on('line', dumperr); - if (dumpProtocolOnFailure) - state.browser._debugProtocol.log = data => testRun.log(`\x1b[32m[pw:protocol]\x1b[0m ${data}`); - state.tearDown = async () => { - state._stdout.off('line', dumpout); - state._stderr.off('line', dumperr); - if (dumpProtocolOnFailure) - delete state.browser._debugProtocol.log; - }; - }); - browserEnvironment.afterEach(async (state, test) => { - if (state.browser.contexts().length !== 0) { - if (test.result === 'ok') - console.warn(`\nWARNING: test "${test.fullName()}" (${test.location()}) did not close all created contexts!\n`); - await Promise.all(state.browser.contexts().map(context => context.close())); - } - await state.tearDown(); - }); - - const pageEnvironment = new Environment('Page'); - pageEnvironment.beforeEach(async state => { - state.context = await state.browser.newContext(); - state.page = await state.context.newPage(); - }); - pageEnvironment.afterEach(async state => { - await state.context.close(); - state.context = null; - state.page = null; - }); - - function loadTest(path) { - require(path); - delete require.cache[require.resolve(path)]; - } - - describe(product, () => { - // In addition to state, expose these two on global so that describes can access them. - global.playwright = playwright; - global.browserType = browserType; - - testRunner.collector().useEnvironment(browserTypeEnvironment); - testRunner.collector().useEnvironment(goldenEnvironment); // Custom environment. - - describe('', function() { - testRunner.collector().useEnvironment(browserEnvironment); - - describe('', function() { - testRunner.collector().useEnvironment(pageEnvironment); - - // Page-level tests that are given a browser, a context and a page. - // Each test is launched in a new browser context. - loadTest('./accessibility.spec.js'); - loadTest('./autowaiting.spec.js'); - loadTest('./click.spec.js'); - loadTest('./cookies.spec.js'); - loadTest('./dialog.spec.js'); - loadTest('./download.spec.js'); - loadTest('./elementhandle.spec.js'); - loadTest('./emulation.spec.js'); - loadTest('./evaluation.spec.js'); - loadTest('./frame.spec.js'); - loadTest('./focus.spec.js'); - loadTest('./input.spec.js'); - loadTest('./jshandle.spec.js'); - loadTest('./keyboard.spec.js'); - loadTest('./mouse.spec.js'); - loadTest('./navigation.spec.js'); - loadTest('./network.spec.js'); - loadTest('./page.spec.js'); - loadTest('./queryselector.spec.js'); - loadTest('./screenshot.spec.js'); - loadTest('./waittask.spec.js'); - loadTest('./interception.spec.js'); - loadTest('./geolocation.spec.js'); - loadTest('./workers.spec.js'); - loadTest('./capabilities.spec.js'); - loadTest('./permissions.spec.js'); - - describe.skip(product !== 'Chromium')('[Chromium]', () => { - loadTest('./chromium/chromium.spec.js'); - loadTest('./chromium/coverage.spec.js'); - loadTest('./chromium/pdf.spec.js'); - loadTest('./chromium/session.spec.js'); - }); - }); - - // Browser-level tests that are given a browser. - describe('[Driver]', () => { - loadTest('./browser.spec.js'); - loadTest('./browsercontext.spec.js'); - loadTest('./ignorehttpserrors.spec.js'); - loadTest('./popup.spec.js'); - }); - }); - - // Top-level tests that launch Browser themselves. - describe('[Driver]', () => { - loadTest('./defaultbrowsercontext.spec.js'); - loadTest('./fixtures.spec.js'); - loadTest('./launcher.spec.js'); - loadTest('./headful.spec.js'); - loadTest('./multiclient.spec.js'); - }); - - describe.skip(product !== 'Chromium')('[Chromium]', () => { - loadTest('./chromium/launcher.spec.js'); - loadTest('./chromium/oopif.spec.js'); - loadTest('./chromium/tracing.spec.js'); - }); - - loadTest('./apicoverage.spec.js'); - - delete global.browserType; - delete global.playwright; - }); - } -}; - -function valueFromEnv(name, defaultValue) { - if (!(name in process.env)) - return defaultValue; - return JSON.parse(process.env[name]); -} diff --git a/test/test.config.js b/test/test.config.js new file mode 100644 index 0000000000..1df9963f47 --- /dev/null +++ b/test/test.config.js @@ -0,0 +1,225 @@ +/** + * Copyright 2019 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. + */ + +const fs = require('fs'); +const path = require('path'); +const rm = require('rimraf').sync; +const {TestServer} = require('../utils/testserver/'); +const {Environment} = require('../utils/testrunner/Test'); + +const serverEnvironment = new Environment('TestServer'); +serverEnvironment.beforeAll(async state => { + const assetsPath = path.join(__dirname, 'assets'); + const cachedPath = path.join(__dirname, 'assets', 'cached'); + + const port = 8907 + state.parallelIndex * 2; + state.server = await TestServer.create(assetsPath, port); + state.server.enableHTTPCache(cachedPath); + state.server.PORT = port; + state.server.PREFIX = `http://localhost:${port}`; + state.server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`; + state.server.EMPTY_PAGE = `http://localhost:${port}/empty.html`; + + const httpsPort = port + 1; + state.httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort); + state.httpsServer.enableHTTPCache(cachedPath); + state.httpsServer.PORT = httpsPort; + state.httpsServer.PREFIX = `https://localhost:${httpsPort}`; + state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`; + state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`; +}); +serverEnvironment.afterAll(async({server, httpsServer}) => { + await Promise.all([ + server.stop(), + httpsServer.stop(), + ]); +}); +serverEnvironment.beforeEach(async({server, httpsServer}) => { + server.reset(); + httpsServer.reset(); +}); + +const customEnvironment = new Environment('Golden+CheckContexts'); +customEnvironment.beforeAll(async ({browserType}) => { + const { OUTPUT_DIR, GOLDEN_DIR } = require('./utils').testOptions(browserType); + if (fs.existsSync(OUTPUT_DIR)) + rm(OUTPUT_DIR); + fs.mkdirSync(OUTPUT_DIR, { recursive: true }); + expect.setupGolden(GOLDEN_DIR, OUTPUT_DIR); +}); +customEnvironment.afterEach(async (state, testRun) => { + if (state.browser && state.browser.contexts().length !== 0) { + if (testRun.ok()) + console.warn(`\nWARNING: test "${testRun.test().fullName()}" (${testRun.test().location()}) did not close all created contexts!\n`); + await Promise.all(state.browser.contexts().map(context => context.close())); + } +}); + +function valueFromEnv(name, defaultValue) { + if (!(name in process.env)) + return defaultValue; + return JSON.parse(process.env[name]); +} + +function setupTestRunner(testRunner) { + const collector = testRunner.collector(); + collector.addTestModifier('skip', (t, condition) => condition && t.setSkipped(true)); + collector.addSuiteModifier('skip', (s, condition) => condition && s.setSkipped(true)); + collector.addTestModifier('fail', (t, condition) => condition && t.setExpectation(t.Expectations.Fail)); + collector.addSuiteModifier('fail', (s, condition) => condition && s.setExpectation(s.Expectations.Fail)); + collector.addTestModifier('slow', t => t.setTimeout(t.timeout() * 3)); + collector.addTestAttribute('debug', t => { + t.setTimeout(100000000); + + let session; + t.environment().beforeEach(async () => { + const inspector = require('inspector'); + const fs = require('fs'); + const util = require('util'); + const url = require('url'); + const readFileAsync = util.promisify(fs.readFile.bind(fs)); + session = new inspector.Session(); + session.connect(); + const postAsync = util.promisify(session.post.bind(session)); + await postAsync('Debugger.enable'); + const setBreakpointCommands = []; + const N = t.body().toString().split('\n').length; + const location = t.location(); + const lines = (await readFileAsync(location.filePath(), 'utf8')).split('\n'); + for (let line = 0; line < N; ++line) { + const lineNumber = line + location.lineNumber(); + setBreakpointCommands.push(postAsync('Debugger.setBreakpointByUrl', { + url: url.pathToFileURL(location.filePath()), + lineNumber, + condition: `console.log('${String(lineNumber + 1).padStart(6, ' ')} | ' + ${JSON.stringify(lines[lineNumber])})`, + }).catch(e => {})); + } + await Promise.all(setBreakpointCommands); + }); + + t.environment().afterEach(async () => { + session.disconnect(); + }); + }); + testRunner.api().fdescribe = testRunner.api().describe.only; + testRunner.api().xdescribe = testRunner.api().describe.skip(true); + testRunner.api().fit = testRunner.api().it.only; + testRunner.api().xit = testRunner.api().it.skip(true); + testRunner.api().dit = testRunner.api().it.only.debug; +} + +module.exports = { + playwrightPath: '..', + dumpProtocolOnFailure: valueFromEnv('DEBUGP', false), + launchOptions: { + executablePath: { + chromium: process.env.CRPATH, + firefox: process.env.FFPATH, + webkit: process.env.WKPATH, + }, + slowMo: valueFromEnv('SLOW_MO', 0), + headless: !!valueFromEnv('HEADLESS', true), + }, + + globalEnvironments: [serverEnvironment], + setupTestRunner, + + specs: [ + { + files: [ + './accessibility.spec.js', + './autowaiting.spec.js', + './click.spec.js', + './cookies.spec.js', + './dialog.spec.js', + './download.spec.js', + './elementhandle.spec.js', + './emulation.spec.js', + './evaluation.spec.js', + './frame.spec.js', + './focus.spec.js', + './input.spec.js', + './jshandle.spec.js', + './keyboard.spec.js', + './mouse.spec.js', + './navigation.spec.js', + './network.spec.js', + './page.spec.js', + './queryselector.spec.js', + './screenshot.spec.js', + './waittask.spec.js', + './interception.spec.js', + './geolocation.spec.js', + './workers.spec.js', + './capabilities.spec.js', + './permissions.spec.js', + ], + environments: [customEnvironment, 'page'], + }, + + { + files: [ + './chromium/chromium.spec.js', + './chromium/coverage.spec.js', + './chromium/pdf.spec.js', + './chromium/session.spec.js', + ], + browsers: ['chromium'], + title: '[Chromium]', + environments: [customEnvironment, 'page'], + }, + + { + files: [ + './browser.spec.js', + './browsercontext.spec.js', + './ignorehttpserrors.spec.js', + './popup.spec.js', + ], + environments: [customEnvironment, 'browser'], + }, + + { + files: [ + './defaultbrowsercontext.spec.js', + './fixtures.spec.js', + './launcher.spec.js', + './headful.spec.js', + './multiclient.spec.js', + ], + environments: [customEnvironment], + }, + + { + files: [ + './chromium/launcher.spec.js', + './chromium/oopif.spec.js', + './chromium/tracing.spec.js', + ], + browsers: ['chromium'], + title: '[Chromium]', + environments: [customEnvironment], + }, + + { + files: [ + './apicoverage.spec.js', + ], + environments: [], + }, + ], +}; diff --git a/test/test.js b/test/test.js index a969d80cbc..0557c646a2 100644 --- a/test/test.js +++ b/test/test.js @@ -15,9 +15,10 @@ * limitations under the License. */ +const fs = require('fs'); +const readline = require('readline'); const TestRunner = require('../utils/testrunner/'); -const utils = require('./utils'); -const os = require('os'); +const {Environment} = require('../utils/testrunner/Test'); let parallel = 1; if (process.env.PW_PARALLEL_TESTS) @@ -36,6 +37,8 @@ if (MAJOR_NODEJS_VERSION >= 8 && require('inspector').url()) { timeout = 0; } +const config = require('./test.config'); + const testRunner = new TestRunner({ timeout, totalTimeout: process.env.CI ? 15 * 60 * 1000 : 0, @@ -46,20 +49,150 @@ const testRunner = new TestRunner({ showSlowTests: process.env.CI ? 5 : 0, showMarkedAsFailingTests: 10, }); -utils.setupTestRunner(testRunner); +if (config.setupTestRunner) + config.setupTestRunner(testRunner); console.log('Testing on Node', process.version); -const products = ['Chromium', 'Firefox', 'WebKit'].filter(name => { - return process.env.BROWSER === name.toLowerCase() || process.env.BROWSER === 'all'; +const browserNames = ['chromium', 'firefox', 'webkit'].filter(name => { + return process.env.BROWSER === name || process.env.BROWSER === 'all'; }); for (const [key, value] of Object.entries(testRunner.api())) global[key] = value; -require('./playwright.spec.js').addPlaywrightTests({ - testRunner, - products, + +// TODO: this should be a preinstalled playwright by default. +const playwrightPath = config.playwrightPath; +const playwright = require(playwrightPath); + +const playwrightEnvironment = new Environment('Playwright'); +playwrightEnvironment.beforeAll(async state => { + state.playwright = playwright; + global.playwright = playwright; }); +playwrightEnvironment.afterAll(async state => { + delete state.playwright; + delete global.playwright; +}); + +testRunner.collector().useEnvironment(playwrightEnvironment); +for (const e of config.globalEnvironments || []) + testRunner.collector().useEnvironment(e); + +for (const browserName of browserNames) { + const browserType = playwright[browserName]; + const browserTypeEnvironment = new Environment('BrowserType'); + browserTypeEnvironment.beforeAll(async state => { + state.browserType = browserType; + }); + browserTypeEnvironment.afterAll(async state => { + delete state.browserType; + }); + + // TODO: maybe launch options per browser? + const launchOptions = { + ...(config.launchOptions || {}), + handleSIGINT: false, + }; + if (launchOptions.executablePath) + launchOptions.executablePath = launchOptions.executablePath[browserName]; + if (launchOptions.executablePath) { + const YELLOW_COLOR = '\x1b[33m'; + const RESET_COLOR = '\x1b[0m'; + console.warn(`${YELLOW_COLOR}WARN: running ${browserName} tests with ${launchOptions.executablePath}${RESET_COLOR}`); + browserType._executablePath = launchOptions.executablePath; + delete launchOptions.executablePath; + } else { + if (!fs.existsSync(browserType.executablePath())) + throw new Error(`Browser is not downloaded. Run 'npm install' and try to re-run tests`); + } + + const browserEnvironment = new Environment(browserName); + browserEnvironment.beforeAll(async state => { + state.browser = await state.browserType.launch(launchOptions); + // TODO: remove browserServer from state. + state.browserServer = state.browser._ownedServer; + state._stdout = readline.createInterface({ input: state.browserServer.process().stdout }); + state._stderr = readline.createInterface({ input: state.browserServer.process().stderr }); + }); + browserEnvironment.afterAll(async state => { + await state.browserServer.close(); + delete state.browser; + delete state.browserServer; + state._stdout.close(); + state._stderr.close(); + delete state._stdout; + delete state._stderr; + }); + browserEnvironment.beforeEach(async(state, testRun) => { + const dumpout = data => testRun.log(`\x1b[33m[pw:stdio:out]\x1b[0m ${data}`); + const dumperr = data => testRun.log(`\x1b[31m[pw:stdio:err]\x1b[0m ${data}`); + state._stdout.on('line', dumpout); + state._stderr.on('line', dumperr); + // TODO: figure out debug options. + if (config.dumpProtocolOnFailure) { + state.browser._debugProtocol.log = data => testRun.log(`\x1b[32m[pw:protocol]\x1b[0m ${data}`); + state.browser._debugProtocol.enabled = true; + } + state._browserTearDown = async (testRun) => { + state._stdout.off('line', dumpout); + state._stderr.off('line', dumperr); + if (config.dumpProtocolOnFailure) { + delete state.browser._debugProtocol.log; + state.browser._debugProtocol.enabled = false; + if (testRun.ok()) + testRun.output().splice(0); + } + }; + }); + browserEnvironment.afterEach(async (state, testRun) => { + await state._browserTearDown(testRun); + delete state._browserTearDown; + }); + + const pageEnvironment = new Environment('Page'); + pageEnvironment.beforeEach(async state => { + state.context = await state.browser.newContext(); + state.page = await state.context.newPage(); + }); + pageEnvironment.afterEach(async state => { + await state.context.close(); + state.context = null; + state.page = null; + }); + + const suiteName = { 'chromium': 'Chromium', 'firefox': 'Firefox', 'webkit': 'WebKit' }[browserName]; + describe(suiteName, () => { + // In addition to state, expose these two on global so that describes can access them. + global.playwright = playwright; + global.browserType = browserType; + + testRunner.collector().useEnvironment(browserTypeEnvironment); + + for (const spec of config.specs || []) { + const skip = spec.browsers && !spec.browsers.includes(browserName); + (skip ? xdescribe : describe)(spec.title || '', () => { + for (const e of spec.environments || ['page']) { + if (e === 'browser') { + testRunner.collector().useEnvironment(browserEnvironment); + } else if (e === 'page') { + testRunner.collector().useEnvironment(browserEnvironment); + testRunner.collector().useEnvironment(pageEnvironment); + } else { + testRunner.collector().useEnvironment(e); + } + } + for (const file of spec.files || []) { + require(file); + delete require.cache[require.resolve(file)]; + } + }); + } + + delete global.browserType; + delete global.playwright; + }); +} for (const [key, value] of Object.entries(testRunner.api())) { // expect is used when running tests, while the rest of api is not. if (key !== 'expect') @@ -72,5 +205,4 @@ if (filterArgIndex !== -1) { testRunner.focusMatchingTests(new RegExp(filter, 'i')); } -// await utils.initializeFlakinessDashboardIfNeeded(testRunner); testRunner.run().then(() => { delete global.expect; }); diff --git a/test/utils.js b/test/utils.js index 3ce7a55f94..7df59eff0e 100644 --- a/test/utils.js +++ b/test/utils.js @@ -20,7 +20,6 @@ const path = require('path'); const util = require('util'); const os = require('os'); const removeFolder = require('rimraf'); -const url = require('url'); const {FlakinessDashboard} = require('../utils/flakiness-dashboard'); const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..'); @@ -170,50 +169,6 @@ const utils = module.exports = { await removeFolderAsync(dir).catch(e => {}); }, - setupTestRunner: function(testRunner) { - const collector = testRunner._collector; - collector.addTestModifier('skip', (t, condition) => condition && t.setSkipped(true)); - collector.addSuiteModifier('skip', (s, condition) => condition && s.setSkipped(true)); - collector.addTestModifier('fail', (t, condition) => condition && t.setExpectation(t.Expectations.Fail)); - collector.addSuiteModifier('fail', (s, condition) => condition && s.setExpectation(s.Expectations.Fail)); - collector.addTestModifier('slow', t => t.setTimeout(t.timeout() * 3)); - collector.addTestAttribute('debug', t => { - t.setTimeout(100000000); - - let session; - t.environment().beforeEach(async () => { - const inspector = require('inspector'); - const readFileAsync = util.promisify(fs.readFile.bind(fs)); - session = new inspector.Session(); - session.connect(); - const postAsync = util.promisify(session.post.bind(session)); - await postAsync('Debugger.enable'); - const setBreakpointCommands = []; - const N = t.body().toString().split('\n').length; - const location = t.location(); - const lines = (await readFileAsync(location.filePath(), 'utf8')).split('\n'); - for (let line = 0; line < N; ++line) { - const lineNumber = line + location.lineNumber(); - setBreakpointCommands.push(postAsync('Debugger.setBreakpointByUrl', { - url: url.pathToFileURL(location.filePath()), - lineNumber, - condition: `console.log('${String(lineNumber + 1).padStart(6, ' ')} | ' + ${JSON.stringify(lines[lineNumber])})`, - }).catch(e => {})); - } - await Promise.all(setBreakpointCommands); - }); - - t.environment().afterEach(async () => { - session.disconnect(); - }); - }); - testRunner.api().fdescribe = testRunner.api().describe.only; - testRunner.api().xdescribe = testRunner.api().describe.skip(true); - testRunner.api().fit = testRunner.api().it.only; - testRunner.api().xit = testRunner.api().it.skip(true); - testRunner.api().dit = testRunner.api().it.only.debug; - }, - testOptions(browserType) { const headless = !!valueFromEnv('HEADLESS', true); const defaultBrowserOptions = {