playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Playwright Stack trace shows wrong line number for failure if importing certain packages

Open mastrzyz opened this issue 1 year ago • 5 comments

System info

  • Playwright Version: 1.41
  • Operating System: Windows 11
  • Browser: All
  • Other info: Node v16.20.2

Source code

example.spec.ts

import { test } from "@playwright/test";



require("appium-windows-driver");













test("Basic Test", () => {
  throw new Error("Will fail");
});

Package.json

{
  "name": "playwright_sandbox",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {},
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.41.1",
    "appium-windows-driver": "1.19.1"
  }
}

Steps

  • [Run the test]

Expected I would expect line 8 to be the line we have a failure image

Actual Looks like the whitespace confuses playwright with the import? we have it on line 6

Note this is a wacky repro but it's the smallest I could do that is portable, we don't actually have tests like this :)

image

Commenting out the require shows "Expected" results again :

image

Removing all new lines and we still have the weird line count issue :

image

mastrzyz avatar Jan 24 '24 19:01 mastrzyz

Hmm, wasn't able to reproduce it on linux with node 18 or 16. This is the project that I used https://github.com/yury-s/bug-29157. Let me try on Windows too.

yury-s avatar Jan 24 '24 19:01 yury-s

I can't either, I wonder if its due to me making this repro as small as possible but Playwright still using the same compilation cache?

mastrzyz avatar Jan 24 '24 20:01 mastrzyz

There is a chance that something got stuck somewhere (node_modules?). Does it reproduce with the original project on a fresh checkout?

yury-s avatar Jan 24 '24 20:01 yury-s

I can repro.

The wrong source-map-support package gets picked up:

https://github.com/appium/appium-windows-driver/blob/53f9603cb8d8a54fc39a6dfcc5b7b239cd9f2afa/package.json#L64

They also internally do a lot of require("source-map-support/register"). It also depends on the asyncbox package, which does the same hence its not working.

mxschmitt avatar Jan 24 '24 22:01 mxschmitt

Workaround: Put require('source-map-support').install = () => {} into your playwright.config.ts in line 1.

mxschmitt avatar Jan 29 '24 15:01 mxschmitt