Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledRejection: process.memoryUsage #6500

Open
6 tasks done
ghost opened this issue Sep 13, 2024 · 3 comments
Open
6 tasks done

UnhandledRejection: process.memoryUsage #6500

ghost opened this issue Sep 13, 2024 · 3 comments
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome

Comments

@ghost
Copy link

ghost commented Sep 13, 2024

Describe the bug

𝐇ello˙. 𝐀m 𝐈 doing something wrong˙? ಥ_ಥ

Run the following script:

"test:browser": "vitest run",

It runs correctly. (。◕‿‿◕。)


Run the following script:

"test:browser-flaky": "vitest run --browser.enabled=true",

Message output in console ⚆ _ ⚆
❯ npm run test:browser-flaky

> test:browser-flaky
> vitest run --browser.enabled=true


 RUN  v2.1.1 /home/projects/vitest-dev-vitest-gmzfxl
      Browser runner started at http://localhost:5173/
      Coverage enabled with v8


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 2 unhandled errors during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Coverage Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: CDP is not supported by the provider "preview".
 ❯ receiverOnMessage node_modules/ws/lib/websocket.js:1220:20
 ❯ dataMessage node_modules/ws/lib/receiver.js:596:14
 ❯ getData node_modules/ws/lib/receiver.js:496:10
 ❯ startLoop node_modules/ws/lib/receiver.js:167:16
 ❯ _write node_modules/ws/lib/receiver.js:94:10
 ❯ socketOnData node_modules/ws/lib/websocket.js:1355:35
 ❯ _0x26b1b3/< ../../../blitz.28a8ce1b.js:40:516951
 ❯ _0x4d0c70/< ../../../blitz.28a8ce1b.js:40:518489
 ❯ _0x132427/< ../../../blitz.28a8ce1b.js:40:195670
 ❯ _0x4f7512 ../../../blitz.28a8ce1b.js:40:195775
 ❯ _0x4d0c70 ../../../blitz.28a8ce1b.js:40:518414
 ❯ _0x3e05c5/< ../../../blitz.28a8ce1b.js:40:519146
 ❯ _0x3e05c5 ../../../blitz.28a8ce1b.js:40:519125
 ❯ _0x1a4990 ../../../blitz.28a8ce1b.js:40:518751
 ❯ _0x38702d ../../../blitz.28a8ce1b.js:40:517760


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: CDP is not supported by the provider "preview".
 ❯ receiverOnMessage node_modules/ws/lib/websocket.js:1220:20
 ❯ dataMessage node_modules/ws/lib/receiver.js:596:14
 ❯ getData node_modules/ws/lib/receiver.js:496:10
 ❯ startLoop node_modules/ws/lib/receiver.js:167:16
 ❯ _write node_modules/ws/lib/receiver.js:94:10
 ❯ socketOnData node_modules/ws/lib/websocket.js:1355:35
 ❯ _0x26b1b3/< ../../../blitz.28a8ce1b.js:40:516951
 ❯ _0x4d0c70/< ../../../blitz.28a8ce1b.js:40:518489
 ❯ _0x132427/< ../../../blitz.28a8ce1b.js:40:195670
 ❯ _0x4f7512 ../../../blitz.28a8ce1b.js:40:195775
 ❯ _0x4d0c70 ../../../blitz.28a8ce1b.js:40:518414
 ❯ _0x3e05c5/< ../../../blitz.28a8ce1b.js:40:519146
 ❯ _0x3e05c5 ../../../blitz.28a8ce1b.js:40:519125
 ❯ _0x1a4990 ../../../blitz.28a8ce1b.js:40:518751
 ❯ _0x38702d ../../../blitz.28a8ce1b.js:40:517760

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files  no tests
      Tests  no tests
     Errors  2 errors
   Start at  17:31:33
   Duration  12.91s (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)

 % @vitest/coverage-v8 does not work on Stackblitz. Report will be empty.
 % Coverage report from v8
-------------|---------|----------|---------|---------|-------------------
File         | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------|---------|----------|---------|---------|-------------------
All files    |       0 |        0 |       0 |       0 |                   
 ...t-gmzfxl |       0 |        0 |       0 |       0 |                   
  ...nfig.js |       0 |        0 |       0 |       0 | 1-31              
 ...zfxl/src |       0 |        0 |       0 |       0 |                   
  index.js   |       0 |        0 |       0 |       0 | 1-2               
  ...test.js |       0 |        0 |       0 |       0 | 1-9               
-------------|---------|----------|---------|---------|-------------------
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: this.server is undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v18.20.3

Run the following script:

"test:browser-error": "vitest run --browser.enabled=true --coverage.enabled=false"

Message output in console ⚆ _ ⚆
❯ npm run test:browser-error

> test:browser-error
> vitest run --browser.enabled=true --coverage.enabled=false


 RUN  v2.1.1 /home/projects/vitest-dev-vitest-gmzfxl
      Browser runner started at http://localhost:5173/

 · src/index.test.js (1)
   · config needs to be object

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: process.memoryUsage is not a function
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files   (1)
      Tests   (1)
     Errors  1 error
   Start at  17:34:48
   Duration  7.55s (transform 0ms, setup 0ms, collect 61ms, tests 0ms, environment 0ms, prepare 40ms)

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-gmzfxl?file=package.json

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (1) Intel Celeron 352
    Memory: 1.66 GB / 15.35 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v22.8.0/bin/npm

Used Package Manager

npm

Validations

@ghost ghost added the pending triage label Sep 13, 2024
@ghost
Copy link
Author

ghost commented Sep 13, 2024

When I erase the line "logHeapUsage": true, in configVitest.json, at least one of the error messages disappear. But I wanted to keep this line in place.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Sep 14, 2024

I'm not sure if logHeapUsage can be supported for browser mode since it's relying on Node's process.memoryUsage. At least we could prevent the runtime error if we guarded this by typeof process.memoryUsage === 'function':

if (this.config.logHeapUsage && typeof process !== 'undefined') {
test.result!.heap = process.memoryUsage().heapUsed
}


The error Error: CDP is not supported by the provider "preview" is probably only on stackblitz? It forces preview provider, but this happens after @vitest/coverage-v8 config checks, so it misses validations:

// Browser-mode "Playwright + Chromium" only features:
if (resolved.browser.enabled && !(resolved.browser.provider === 'playwright' && resolved.browser.name === 'chromium')) {
const browserConfig = { browser: { provider: resolved.browser.provider, name: resolved.browser.name } }
if (resolved.coverage.enabled && resolved.coverage.provider === 'v8') {
throw new Error(
`@vitest/coverage-v8 does not work with\n${JSON.stringify(browserConfig, null, 2)}\n`
+ `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', name: 'chromium' } }, null, 2)}`
+ `\n\n...or change your coverage provider to:\n${JSON.stringify({ coverage: { provider: 'istanbul' } }, null, 2)}\n`,
)
}

if (resolved.browser.enabled && stdProvider === 'stackblitz') {
resolved.browser.provider = 'preview'
}

@ghost
Copy link
Author

ghost commented Sep 14, 2024

Maybe Performance.measureUserAgentSpecificMemory() is equivalent to Node.js's process.memoryUsage because it estimates the memory used by the iframes and workers of a web page?

async function getMemoryUsage() {
  if (typeof performance !== 'undefined' && 'measureUserAgentSpecificMemory' in performance) {
    try {
      const memorySample = await performance.measureUserAgentSpecificMemory();
      return memorySample.bytes;
    } catch (error) {
      console.error('Error measuring memory:', error);
      return null;
    }
  } else {
    console.warn('Performance.measureUserAgentSpecificMemory is not supported in this browser.');
    return null;
  }
}

if (this.config.logHeapUsage) {
  getMemoryUsage().then(heapUsed => {
    if (heapUsed !== null) {
      test.result!.heap = heapUsed;
      console.log('Heap Usage:', heapUsed);
    }
  });
}

@sheremet-va sheremet-va added pr welcome p2-nice-to-have Not breaking anything but nice to have (priority) p2-to-be-discussed Enhancement under consideration (priority) and removed pending triage p2-nice-to-have Not breaking anything but nice to have (priority) labels Sep 26, 2024
@sheremet-va sheremet-va added p2-nice-to-have Not breaking anything but nice to have (priority) and removed p2-to-be-discussed Enhancement under consideration (priority) labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome
Projects
Status: Approved
Development

No branches or pull requests

2 participants