Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: vendor stack utils (#34719)
Pavel Feldman46b048f0181c
diff --git a/packages/playwright-core/ThirdPartyNotices.txt b/packages/playwright-core/ThirdPartyNotices.txtindex cc6ee5c884..420d698fa5 100644--- a/packages/playwright-core/ThirdPartyNotices.txt+++ b/packages/playwright-core/ThirdPartyNotices.txt@@ -19,7 +19,6 @@ This project incorporates components from the projects listed below. The origina- [email protected] (https://github.com/kpdecker/jsdiff)- [email protected] (https://github.com/motdotla/dotenv)- [email protected] (https://github.com/mafintosh/end-of-stream)-- [email protected] (https://github.com/sindresorhus/escape-string-regexp)- [email protected] (https://github.com/maxogden/extract-zip)- [email protected] (https://github.com/andrewrk/node-fd-slicer)- [email protected] (https://github.com/sindresorhus/get-stream)@@ -46,7 +45,6 @@ This project incorporates components from the projects listed below. The origina- [email protected] (https://github.com/TooTallNate/node-socks-proxy-agent)- [email protected] (https://github.com/JoshGlazebrook/socks)- [email protected] (https://github.com/alexei/sprintf.js)-- [email protected] (https://github.com/tapjs/stack-utils)- [email protected] (https://github.com/npm/wrappy)- [email protected] (https://github.com/websockets/ws)- [email protected] (https://github.com/eemeli/yaml)@@ -563,20 +561,6 @@ THE SOFTWARE.=========================================END OF [email protected] AND INFORMATION-%% [email protected] NOTICES AND INFORMATION BEGIN HERE-=========================================-MIT License--Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)--Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.-=========================================-END OF [email protected] AND INFORMATION-%% [email protected] NOTICES AND INFORMATION BEGIN HERE=========================================Copyright (c) 2014 Max Ogden and other contributors@@ -1454,32 +1438,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.=========================================END OF [email protected] AND INFORMATION-%% [email protected] NOTICES AND INFORMATION BEGIN HERE-=========================================-The MIT License (MIT)--Copyright (c) Isaac Z. Schlueter <[email protected]>, James Talmage <[email protected]> (github.com/jamestalmage), and Contributors--Permission is hereby granted, free of charge, to any person obtaining a copy-of this software and associated documentation files (the "Software"), to deal-in the Software without restriction, including without limitation the rights-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell-copies of the Software, and to permit persons to whom the Software is-furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in-all copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN-THE SOFTWARE.-=========================================-END OF [email protected] AND INFORMATION-%% [email protected] NOTICES AND INFORMATION BEGIN HERE=========================================The ISC License@@ -1597,6 +1555,6 @@ END OF [email protected] AND INFORMATIONSUMMARY BEGIN HERE=========================================-Total Packages: 48+Total Packages: 46=========================================END OF SUMMARY\ No newline at end of filediff --git a/packages/playwright-core/bundles/utils/package-lock.json b/packages/playwright-core/bundles/utils/package-lock.jsonindex aae091493b..49e99ef5c3 100644--- a/packages/playwright-core/bundles/utils/package-lock.json+++ b/packages/playwright-core/bundles/utils/package-lock.json@@ -25,7 +25,6 @@"retry": "0.12.0","signal-exit": "3.0.7","socks-proxy-agent": "6.1.1",- "stack-utils": "2.0.5","ws": "8.17.1","yaml": "^2.6.0"},@@ -229,14 +228,6 @@"url": "https://dotenvx.com"}},- "node_modules/escape-string-regexp": {- "version": "2.0.0",- "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",- "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==",- "engines": {- "node": ">=8"- }- },"node_modules/graceful-fs": {"version": "4.2.10","resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz",@@ -418,17 +409,6 @@"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz","integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA=="},- "node_modules/stack-utils": {- "version": "2.0.5",- "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.5.tgz",- "integrity": "sha512-xrQcmYhOsn/1kX+Vraq+7j4oE2j/6BFscZ0etmYg81xuM8Gq0022Pxb8+IqgOFUIaxHs0KaSb7T1+OegiNrNFA==",- "dependencies": {- "escape-string-regexp": "^2.0.0"- },- "engines": {- "node": ">=10"- }- },"node_modules/ws": {"version": "8.17.1","resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",diff --git a/packages/playwright-core/bundles/utils/package.json b/packages/playwright-core/bundles/utils/package.jsonindex 3c2c382e0f..e7f09cf3a0 100644--- a/packages/playwright-core/bundles/utils/package.json+++ b/packages/playwright-core/bundles/utils/package.json@@ -26,7 +26,6 @@"retry": "0.12.0","signal-exit": "3.0.7","socks-proxy-agent": "6.1.1",- "stack-utils": "2.0.5","ws": "8.17.1","yaml": "^2.6.0"},diff --git a/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts b/packages/playwright-core/bundles/utils/src/utilsBundleImpl.tsindex 5e94036ae3..409372e894 100644--- a/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts+++ b/packages/playwright-core/bundles/utils/src/utilsBundleImpl.ts@@ -56,9 +56,6 @@ export const progress = progressLibrary;export { SocksProxyAgent } from 'socks-proxy-agent';-import StackUtilsLibrary from 'stack-utils';-export const StackUtils = StackUtilsLibrary;-import yamlLibrary from 'yaml';export const yaml = yamlLibrary;diff --git a/packages/playwright-core/src/utils/stackTrace.ts b/packages/playwright-core/src/utils/stackTrace.tsindex bcab6c7230..fb97115035 100644--- a/packages/playwright-core/src/utils/stackTrace.ts+++ b/packages/playwright-core/src/utils/stackTrace.ts@@ -16,12 +16,30 @@import * as path from 'path';-import { parseStackTraceLine } from '../utilsBundle';import { colors } from '../utilsBundle';import { findRepeatedSubsequences } from './sequence';+import { StackUtils } from './stackUtils';import type { StackFrame } from '@protocol/channels';+const stackUtils = new StackUtils();++export function parseStackTraceLine(line: string): StackFrame | null {+ const frame = stackUtils.parseLine(line);+ if (!frame)+ return null;+ if (!process.env.PWDEBUGIMPL && (frame.file?.startsWith('internal') || frame.file?.startsWith('node:')))+ return null;+ if (!frame.file)+ return null;+ return {+ file: frame.file,+ line: frame.line || 0,+ column: frame.column || 0,+ function: frame.function,+ };+}+export function rewriteErrorMessage<E extends Error>(e: E, newMessage: string): E {const lines: string[] = (e.stack?.split('\n') || []).filter(l => l.startsWith(' at '));e.message = newMessage;diff --git a/packages/playwright-core/src/utils/stackUtils.ts b/packages/playwright-core/src/utils/stackUtils.tsnew file mode 100644index 0000000000..0be4675a86--- /dev/null+++ b/packages/playwright-core/src/utils/stackUtils.ts@@ -0,0 +1,151 @@+/**+ * The MIT License (MIT)+ * Modifications copyright (c) Microsoft Corporation.+ *+ * Copyright (c) 2016-2023 Isaac Z. Schlueter [email protected], James Talmage [email protected] (github.com/jamestalmage), and+ * Contributors+ *+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to+ * permit persons to whom the Software is furnished to do so, subject to the following conditions:+ *+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the+ * Software.+ *+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+ */++import * as url from 'url';++type StackData = {+ line?: number;+ column?: number;+ file?: string;+ isConstructor?: boolean;+ evalOrigin?: string;+ native?: boolean;+ function?: string;+ method?: string;+ evalLine?: number | undefined;+ evalColumn?: number | undefined;+ evalFile?: string | undefined;+};++export class StackUtils {+ parseLine(line: string) {+ const match = line && line.match(re);+ if (!match)+ return null;++ const ctor = match[1] === 'new';+ let fname = match[2];+ const evalOrigin = match[3];+ const evalFile = match[4];+ const evalLine = Number(match[5]);+ const evalCol = Number(match[6]);+ let file = match[7];+ const lnum = match[8];+ const col = match[9];+ const native = match[10] === 'native';+ const closeParen = match[11] === ')';+ let method;++ const res: StackData = {};++ if (lnum)+ res.line = Number(lnum);++ if (col)+ res.column = Number(col);++ if (closeParen && file) {+ // make sure parens are balanced+ // if we have a file like "asdf) [as foo] (xyz.js", then odds are+ // that the fname should be += " (asdf) [as foo]" and the file+ // should be just "xyz.js"+ // walk backwards from the end to find the last unbalanced (+ let closes = 0;+ for (let i = file.length - 1; i > 0; i--) {+ if (file.charAt(i) === ')') {+ closes++;+ } else if (file.charAt(i) === '(' && file.charAt(i - 1) === ' ') {+ closes--;+ if (closes === -1 && file.charAt(i - 1) === ' ') {+ const before = file.slice(0, i - 1);+ const after = file.slice(i + 1);+ file = after;+ fname += ` (${before}`;+ break;+ }+ }+ }+ }++ if (fname) {+ const methodMatch = fname.match(methodRe);+ if (methodMatch) {+ fname = methodMatch[1];+ method = methodMatch[2];+ }+ }++ setFile(res, file);++ if (ctor)+ res.isConstructor = true;++ if (evalOrigin) {+ res.evalOrigin = evalOrigin;+ res.evalLine = evalLine;+ res.evalColumn = evalCol;+ res.evalFile = evalFile && evalFile.replace(/\\/g, '/');+ }++ if (native)+ res.native = true;+ if (fname)+ res.function = fname;+ if (method && fname !== method)+ res.method = method;+ return res;+ }+}++function setFile(result: StackData, filename: string) {+ if (filename) {+ if (filename.startsWith('file://'))+ filename = url.fileURLToPath(filename);+ result.file = filename;+ }+}++const re = new RegExp('^' ++ // Sometimes we strip out the ' at' because it's noisy+ '(?:\\s*at )?' ++ // $1 = ctor if 'new'+ '(?:(new) )?' ++ // $2 = function name (can be literally anything)+ // May contain method at the end as [as xyz]+ '(?:(.*?) \\()?' ++ // (eval at <anonymous> (file.js:1:1),+ // $3 = eval origin+ // $4:$5:$6 are eval file/line/col, but not normally reported+ '(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?' ++ // file:line:col+ // $7:$8:$9+ // $10 = 'native' if native+ '(?:(.+?):(\\d+):(\\d+)|(native))' ++ // maybe close the paren, then end+ // if $11 is ), then we only allow balanced parens in the filename+ // any imbalance is placed on the fname. This is a heuristic, and+ // bound to be incorrect in some edge cases. The bet is that+ // having weird characters in method names is more common than+ // having weird characters in filenames, which seems reasonable.+ '(\\)?)$'+);++const methodRe = /^(.*?) \[as (.*?)\]$/;diff --git a/packages/playwright-core/src/utilsBundle.ts b/packages/playwright-core/src/utilsBundle.tsindex 5e7dd3771a..41cccd1f57 100644--- a/packages/playwright-core/src/utilsBundle.ts+++ b/packages/playwright-core/src/utilsBundle.ts@@ -14,9 +14,6 @@* limitations under the License.*/-import * as path from 'path';-import * as url from 'url';-export const colors: typeof import('../bundles/utils/node_modules/colors/safe') = require('./utilsBundleImpl').colors;export const debug: typeof import('../bundles/utils/node_modules/@types/debug') = require('./utilsBundleImpl').debug;export const diff: typeof import('../bundles/utils/node_modules/@types/diff') = require('./utilsBundleImpl').diff;@@ -40,28 +37,6 @@ export const wsReceiver = require('./utilsBundleImpl').wsReceiver;export const wsSender = require('./utilsBundleImpl').wsSender;export type { Command } from '../bundles/utils/node_modules/commander';export type { EventEmitter as WebSocketEventEmitter, RawData as WebSocketRawData, WebSocket, WebSocketServer } from '../bundles/utils/node_modules/@types/ws';-import type { StackFrame } from '@protocol/channels';--const StackUtils: typeof import('../bundles/utils/node_modules/@types/stack-utils') = require('./utilsBundleImpl').StackUtils;-const stackUtils = new StackUtils({ internals: StackUtils.nodeInternals() });--export function parseStackTraceLine(line: string): StackFrame | null {- const frame = stackUtils.parseLine(line);- if (!frame)- return null;- if (!process.env.PWDEBUGIMPL && (frame.file?.startsWith('internal') || frame.file?.startsWith('node:')))- return null;- if (!frame.file)- return null;- // ESM files return file:// URLs, see here: https://github.com/tapjs/stack-utils/issues/60- const file = frame.file.startsWith('file://') ? url.fileURLToPath(frame.file) : path.resolve(process.cwd(), frame.file);- return {- file,- line: frame.line || 0,- column: frame.column || 0,- function: frame.function,- };-}export function ms(ms: number): string {if (!isFinite(ms))diff --git a/packages/playwright/src/reporters/base.ts b/packages/playwright/src/reporters/base.tsindex 96f47fb192..156f9755db 100644--- a/packages/playwright/src/reporters/base.ts+++ b/packages/playwright/src/reporters/base.ts@@ -17,7 +17,8 @@import * as path from 'path';import { getPackageManagerExecCommand } from 'playwright-core/lib/utils';-import { colors as realColors, ms as milliseconds, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';+import { parseStackTraceLine } from 'playwright-core/lib/utils';+import { colors as realColors, ms as milliseconds } from 'playwright-core/lib/utilsBundle';import { resolveReporterOutputPath } from '../util';import { getEastAsianWidth } from '../utilsBundle';diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.tsindex d0a63e8e6e..571c091b73 100644--- a/packages/playwright/src/util.ts+++ b/packages/playwright/src/util.ts@@ -21,7 +21,8 @@ import util from 'util';import { sanitizeForFilePath } from 'playwright-core/lib/server';import { calculateSha1, formatCallLog, isRegExp, isString, stringifyStackFrames } from 'playwright-core/lib/utils';-import { debug, mime, minimatch, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';+import { parseStackTraceLine } from 'playwright-core/lib/utils';+import { debug, mime, minimatch } from 'playwright-core/lib/utilsBundle';import type { Location } from './../types/testReporter';import type { TestInfoErrorImpl } from './common/ipc';