fix(expect): do not rely on displayName (#9523)

Support for displayName was removed in Node 16.
Switching to Function.name instead.

Relevant V8 change: https://chromium-review.googlesource.com/c/v8/v8/+/2692189
This commit is contained in:
Dmitry Gozman 2021-10-14 19:23:45 -07:00 committed by GitHub
parent 7ee48febf9
commit c711fb35ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,6 @@
const { test, expect } = require('@playwright/test');
test('failing test', async ({ page }) => {
await page.setContent(`<div>hello</div><span>world</span>`);
await expect(page.locator('span')).toHaveText('hello', { timeout: 1000 });
});

View File

@ -52,6 +52,7 @@ function copy_test_scripts {
cp "${SCRIPTS_PATH}/electron-app.js" .
cp "${SCRIPTS_PATH}/driver-client.js" .
cp "${SCRIPTS_PATH}/sample.spec.js" .
cp "${SCRIPTS_PATH}/failing.spec.js" .
cp "${SCRIPTS_PATH}/read-json-report.js" .
cp "${SCRIPTS_PATH}/playwright-test-types.ts" .
}
@ -80,6 +81,7 @@ function run_tests {
test_playwright_chromium_should_work
test_playwright_webkit_should_work
test_playwright_firefox_should_work
test_playwright_test_stacks_should_work
}
function test_screencast {
@ -606,7 +608,7 @@ function test_playwright_test_should_work {
PLAYWRIGHT_BROWSERS_PATH="0" npx playwright install
echo "Running playwright test"
PLAYWRIGHT_JSON_OUTPUT_NAME=report.json PLAYWRIGHT_BROWSERS_PATH="0" npx playwright test -c . --browser=all --reporter=list,json
PLAYWRIGHT_JSON_OUTPUT_NAME=report.json PLAYWRIGHT_BROWSERS_PATH="0" npx playwright test -c . --browser=all --reporter=list,json sample.spec.js
echo "Checking the report"
node ./read-json-report.js ./report.json
@ -621,6 +623,28 @@ function test_playwright_test_should_work {
echo "${FUNCNAME[0]} success"
}
function test_playwright_test_stacks_should_work {
initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_CORE_TGZ}
npm install ${PLAYWRIGHT_TEST_TGZ}
PLAYWRIGHT_BROWSERS_PATH="0" npx playwright install chromium
copy_test_scripts
echo "Running playwright test"
OUTPUT=$(DEBUG=pw:api npx playwright test -c . failing.spec.js || true)
if [[ "${OUTPUT}" != *"expect.toHaveText started"* ]]; then
echo "ERROR: missing 'expect.toHaveText started' in the output"
exit 1
fi
if [[ "${OUTPUT}" != *"failing.spec.js:5:38"* ]]; then
echo "ERROR: missing 'failing.spec.js:5:38' in the output"
exit 1
fi
echo "${FUNCNAME[0]} success"
}
function initialize_test {
cd ${TEST_ROOT}
local TEST_NAME="./$1"

View File

@ -156,7 +156,7 @@ function wrap(matcherName: string, matcher: any) {
reportStepError(e);
}
};
result.displayName = '__PWTRAP__[expect.' + matcherName + ']';
Object.defineProperty(result, 'name', { value: '__PWTRAP__[expect.' + matcherName + ']' });
return result;
}