Unverified Commit 474f1e7d authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add initial test trace outputs (#30246)

parent 9d280afb
......@@ -171,6 +171,15 @@ jobs:
name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
- name: Upload test trace
if: always()
uses: actions/upload-artifact@v2
with:
name: test-trace
retention-days: 2
path: |
test/traces
testProd:
name: Test Production
runs-on: ubuntu-latest
......
import a from "other";
function _arrayWithHoles(b) {
if (Array.isArray(b)) return b;
function _arrayWithHoles(a) {
if (Array.isArray(a)) return a;
}
function _classCallCheck(c, d) {
if (!(c instanceof d)) throw new TypeError("Cannot call a class as a function");
function _classCallCheck(a, b) {
if (!(a instanceof b)) throw new TypeError("Cannot call a class as a function");
}
function _iterableToArrayLimit(b, e) {
var f = [], g = !0, h = !1, i = void 0;
function _iterableToArrayLimit(a, b) {
var c = [], d = !0, e = !1, f = void 0;
try {
for(var j, k = b[Symbol.iterator](); !(g = (j = k.next()).done) && (f.push(j.value), !e || f.length !== e); g = !0);
} catch (l) {
h = !0, i = l;
for(var g, h = a[Symbol.iterator](); !(d = (g = h.next()).done) && (c.push(g.value), !b || c.length !== b); d = !0);
} catch (a) {
e = !0, f = a;
} finally{
try {
g || null == k.return || k.return();
d || null == h.return || h.return();
} finally{
if (h) throw i;
if (e) throw f;
}
}
return f;
return c;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
function _slicedToArray(b, e) {
return _arrayWithHoles(b) || _iterableToArrayLimit(b, e) || _nonIterableRest();
function _slicedToArray(a, b) {
return _arrayWithHoles(a) || _iterableToArrayLimit(a, b) || _nonIterableRest();
}
var foo = _slicedToArray(a, 1)[0], Foo = function() {
"use strict";
_classCallCheck(this, Foo);
};
export var __N_SSG = !0;
export default function Home() {
export default function a() {
return React.createElement("div", null);
};
......@@ -250,6 +250,7 @@ async function main() {
...process.env,
// run tests in headless mode by default
HEADLESS: 'true',
TRACE_PLAYWRIGHT: 'true',
...(usePolling
? {
// Events can be finicky in CI. This switches to a more
......@@ -274,7 +275,7 @@ async function main() {
children.add(child)
child.on('exit', (code) => {
child.on('exit', async (code) => {
children.delete(child)
if (code) {
if (isFinalRun && hideOutput) {
......@@ -297,8 +298,19 @@ async function main() {
}
trimmedOutput.forEach((chunk) => process.stdout.write(chunk))
}
reject(new Error(`failed with code: ${code}`))
return reject(new Error(`failed with code: ${code}`))
}
await fs
.remove(
path.join(
__dirname,
'test/traces',
path
.relative(path.join(__dirname, 'test'), test)
.replace(/\//g, '-')
)
)
.catch(() => {})
resolve(new Date().getTime() - start)
})
})
......
import { BrowserInterface } from './base'
import fs from 'fs-extra'
import {
chromium,
webkit,
......@@ -8,11 +9,15 @@ import {
Page,
ElementHandle,
} from 'playwright-chromium'
import path from 'path'
let page: Page
let browser: Browser
let context: BrowserContext
let pageLogs: Array<{ source: string; message: string }> = []
let traceStarted = false
const tracePlaywright = process.env.TRACE_PLAYWRIGHT
export async function quit() {
await context?.close()
......@@ -44,6 +49,24 @@ class Playwright extends BrowserInterface {
}
async loadPage(url: string) {
if (traceStarted) {
const traceDir = path.join(__dirname, '../../traces')
const traceOutputPath = path.join(
traceDir,
`${path
.relative(path.join(__dirname, '../../'), process.env.TEST_FILE_PATH)
.replace(/\//g, '-')}`,
`playwright-${encodeURIComponent(url)}-${Date.now()}.zip`
)
await fs.remove(traceOutputPath)
await context.tracing
.stop({
path: traceOutputPath,
})
.catch((err) => console.error('failed to write playwright trace', err))
}
// clean-up existing pages
for (const oldPage of context.pages()) {
await oldPage.close()
......@@ -61,6 +84,34 @@ class Playwright extends BrowserInterface {
page.on('pageerror', (error) => {
console.error('page error', error)
})
if (tracePlaywright) {
page.on('websocket', (ws) => {
page
.evaluate(`console.log('connected to ws at ${ws.url()}')`)
.catch(() => {})
ws.on('close', () =>
page
.evaluate(`console.log('closed websocket ${ws.url()}')`)
.catch(() => {})
)
ws.on('framereceived', (frame) => {
if (!frame.payload.includes('pong')) {
page
.evaluate(`console.log('received ws message ${frame.payload}')`)
.catch(() => {})
}
})
})
}
if (tracePlaywright) {
await context.tracing.start({
screenshots: true,
snapshots: true,
})
traceStarted = true
}
await page.goto(url, { waitUntil: 'load' })
}
......
......@@ -8,6 +8,8 @@ import { NextStartInstance } from './next-modes/next-start'
const testFile = module.parent.filename
const testsFolder = path.join(__dirname, '..')
process.env.TEST_FILE_PATH = testFile
let testMode = process.env.NEXT_TEST_MODE
if (!testFile.match(/\.test\.(js|tsx?)/)) {
......
......@@ -160,6 +160,25 @@ export class NextInstance {
this.emit('destroy', [])
await this.stop()
if (process.env.TRACE_PLAYWRIGHT) {
await fs
.copy(
path.join(this.testDir, '.next/trace'),
path.join(
__dirname,
'../../traces',
`${path
.relative(
path.join(__dirname, '../../'),
process.env.TEST_FILE_PATH
)
.replace(/\//g, '-')}`,
`next-trace`
)
)
.catch(() => {})
}
if (!process.env.NEXT_TEST_SKIP_CLEANUP) {
await fs.remove(this.testDir)
}
......
......@@ -2,6 +2,10 @@ import { getFullUrl } from 'next-test-utils'
import os from 'os'
import { BrowserInterface } from './browsers/base'
if (!process.env.TEST_FILE_PATH) {
process.env.TEST_FILE_PATH = module.parent.filename
}
let deviceIP: string
const isBrowserStack = !!process.env.BROWSERSTACK
;(global as any).browserName = process.env.BROWSER_NAME || 'chrome'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment