Skip to content

refactor: show error message from jest-worker#203

Merged
alexander-akait merged 1 commit into
webpack:masterfrom
pustovalov:jest-worker
Jan 9, 2020
Merged

refactor: show error message from jest-worker#203
alexander-akait merged 1 commit into
webpack:masterfrom
pustovalov:jest-worker

Conversation

@pustovalov

@pustovalov pustovalov commented Dec 27, 2019

Copy link
Copy Markdown
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

#143 (comment)

 looks like bug in jest-worker

jestjs/jest#8872 (comment)

https://github.com/facebook/jest/blob/master/packages/jest-worker/src/workers/ChildProcessWorker.ts#L93

I think these changes will help to find a problem

Breaking Changes

Nope

Additional Info

@jsf-clabot

jsf-clabot commented Dec 27, 2019

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Dec 27, 2019

Copy link
Copy Markdown

Codecov Report

Merging #203 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
+ Coverage   98.44%   98.45%   +<.01%     
==========================================
  Files           7        7              
  Lines         387      388       +1     
  Branches      155      156       +1     
==========================================
+ Hits          381      382       +1     
  Misses          6        6
Impacted Files Coverage Δ
src/TaskRunner.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e2da43...b29d3ef. Read the comment docs.

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

jamesgeorge007
jamesgeorge007 previously approved these changes Dec 29, 2019

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add test(s) where we can see what an error appears?

@pustovalov

Copy link
Copy Markdown
Contributor Author

I will try

@pustovalov

Copy link
Copy Markdown
Contributor Author

When writing a test, I found silent:false doesn’t work, thanks to this demo: https://github.com/tedconn/worker-jest-ts

forkOptions: {
    silent: false,
},

[~/Downloads/worker-jest-ts-master]$ npm test                                                                                                                                        [ruby-2.6.1]

> [email protected] test /Users/pavel/Downloads/worker-jest-ts-master
> jest --forceExit

 FAIL  src/__tests__/index.test.js
  invokes the compiler
    ✕ prints the right message (262ms)

  ● invokes the compiler › prints the right message

    Call retries were exceeded

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

Test Suites: 1 failed, 1 total

Change silent: false to this one

if (worker.getStderr()) worker.getStderr().pipe(process.stderr)

result:

[~/Downloads/worker-jest-ts-master]$ npm test                                                                                                                                        [ruby-2.6.1]

> [email protected] test /Users/pavel/Downloads/worker-jest-ts-master
> jest --forceExit

/Users/pavel/Downloads/worker-jest-ts-master/src/compiler.ts:1
export async function compile() {
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1055:16)
    at Module._compile (internal/modules/cjs/loader.js:1103:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at execMethod (/Users/pavel/Downloads/worker-jest-ts-master/node_modules/jest-worker/build/workers/processChild.js:128:16)
    at process.<anonymous> (/Users/pavel/Downloads/worker-jest-ts-master/node_modules/jest-worker/build/workers/processChild.js:64:7)
    at process.emit (events.js:305:20)
/Users/pavel/Downloads/worker-jest-ts-master/src/compiler.ts:1
export async function compile() {
^^^^^^

  invokes the compiler
    ✕ prints the right message (289ms)

  ● invokes the compiler › prints the right message

    Call retries were exceeded

      at ChildProcessWorker.initialize (node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total

but even with if (worker.getStderr()) worker.getStderr().pipe(process.stderr) I did not find a way to write a test for this

If I put process.exit(1) to the worker.js, I see this an error:

  console.log src/TaskRunner.js:60
    er Error: Call retries were exceeded
        at ChildProcessWorker.initialize (/Users/pavel/terser-webpack-plugin/node_modules/jest-worker/build/workers/ChildProcessWorker.js:193:21)
        at ChildProcessWorker.onExit (/Users/pavel/terser-webpack-plugin/node_modules/jest-worker/build/workers/ChildProcessWorker.js:264:12)
        at ChildProcess.emit (events.js:305:20)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
      type: 'WorkerError'
    }

I think we see this error because the process does not have enough memory and it crashes, maybe we can add some debug information to the
https://github.com/webpack-contrib/terser-webpack-plugin/blob/master/src/TaskRunner.js#L47

something like this

const showMemoryUsage = (step = '') => {
  const used = process.memoryUsage().heapUsed / 1024 / 1024;
  console.log(`Memory used ${step}: ${Math.round(used * 100) / 100} MB`);
};

showMemoryUsage('on worker error');

@alexander-akait

Copy link
Copy Markdown
Member

In theory crash can be not only because of memory, I think we can then avoid the tests, let's just add comments to the code, why are we doing this

@pustovalov

pustovalov commented Jan 6, 2020

Copy link
Copy Markdown
Contributor Author

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants