microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.42k stars 3.63k forks source link

[Bug]: "--ui" mode hangs up on throw new Error in playwright config file #30513

Closed kristaps-aksjonovs closed 6 months ago

kristaps-aksjonovs commented 6 months ago

Version

1.43.1

Steps to reproduce

Create a function in config file that will contain throw new Error() to check if arguments are valid. And run yarn playwright run

Example of playwright.config.ts:

import {defineConfig, devices, PlaywrightTestConfig} from '@playwright/test';

function getConfig(url: string): PlaywrightTestConfig {
  if (!url) {
    throw new Error("URL is empty")
  }

  return {
    testDir: './tests',
    fullyParallel: true,
    retries: 0,
    workers: 1,
    reporter: 'html',
    use: {
      trace: 'on-first-retry',
      baseURL: url
    },

    projects: [
      {
        name: 'chromium',
        use: { ...devices['Desktop Chrome'] },
      },
    ],
  }
}

export default defineConfig(getConfig(""));

Expected behavior

Throw error same as when test is executed using yarn playwright test.

 yarn playwright test     
$ /Experiments/playwright_24_05_2024/node_modules/.bin/playwright test
Error: URL is empty
    at getConfig (/Experiments/playwright_24_05_2024/playwright.config.ts:5:11)
    at Object.<anonymous> (/Experiments/playwright_24_05_2024/playwright.config.ts:28:29)

Actual behavior

Seems --ui is stuck with "Loading...." and errors or even console.log() is NOT displayed. Note: Same behavior happens when globalSetup is used and it contains throw new Error()

playwright_ui_crash

Additional context

No response

Environment

System:
    OS: macOS 14.4.1
    CPU: arm64 Apple M3
  Binaries:
    Node: 20.10.0 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 10.2.3 - /opt/homebrew/opt/node@20/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash
pavelfeldman commented 6 months ago

Does the Output panel contain any information?

kristaps-aksjonovs commented 6 months ago

All tabs in UI are empty and also did start process with DEBUG=pw:* yarn playwright test --ui It crashed after a while with:

<--- Last few GCs --->

[66888:0x128008000]    16442 ms: Scavenge (reduce) 4037.4 (4106.4) -> 4037.3 (4107.4) MB, 0.42 / 0.00 ms  (average mu = 0.985, current mu = 0.937) allocation failure; 
[66888:0x128008000]    16449 ms: Mark-Compact (reduce) 4038.3 (4107.4) -> 4038.2 (4108.4) MB, 6.58 / 0.00 ms  (average mu = 0.973, current mu = 0.690) allocation failure; scavenge might not succeed

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x10035a4c4 node::Abort() [/opt/homebrew/Cellar/node@20/20.10.0/bin/node]
kristaps-aksjonovs commented 6 months ago

Thank you very much. That was quick response.