Skip to content

Commit

Permalink
Remove debug and inspect flags from the arguments sent to the chi…
Browse files Browse the repository at this point in the history
…ld (#5068)

* Remove `debug` and `inspect` flags from the arguments sent to the child

* address PR comments
  • Loading branch information
SimenB authored and mjesun committed Dec 12, 2017
1 parent c3db693 commit f20344b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
15 changes: 9 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

### Fixes

* `[jest-worker]` Remove `debug` and `inspect` flags from the arguments sent to
the child ([#5068](https://github.com/facebook/jest/pull/5068))
* `[jest-config]` Use all `--testPathPattern` and `<regexForTestFiles>` args in
`testPathPattern`([#5066](https://github.com/facebook/jest/pull/5066))
* `[jest-cli]` Do not support `--watch` inside non-version-controlled environments
([#5060](https://github.com/facebook/jest/pull/5060))
`testPathPattern` ([#5066](https://github.com/facebook/jest/pull/5066))
* `[jest-cli]` Do not support `--watch` inside non-version-controlled
environments ([#5060](https://github.com/facebook/jest/pull/5060))
* `[jest-config]` Escape Windows path separator in testPathPattern CLI arguments
([#5054](https://github.com/facebook/jest/pull/5054)
* `[jest-jasmine]` Register sourcemaps as node environment to improve performance with jsdom ([#5045](https://github.com/facebook/jest/pull/5045))
* `[jest-jasmine]` Register sourcemaps as node environment to improve
performance with jsdom ([#5045](https://github.com/facebook/jest/pull/5045))
* `[pretty-format]` Do not call toJSON recursively
([#5044](https://github.com/facebook/jest/pull/5044))
* `[pretty-format]` Fix errors when identity-obj-proxy mocks CSS Modules
Expand Down Expand Up @@ -66,8 +69,8 @@

### Features

* `[jest-config]` Add `testEnvironmentOptions` to apply to jsdom options or node context.
([#5003](https://github.com/facebook/jest/pull/5003))
* `[jest-config]` Add `testEnvironmentOptions` to apply to jsdom options or node
context. ([#5003](https://github.com/facebook/jest/pull/5003))
* `[jest-jasmine2]` Update Timeout error message to `jest.timeout` and display
current timeout value ([#4990](https://github.com/facebook/jest/pull/4990))
* `[jest-runner]` Enable experimental detection of leaked contexts
Expand Down
25 changes: 13 additions & 12 deletions docs/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ environment. You don't have to require or import anything to use them.
Runs a function after all the tests in this file have completed. If the function
returns a promise, Jest waits for that promise to resolve before continuing.

Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait
before aborting. _Note: The default timeout is 5 seconds._
Optionally, you can provide a `timeout` (in milliseconds) for specifying how
long to wait before aborting. _Note: The default timeout is 5 seconds._

This is often useful if you want to clean up some global setup state that is
shared across tests.
Expand Down Expand Up @@ -66,8 +66,8 @@ Runs a function after each one of the tests in this file completes. If the
function returns a promise, Jest waits for that promise to resolve before
continuing.

Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait
before aborting. _Note: The default timeout is 5 seconds._
Optionally, you can provide a `timeout` (in milliseconds) for specifying how
long to wait before aborting. _Note: The default timeout is 5 seconds._

This is often useful if you want to clean up some temporary state that is
created by each test.
Expand Down Expand Up @@ -112,8 +112,8 @@ If you want to run some cleanup just once, after all of the tests run, use
Runs a function before any of the tests in this file run. If the function
returns a promise, Jest waits for that promise to resolve before running tests.

Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait
before aborting. _Note: The default timeout is 5 seconds._
Optionally, you can provide a `timeout` (in milliseconds) for specifying how
long to wait before aborting. _Note: The default timeout is 5 seconds._

This is often useful if you want to set up some global state that will be used
by many tests.
Expand Down Expand Up @@ -157,8 +157,8 @@ Runs a function before each of the tests in this file runs. If the function
returns a promise, Jest waits for that promise to resolve before running the
test.

Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait
before aborting. _Note: The default timeout is 5 seconds._
Optionally, you can provide a `timeout` (in milliseconds) for specifying how
long to wait before aborting. _Note: The default timeout is 5 seconds._

This is often useful if you want to reset some global state that will be used by
many tests.
Expand Down Expand Up @@ -327,8 +327,9 @@ test('did not rain', () => {
```

The first argument is the test name; the second argument is a function that
contains the expectations to test. The third argument (optional) is `timeout` (in milliseconds)
for specifying how long to wait before aborting. _Note: The default timeout is 5 seconds._
contains the expectations to test. The third argument (optional) is `timeout`
(in milliseconds) for specifying how long to wait before aborting. _Note: The
default timeout is 5 seconds._

> Note: If a **promise is returned** from `test`, Jest will wait for the promise
> to resolve before letting the test complete. Jest will also wait if you
Expand Down Expand Up @@ -358,8 +359,8 @@ When you are debugging a large codebase, you will often only want to run a
subset of tests. You can use `.only` to specify which tests are the only ones
you want to run.

Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait
before aborting. _Note: The default timeout is 5 seconds._
Optionally, you can provide a `timeout` (in milliseconds) for specifying how
long to wait before aborting. _Note: The default timeout is 5 seconds._

For example, let's say you had these tests:

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ to `3`, pass `Infinity` to allow endless retries.
#### `forkOptions: Object` (optional)

Allow customizing all options passed to `childProcess.fork`. By default, some
values are set (`cwd` and `env`), but you can override them and customize the
rest. For a list of valid values, check
values are set (`cwd`, `env` and `execArgv`), but you can override them and
customize the rest. For a list of valid values, check
[the Node documentation](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).

#### `computeWorkerKey: (method: string, ...args: Array<any>) => ?string` (optional)
Expand Down
11 changes: 9 additions & 2 deletions packages/jest-worker/src/__tests__/worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import {
let Worker;
let forkInterface;
let childProcess;
let originalExecArgv;

beforeEach(() => {
jest.mock('child_process');
originalExecArgv = process.execArgv;

childProcess = require('child_process');
childProcess.fork.mockImplementation(() => {
Expand All @@ -41,14 +43,18 @@ beforeEach(() => {

afterEach(() => {
jest.resetModules();
process.execArgv = originalExecArgv;
});

it('passes fork options down to child_process.fork, adding the defaults', () => {
const child = require.resolve('../child');

process.execArgv = ['--inspect', '-p'];

new Worker({
forkOptions: {
cwd: '/tmp',
execArgv: ['--no-warnings'],
execPath: 'hello',
},
maxRetries: 3,
workerPath: '/tmp/foo/bar/baz.js',
Expand All @@ -58,7 +64,8 @@ it('passes fork options down to child_process.fork, adding the defaults', () =>
expect(childProcess.fork.mock.calls[0][1]).toEqual({
cwd: '/tmp', // Overridden default option.
env: process.env, // Default option.
execArgv: ['--no-warnings'], // Added option.
execArgv: ['-p'], // Filtered option.
execPath: 'hello', // Added option.
silent: true, // Default option.
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-worker/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export default class {
{
cwd: process.cwd(),
env: process.env,
// suppress --debug / --inspect flags while preserving others (like --harmony)
execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)),
silent: true,
},
this._options.forkOptions,
Expand Down

0 comments on commit f20344b

Please sign in to comment.