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

Support jest-preset.js files within Node modules. #4499

Closed
wants to merge 3 commits into from
Closed

Support jest-preset.js files within Node modules. #4499

wants to merge 3 commits into from

Conversation

milesj
Copy link

@milesj milesj commented Sep 18, 2017

Summary

Currently, Jest configuration may be a .json or .js file, but presets only support .json. This PR makes a change to also support jest-preset.js files within node modules.

This change would allow modules to make use of process.env.NODE_ENV.

Test plan

Unit tests.

[17:16:03] Miles:jest > yrun jest ./packages/jest-config/
yarn run v1.0.2
$ node ./packages/jest-cli/bin/jest.js "./packages/jest-config/"
 PASS  packages/jest-config/src/__tests__/normalize.test.js
 PASS  packages/jest-config/src/__tests__/resolve_config_path.test.js
 PASS  packages/jest-config/src/__tests__/set_from_argv.test.js
 PASS  packages/jest-config/src/__tests__/get_max_workers.test.js
 PASS  packages/jest-config/src/__tests__/validate_pattern.test.js

Test Suites: 5 passed, 5 total
Tests:       65 passed, 65 total
Snapshots:   5 passed, 5 total
Time:        0.776s, estimated 1s
Ran all test suites matching /.\/packages\/jest-config\//i.

And I've verified relative filesystem paths in another project of mine.

"jest": {
  "preset": "./node_modules/@milesj/build-tool-config/jest-preset.json",
  "roots": [
    "./packages",
    "./tests"
  ],
  "testRegex": "./packages/([-a-z]+)?/tests/.*\\.test\\.js$"
},

@codecov-io
Copy link

Codecov Report

Merging #4499 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4499      +/-   ##
=========================================
+ Coverage   56.85%   56.9%   +0.04%     
=========================================
  Files         186     186              
  Lines        6300    6304       +4     
  Branches        3       3              
=========================================
+ Hits         3582    3587       +5     
+ Misses       2717    2716       -1     
  Partials        1       1
Impacted Files Coverage Δ
packages/jest-config/src/normalize.js 78.6% <100%> (+0.46%) ⬆️
packages/jest-config/src/utils.js 75% <0%> (+2.27%) ⬆️

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 beb77e2...fa4dfdb. Read the comment docs.

},
);
const foundModule = PRESET_EXTENSIONS.some(ext => {
const presetModule = Resolver.findNodeModule(
Copy link
Member

Choose a reason for hiding this comment

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

findNodeModule has an extensions options. Mind simplifying your code a bit? :)

Copy link
Author

Choose a reason for hiding this comment

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

Awesome! Will update.


try {
// $FlowFixMe
preset = (require(presetModule): InitialOptions);
Copy link
Member

Choose a reason for hiding this comment

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

I worry about this not working with multiple projects, you'd want the preset to be re-evaluated every time. Can we remove it from the require.cache right after requiring it? :)

Copy link
Member

Choose a reason for hiding this comment

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

And guard that in a separate try-catch, I don't want Jest to rely on require.cache to be present :D

@cpojer
Copy link
Member

cpojer commented Sep 18, 2017

I like it. Added two comments to simplify the code and make it more resilient :)

@milesj
Copy link
Author

milesj commented Sep 19, 2017

@cpojer So I'm trying to use the extensions option but it short-circuits before it actually reaches the code to do so, which is here: https://github.com/facebook/jest/blob/master/packages/jest-resolve/src/default_resolver.js#L95

I added some logging, console.log('tryResolve', name, dir, 'isdir=', isDirectory(dir));, and it looks like isDirectory always returns false. Here's the output: tryResolve /node_modules/with-json-ext/jest-preset /node_modules/with-json-ext isdir= false. Not sure where my issue is or if it's an issue with virtual mock.

@cpojer
Copy link
Member

cpojer commented Sep 19, 2017

yeah it seems like your path is wrong, because it is absolute, not relative to the preset.

@milesj
Copy link
Author

milesj commented Sep 19, 2017

@cpojer This is actually failing for the existing react-native tests as well. I'll dig around a bit more.

@bbrzoska
Copy link

It would be a great feature to have.

Our use case requires us to generate the transformIgnorePatterns regexp based on the list of yarn workspaces (we're not precompiling those). If we could generate it in the preset it would be a huge win, since right now we have hacked this in as a custom "transform" that basically returns src when the file is ought to be ignored. That's really slow though :(.

@milesj
Copy link
Author

milesj commented Oct 27, 2017

I'll try and tackle this again this weekend.

@bbrzoska
Copy link

bbrzoska commented Dec 5, 2017

Hi @milesj, do you think this could land before v22 is released? Thanks!

@milesj
Copy link
Author

milesj commented Dec 6, 2017

@bazyli-brzoska I keep forgetting about this :P But most likely can tackle it this week.

@cpojer
Copy link
Member

cpojer commented Dec 15, 2017

@milesj hey! Did you ever find time to take another look at this? Thanks.

@milesj
Copy link
Author

milesj commented Dec 15, 2017

@cpojer I looked a little bit but ran into the same issues. Haven't had enough time due to the holidays.

@bbrzoska
Copy link

@cpojer I could take a look -- what's the ETA before v22 release so I can estimate how much time we have?

@cpojer
Copy link
Member

cpojer commented Dec 18, 2017

Literally two minutes.

@thymikee
Copy link
Collaborator

@bazyli-brzoska if all goes well, we release today. But this feature can land in a feature release, e.g. 22.1, it's not a blocker so no worries.

@milesj
Copy link
Author

milesj commented Dec 19, 2017

Sorry guys, holidays got in the way. That being said, my christmas break started yesterday, so I'll definitely have time. Most likely today or tomorrow (assuming no one has started it yet).

@niieani
Copy link
Contributor

niieani commented Dec 19, 2017

@milesj No pressure, after all, we do it in our free time ;) I haven't started yet, so it's all yours. 💪

@milesj
Copy link
Author

milesj commented Dec 21, 2017

I rebased and made some changes. However, I seem to be having issues with my Yarn installation that I can't seem to resolve. Continuously getting this kind of output:

[-/4] ⠈ waiting...
[-/4] ⠈ waiting...
[-/4] ⡀ waiting...
[-/4] ⠁ waiting...
[-/4] ⠄ waiting...
[-/4] ⠄ waiting...
[-/4] ⠄ waiting...
[4/4] ⠄ weak
[3/4] 🔗  Linking dependencies...
warning " > [email protected]" has unmet peer dependency "enzyme@^3.0.0".
warning " > [email protected]" has unmet peer dependency "react@^16.0.0-0".
warning " > [email protected]" has unmet peer dependency "react-dom@^16.0.0-0".
[-/4] ⡀ waiting...
[-/4] ⢀ waiting...
[-/4] ⢀ waiting...
[-/4] ⢀ waiting...
[4/4] ⢀ weak
[-/3] ⠄ waiting...
[2/3] ⠄ weak
[-/3] ⠄ waiting...
[-/3] ⠄ waiting...
[-/3] ⠄ waiti

@SimenB
Copy link
Member

SimenB commented Dec 21, 2017

My goto for those issues is yarn lerna clean (select yes) && rm -rf node_modules && yarn. Also make sure you're on latest yarn (1.3.2 currently).

@milesj
Copy link
Author

milesj commented Dec 21, 2017

The problem happens on all my projects and seems to be an issue with node-gyp/fsevents. Digging a bit further.

@milesj
Copy link
Author

milesj commented Dec 28, 2017

Got my yarn working again. Looking into this.

Edit: I rebased off master and it seems like test/builds currently fail, which is problematic for my testing. Will wait a bit.

@SimenB
Copy link
Member

SimenB commented Dec 29, 2017

Seems like legitimate failures, is it green locally for you?

@milesj
Copy link
Author

milesj commented Dec 29, 2017

My master (rebased today from upstream) has 17 failing tests.

Test Suites: 4 failed, 207 passed, 211 total
Tests: 17 failed, 1 skipped, 1771 passed, 1789 total
Snapshots: 687 passed, 687 total
Time: 65.077s, estimated 70s

@SimenB
Copy link
Member

SimenB commented Dec 30, 2017

Master is green on CI and on my machine. Have you tried what I suggested, yarn lerna clean (select yes) && rm -rf node_modules && yarn?

@milesj
Copy link
Author

milesj commented Dec 31, 2017

Yup a few times, here's the output.

[01:26:53] Miles:jest > yrun jest
yarn run v1.3.2
$ node ./packages/jest-cli/bin/jest.js
 FAIL  integration_tests/__tests__/jest_changed_files.test.js
  ● gets hg SCM roots and dedups them

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:41:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

  ● gets mixed git and hg SCM roots and dedups them

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:111:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

  ● gets changed files for hg

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:194:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

 FAIL  packages/jest-haste-map/src/__tests__/index.test.js
  ● HasteMap › builds a haste map on a fresh cache

    TypeError: Cannot read property 'clocks' of null

      258 | 
      259 |     return hasteMap.build().then(({__hasteMapForTest: data}) => {
    > 260 |       expect(data.clocks).toEqual(mockClocks);
      261 | 
      262 |       expect(data.files).toEqual({
      263 |         '/fruits/__mocks__/Pear.js': ['', 32, 1, ['Melon']],
      
      at hasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:260:19)

  ● HasteMap › retains all files if `retainAllFiles` is specified

    TypeError: Cannot read property 'files' of null

      320 |       // Expect the node module to be part of files but make sure it wasn't
      321 |       // read.
    > 322 |       expect(data.files['/fruits/node_modules/fbjs/index.js']).toEqual([
      323 |         '',
      324 |         32,
      325 |         0,
      
      at hasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:322:19)

  ● HasteMap › warns on duplicate module ids

    TypeError: Cannot read property 'map' of null

      370 |         // Duplicate modules are removed so that it doesn't cause
      371 |         // non-determinism later on.
    > 372 |         expect(data.map.Strawberry[H.GENERIC_PLATFORM]).not.toBeDefined();
      373 | 
      374 |         expect(console.warn.mock.calls[0][0]).toMatchSnapshot();
      375 |       });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:372:19)

  ● HasteMap › splits up modules by platform

    TypeError: Cannot read property 'files' of null

      420 |       .build()
      421 |       .then(({__hasteMapForTest: data}) => {
    > 422 |         expect(data.files).toEqual({
      423 |           '/fruits/strawberry.android.js': [
      424 |             'Strawberry',
      425 |             32,
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:422:19)

  ● HasteMap › does not access the file system on a warm cache with no changes

    TypeError: Cannot read property 'clocks' of null

      466 |             expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8');
      467 | 
    > 468 |             expect(data.clocks).toEqual(mockClocks);
      469 |             expect(data.files).toEqual(initialData.files);
      470 |             expect(data.map).toEqual(initialData.map);
      471 |           });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:468:21)

  ● HasteMap › only does minimal file system access when files change

    TypeError: Cannot read property 'clocks' of null

      503 |             expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8');
      504 | 
    > 505 |             expect(data.clocks).toEqual(mockClocks);
      506 | 
      507 |             const files = object(initialData.files);
      508 |             files['/fruits/banana.js'] = ['Kiwi', 32, 1, ['Raspberry']];
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:505:21)

  ● HasteMap › correctly handles file deletions

    TypeError: Cannot read property 'files' of null

      540 |           .build()
      541 |           .then(({__hasteMapForTest: data}) => {
    > 542 |             const files = object(initialData.files);
      543 |             delete files['/fruits/banana.js'];
      544 |             expect(data.files).toEqual(files);
      545 | 
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:542:42)

  ● HasteMap › duplicate modules › recovers when a duplicate file is deleted

    TypeError: Cannot read property 'duplicates' of null

      563 |         defaultConfig,
      564 |       ).build();
    > 565 |       expect(data.duplicates).toEqual({
      566 |         Strawberry: {
      567 |           g: {'/fruits/another_strawberry.js': 0, '/fruits/strawberry.js': 0},
      568 |         },
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:565:19)

  ● HasteMap › duplicate modules › recovers when a duplicate file is deleted

    TypeError: Cannot read property 'duplicates' of null

      584 |         defaultConfig,
      585 |       ).build();
    > 586 |       expect(data.duplicates).toEqual({});
      587 |       expect(data.map['Strawberry']).toEqual({g: ['/fruits/strawberry.js', 0]});
      588 |       // Make sure the other files are not affected.
      589 |       expect(data.map['Banana']).toEqual({g: ['/fruits/banana.js', 0]});
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:586:19)

  ● HasteMap › duplicate modules › recovers when a duplicate module is renamed

    TypeError: Cannot read property 'duplicates' of null

      563 |         defaultConfig,
      564 |       ).build();
    > 565 |       expect(data.duplicates).toEqual({
      566 |         Strawberry: {
      567 |           g: {'/fruits/another_strawberry.js': 0, '/fruits/strawberry.js': 0},
      568 |         },
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:565:19)

  ● HasteMap › duplicate modules › recovers when a duplicate module is renamed

    TypeError: Cannot read property 'duplicates' of null

      607 |         defaultConfig,
      608 |       ).build();
    > 609 |       expect(data.duplicates).toEqual({});
      610 |       expect(data.map['Strawberry']).toEqual({g: ['/fruits/strawberry.js', 0]});
      611 |       expect(data.map['AnotherStrawberry']).toEqual({
      612 |         g: ['/fruits/another_strawberry.js', 0],
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:609:19)

  ● HasteMap › ignores files that do not exist

    TypeError: Cannot read property 'files' of null

      654 |       .build()
      655 |       .then(({__hasteMapForTest: data}) => {
    > 656 |         expect(Object.keys(data.files).length).toBe(5);
      657 | 
      658 |         // Ensure this file is not part of the file list.
      659 |         expect(data.files['/fruits/invalid/file.js']).toBe(undefined);
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:656:31)

  ● HasteMap › tries to crawl using node as a fallback

    TypeError: Cannot read property 'files' of null

      707 |         expect(node).toBeCalled();
      708 | 
    > 709 |         expect(data.files).toEqual({
      710 |           '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']],
      711 |         });
      712 | 
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:709:19)

  ● HasteMap › tries to crawl using node as a fallback when promise fails once

    TypeError: Cannot read property 'files' of null

      736 |         expect(node).toBeCalled();
      737 | 
    > 738 |         expect(data.files).toEqual({
      739 |           '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']],
      740 |         });
      741 |       });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:738:19)

 PASS  integration_tests/__tests__/timeouts.test.js (5.681s)
 PASS  integration_tests/__tests__/custom_reporters.test.js (17.326s)
 PASS  integration_tests/__tests__/jasmine_async.test.js (17.015s)
 PASS  integration_tests/__tests__/multi_project_runner.test.js (21.897s)
 PASS  integration_tests/__tests__/snapshot.test.js (24.041s)
 PASS  integration_tests/__tests__/transform.test.js (25.67s)
 PASS  integration_tests/__tests__/coverage_report.test.js (25.881s)
 FAIL  integration_tests/__tests__/only_changed.test.js (26.753s)
  ● gets changed files for hg

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/only_changed.test.js:156:3)
      at step (integration_tests/__tests__/only_changed.test.js:14:349)
      at integration_tests/__tests__/only_changed.test.js:14:579
      at Object.<anonymous> (integration_tests/__tests__/only_changed.test.js:14:260)

 PASS  integration_tests/__tests__/globals.test.js (9.99s)
 PASS  integration_tests/__tests__/mock_names.test.js (9.087s)
 PASS  integration_tests/__tests__/test_path_pattern_reporter_message.test.js (9.84s)
 PASS  packages/jest-runtime/src/__tests__/runtime_cli.test.js (8.611s)
 PASS  integration_tests/__tests__/stack_trace.test.js (7.912s)
 PASS  integration_tests/__tests__/to_match_snapshot.test.js (15.829s)
 PASS  integration_tests/__tests__/failures.test.js (9.378s)
 PASS  integration_tests/__tests__/jest_require_mock.test.js (5.482s)
 PASS  integration_tests/__tests__/babel_plugin_jest_hoist.test.js (6.341s)
 PASS  integration_tests/__tests__/jest_require_actual.test.js
 PASS  integration_tests/__tests__/console.test.js (5.241s)
 PASS  integration_tests/__tests__/env.test.js (5.121s)
 PASS  integration_tests/__tests__/config.test.js (6.744s)
 PASS  integration_tests/__tests__/jest.config.js.test.js (5.223s)
 PASS  integration_tests/__tests__/debug.test.js
 PASS  integration_tests/__tests__/test_failure_exit_code.test.js
 PASS  integration_tests/__tests__/coverage_remapping.test.js (5.008s)
 PASS  integration_tests/__tests__/typescript_coverage.test.js
 PASS  integration_tests/__tests__/module_name_mapper.test.js (5.735s)
 PASS  packages/jest-runtime/src/__tests__/script_transformer.test.js (5.154s)
 PASS  integration_tests/__tests__/to_throw_error_matching_snapshot.test.js (6.5s)
 PASS  packages/jest-runtime/src/__tests__/runtime_require_module_or_mock.test.js
 PASS  integration_tests/__tests__/use_stderr.test.js
 PASS  integration_tests/__tests__/coverage_threshold.test.js
 PASS  integration_tests/__tests__/nested_event_loop.test.js
 PASS  integration_tests/__tests__/native_async_mock.test.js
 PASS  integration_tests/__tests__/run_tests_by_path.test.js
 PASS  integration_tests/__tests__/find_related_files.test.js
 PASS  integration_tests/__tests__/snapshot_serializers.test.js (5.231s)
 PASS  integration_tests/__tests__/force_exit.test.js
 PASS  packages/jest-repl/src/__tests__/jest_repl.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_require_module_or_mock_transitive_deps.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_mock.test.js
 PASS  integration_tests/__tests__/clear_cache.test.js
 PASS  integration_tests/__tests__/console_log_output_when_run_in_band.test.js
 PASS  integration_tests/__tests__/json_reporter.test.js
 PASS  integration_tests/__tests__/compare_dom_nodes.test.js
 PASS  integration_tests/__tests__/auto_clear_mocks.test.js
 PASS  integration_tests/__tests__/location_in_results.test.js
 PASS  integration_tests/__tests__/stack_trace_no_captureStackTrace.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_environment.test.js
 PASS  integration_tests/__tests__/setup_test_framework_script_file_cli_config.test.js
 PASS  integration_tests/__tests__/test_environment_async.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_require_mock.test.js
 PASS  integration_tests/__tests__/test_environment.test.js
 PASS  integration_tests/__tests__/timer_reset_mocks.test.js
 PASS  integration_tests/__tests__/auto_reset_mocks.test.js
 PASS  integration_tests/__tests__/runtime_internal_module_registry.test.js
 PASS  integration_tests/__tests__/timer_use_real_timers.test.js
 PASS  integration_tests/__tests__/global_setup.test.js
 PASS  packages/jest-cli/src/__tests__/run_jest.test.js
 PASS  examples/typescript/__tests__/checkbox_with_label.test.tsx
  ● Console

    console.warn node_modules/react/lib/lowPriorityWarning.js:38
      Warning: Accessing createClass via the main React package is deprecated, and will be removed in React v16.0. Use a plain JavaScript class instead. If you're not yet ready to migrate, create-react-class v15.* is available on npm as a temporary, drop-in replacement. For more info see https://fb.me/react-create-class

 PASS  integration_tests/__tests__/test_results_processor.test.js
 PASS  packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.js
 PASS  integration_tests/__tests__/log_heap_usage.test.js
 PASS  integration_tests/__tests__/transform-linked-modules.test.js
 PASS  examples/enzyme/__tests__/checkbox_with_label.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_require_module.test.js
 PASS  integration_tests/__tests__/verbose.test.js
 PASS  packages/expect/src/__tests__/matchers.test.js
 PASS  integration_tests/__tests__/test_name_pattern.test.js
 PASS  integration_tests/__tests__/override-globals.test.js
 PASS  integration_tests/__tests__/test_in_root.test.js
 PASS  integration_tests/__tests__/set_immediate.test.js
 PASS  integration_tests/__tests__/global_teardown.test.js
 PASS  integration_tests/__tests__/resolve.test.js
 PASS  integration_tests/__tests__/pass_with_no_tests.test.js
 PASS  integration_tests/__tests__/empty_suite_error.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_node_path.test.js
 PASS  packages/jest-test-typescript-parser/src/__tests__/type_script_parser.test.js
 PASS  integration_tests/__tests__/no_test_found.test.js
 PASS  packages/jest-runtime/src/__tests__/resolve_browser.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_internal_module.test.js
 PASS  examples/typescript/__tests__/sum.test.js
 PASS  integration_tests/__tests__/list_tests.test.js
 PASS  integration_tests/__tests__/regex_(char_in_path.test.js
 PASS  integration_tests/__tests__/node_path.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js
 PASS  packages/jest-cli/src/__tests__/test_scheduler.test.js
 PASS  packages/jest-editor-support/src/__tests__/snapshot.test.js
 PASS  examples/react-native/__tests__/intro.test.js
 PASS  packages/jest-leak-detector/src/__tests__/index.test.js
 PASS  integration_tests/__tests__/show_config.test.js
 PASS  examples/snapshot/__tests__/clock.react.test.js
 PASS  packages/pretty-format/src/__tests__/immutable.test.js
 PASS  packages/jest-cli/src/__tests__/search_source.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_jest_fn.js
 PASS  packages/jest-runtime/src/__tests__/instrumentation.test.js
 PASS  integration_tests/__tests__/version.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_module_directories.test.js
 PASS  examples/manual_mocks/__tests__/file_summarizer.test.js
 PASS  examples/react/__tests__/checkbox_with_label.test.js
  ● Console

    console.warn node_modules/react-addons-test-utils/index.js:31
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

 PASS  examples/jquery/__tests__/display_user.test.js
 PASS  examples/jquery/__tests__/fetch_current_user.test.js
 PASS  packages/jest-util/src/__tests__/fake_timers.test.js
 PASS  packages/pretty-format/src/__tests__/dom_element.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_gen_mock_from_module.test.js
 PASS  examples/snapshot/__tests__/link.react.test.js
 PASS  packages/jest-matcher-utils/src/__tests__/index.test.js
 PASS  packages/jest-runtime/src/__tests__/runtime_jest_spy_on.test.js
 PASS  packages/jest-cli/src/__tests__/watch.test.js
 PASS  packages/jest-config/src/__tests__/normalize.test.js
 PASS  packages/jest-runtime/src/__tests__/Runtime-sourceMaps.test.js
 PASS  examples/typescript/__tests__/sub-test.ts
 PASS  examples/timer/__tests__/infinite_timer_game.test.js
  ● Console

    console.log examples/timer/infiniteTimerGame.js:4
      Ready....go!
    console.log examples/timer/infiniteTimerGame.js:7
      Times up! 10 seconds before the next game starts...

 PASS  packages/jest-cli/src/reporters/__tests__/coverage_worker.test.js
 PASS  packages/jest-resolve-dependencies/src/__tests__/dependency_resolver.test.js
 PASS  packages/jest-cli/src/__tests__/watch_filename_pattern_mode.test.js
 PASS  examples/timer/__tests__/timer_game.test.js
  ● Console

    console.log examples/timer/timerGame.js:4
      Ready....go!
    console.log examples/timer/timerGame.js:4
      Ready....go!
    console.log examples/timer/timerGame.js:6
      Times up -- stop!
    console.log examples/timer/timerGame.js:6
      Times up -- stop!
    console.log examples/timer/timerGame.js:4
      Ready....go!
    console.log examples/timer/timerGame.js:6
      Times up -- stop!

 PASS  packages/jest-editor-support/src/__tests__/parsers/babylon_parser.test.js
 PASS  packages/expect/src/__tests__/spy_matchers.test.js
 PASS  packages/expect/src/__tests__/utils.test.js
 PASS  packages/jest-mock/src/__tests__/jest_mock.test.js
 PASS  packages/jest-worker/src/__tests__/index.test.js
 PASS  packages/jest-cli/src/__tests__/generate_empty_coverage.test.js
 PASS  packages/jest-resolve/src/__tests__/is_builtin_module.test.js
 PASS  packages/pretty-format/src/__tests__/react.test.js
 PASS  packages/jest-diff/src/__tests__/diff.test.js
 PASS  packages/jest-haste-map/src/__tests__/get_mock_name.test.js
 PASS  packages/jest-cli/src/lib/__tests__/is_valid_path.test.js
 PASS  packages/pretty-format/src/__tests__/pretty_format.test.js
 PASS  packages/jest-runner/src/__tests__/test_runner.test.js
 PASS  examples/module_mock/__tests__/partial_mock.js
 PASS  integration_tests/__tests__/require_v8_module.test.js
 PASS  packages/expect/src/__tests__/to_throw_matchers.test.js
 PASS  packages/expect/src/__tests__/extend.test.js
 PASS  packages/jest-resolve/src/__tests__/resolve.test.js
 PASS  packages/jest-validate/src/__tests__/validate.test.js
 PASS  packages/jest-cli/src/lib/__tests__/prompt.test.js
 PASS  packages/pretty-format/src/__tests__/asymmetric_matcher.test.js
 PASS  packages/jest-worker/src/__tests__/worker.test.js
 PASS  packages/jest-cli/src/__tests__/globals.test.js
 PASS  examples/getting_started/sum.test.js
 PASS  integration_tests/timer-resetMocks/after_resetAllMocks/timer_and_mock.test.js
 PASS  packages/expect/src/__tests__/asymmetric_matchers.test.js
 PASS  packages/jest-editor-support/src/__tests__/test_reconciler.test.js
 PASS  packages/jest-jasmine2/src/__tests__/queue_runner.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/default_reporter.test.js
 PASS  packages/jest-snapshot/src/__tests__/throw_matcher.test.js
 PASS  packages/jest-snapshot/src/__tests__/utils.test.js
 PASS  packages/jest-cli/src/__tests__/test_sequencer.test.js
 PASS  packages/jest-worker/src/__tests__/child.test.js
 PASS  packages/expect/src/__tests__/symbol_in_objects.test.js
 PASS  packages/jest-environment-node/src/__tests__/node_environment.test.js
 PASS  packages/jest-docblock/src/__tests__/index.test.js
 PASS  packages/jest-util/src/__tests__/validate_cli_options.test.js
 PASS  packages/jest-cli/src/__tests__/watch_test_name_pattern_mode.test.js
 PASS  integration_tests/test-in-root/test.js
 PASS  packages/jest-config/src/__tests__/validate_pattern.test.js
 PASS  packages/jest-runtime/src/__tests__/should_instrument.test.js
 PASS  packages/jest-message-util/src/__tests__/messages.test.js
 PASS  packages/jest-cli/src/lib/__tests__/format_test_name_by_pattern.test.js
 PASS  packages/jest-config/src/__tests__/set_from_argv.test.js
 PASS  packages/jest-get-type/src/__tests__/index.test.js
 PASS  packages/expect/src/__tests__/assertion_counts.test.js
 PASS  packages/jest-editor-support/src/__tests__/runner.test.js
 PASS  packages/jest-snapshot/src/__tests__/mock_serializer.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/verbose_reporter.test.js
 PASS  packages/jest-haste-map/src/__tests__/worker.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/utils.test.js
 PASS  packages/jest-jasmine2/src/__tests__/reporter.test.js
 PASS  packages/jest-util/src/__tests__/create_process_object.test.js
 PASS  packages/expect/src/__tests__/stacktrace.test.js
 PASS  examples/async/__tests__/user.test.js
 PASS  packages/jest-snapshot/src/__tests__/matcher.test.js
 PASS  packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js
 PASS  packages/jest-cli/src/__tests__/cli/args.test.js
 PASS  packages/jest-jasmine2/src/__tests__/p_timeout.test.js
 PASS  packages/jest-haste-map/src/crawlers/__tests__/node.test.js
 PASS  integration_tests/timer-resetMocks/with_resetMocks/timer_with_mock.test.js
 PASS  packages/jest-config/src/__tests__/resolve_config_path.test.js
 PASS  packages/jest-jasmine2/src/__tests__/expectation_result_factory.test.js
 PASS  examples/module_mock/__tests__/full_mock.js
 PASS  packages/jest-cli/src/lib/__tests__/scroll_list.test.js
 PASS  packages/jest-cli/src/lib/__tests__/log_debug_messages.test.js
 PASS  packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js
 PASS  integration_tests/test-in-root/spec.js
 PASS  packages/jest-config/src/__tests__/read_config.test.js
 PASS  integration_tests/__tests__/json.test.js
 PASS  packages/jest-editor-support/src/__tests__/project_workspace.test.js
 PASS  packages/jest-jasmine2/src/__tests__/it_to_test_alias.test.js
 PASS  packages/jest-haste-map/src/crawlers/__tests__/watchman.test.js
 PASS  packages/jest-util/src/__tests__/install_common_globals.test.js
 PASS  packages/jest-haste-map/src/lib/__tests__/get_platform_extension.test.js
 PASS  packages/jest-config/src/__tests__/get_max_workers.test.js
 PASS  integration_tests/__tests__/global.test.js
 PASS  packages/jest-util/src/__tests__/is_interactive.test.js
 PASS  packages/pretty-format/src/__tests__/convert_ansi.test.js
 PASS  packages/jest-editor-support/src/__tests__/settings.test.js
 PASS  packages/jest-util/src/__tests__/deep_cyclic_copy.test.js
 PASS  packages/jest-util/src/__tests__/format_test_results.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/get_snapshot_status.test.js
 PASS  packages/jest-jasmine2/src/__tests__/iterators.test.js
 PASS  packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js
 PASS  integration_tests/__tests__/symbol.test.js
 PASS  packages/jest-cli/src/__tests__/failed_tests_cache.test.js
 PASS  packages/jest-jasmine2/src/__tests__/integration/lifecycle_hooks_test.js
 PASS  packages/jest-jasmine2/src/__tests__/matchers.test.js
 PASS  packages/expect/src/__tests__/fake_chalk.test.js
 PASS  examples/module_mock/__tests__/mock_per_test.js
 PASS  examples/typescript/__tests__/sum-test.ts

Summary of all failing tests
 FAIL  integration_tests/__tests__/jest_changed_files.test.js
  ● gets hg SCM roots and dedups them

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:41:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

  ● gets mixed git and hg SCM roots and dedups them

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:111:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

  ● gets changed files for hg

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:194:3)
      at step (integration_tests/__tests__/jest_changed_files.test.js:14:338)
      at integration_tests/__tests__/jest_changed_files.test.js:14:568
      at Object.<anonymous> (integration_tests/__tests__/jest_changed_files.test.js:14:249)

 FAIL  packages/jest-haste-map/src/__tests__/index.test.js
  ● HasteMap › builds a haste map on a fresh cache

    TypeError: Cannot read property 'clocks' of null

      258 | 
      259 |     return hasteMap.build().then(({__hasteMapForTest: data}) => {
    > 260 |       expect(data.clocks).toEqual(mockClocks);
      261 | 
      262 |       expect(data.files).toEqual({
      263 |         '/fruits/__mocks__/Pear.js': ['', 32, 1, ['Melon']],
      
      at hasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:260:19)

  ● HasteMap › retains all files if `retainAllFiles` is specified

    TypeError: Cannot read property 'files' of null

      320 |       // Expect the node module to be part of files but make sure it wasn't
      321 |       // read.
    > 322 |       expect(data.files['/fruits/node_modules/fbjs/index.js']).toEqual([
      323 |         '',
      324 |         32,
      325 |         0,
      
      at hasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:322:19)

  ● HasteMap › warns on duplicate module ids

    TypeError: Cannot read property 'map' of null

      370 |         // Duplicate modules are removed so that it doesn't cause
      371 |         // non-determinism later on.
    > 372 |         expect(data.map.Strawberry[H.GENERIC_PLATFORM]).not.toBeDefined();
      373 | 
      374 |         expect(console.warn.mock.calls[0][0]).toMatchSnapshot();
      375 |       });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:372:19)

  ● HasteMap › splits up modules by platform

    TypeError: Cannot read property 'files' of null

      420 |       .build()
      421 |       .then(({__hasteMapForTest: data}) => {
    > 422 |         expect(data.files).toEqual({
      423 |           '/fruits/strawberry.android.js': [
      424 |             'Strawberry',
      425 |             32,
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:422:19)

  ● HasteMap › does not access the file system on a warm cache with no changes

    TypeError: Cannot read property 'clocks' of null

      466 |             expect(fs.readFileSync).toBeCalledWith(cacheFilePath, 'utf8');
      467 | 
    > 468 |             expect(data.clocks).toEqual(mockClocks);
      469 |             expect(data.files).toEqual(initialData.files);
      470 |             expect(data.map).toEqual(initialData.map);
      471 |           });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:468:21)

  ● HasteMap › only does minimal file system access when files change

    TypeError: Cannot read property 'clocks' of null

      503 |             expect(fs.readFileSync).toBeCalledWith('/fruits/banana.js', 'utf8');
      504 | 
    > 505 |             expect(data.clocks).toEqual(mockClocks);
      506 | 
      507 |             const files = object(initialData.files);
      508 |             files['/fruits/banana.js'] = ['Kiwi', 32, 1, ['Raspberry']];
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:505:21)

  ● HasteMap › correctly handles file deletions

    TypeError: Cannot read property 'files' of null

      540 |           .build()
      541 |           .then(({__hasteMapForTest: data}) => {
    > 542 |             const files = object(initialData.files);
      543 |             delete files['/fruits/banana.js'];
      544 |             expect(data.files).toEqual(files);
      545 | 
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:542:42)

  ● HasteMap › duplicate modules › recovers when a duplicate file is deleted

    TypeError: Cannot read property 'duplicates' of null

      563 |         defaultConfig,
      564 |       ).build();
    > 565 |       expect(data.duplicates).toEqual({
      566 |         Strawberry: {
      567 |           g: {'/fruits/another_strawberry.js': 0, '/fruits/strawberry.js': 0},
      568 |         },
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:565:19)

  ● HasteMap › duplicate modules › recovers when a duplicate file is deleted

    TypeError: Cannot read property 'duplicates' of null

      584 |         defaultConfig,
      585 |       ).build();
    > 586 |       expect(data.duplicates).toEqual({});
      587 |       expect(data.map['Strawberry']).toEqual({g: ['/fruits/strawberry.js', 0]});
      588 |       // Make sure the other files are not affected.
      589 |       expect(data.map['Banana']).toEqual({g: ['/fruits/banana.js', 0]});
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:586:19)

  ● HasteMap › duplicate modules › recovers when a duplicate module is renamed

    TypeError: Cannot read property 'duplicates' of null

      563 |         defaultConfig,
      564 |       ).build();
    > 565 |       expect(data.duplicates).toEqual({
      566 |         Strawberry: {
      567 |           g: {'/fruits/another_strawberry.js': 0, '/fruits/strawberry.js': 0},
      568 |         },
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:565:19)

  ● HasteMap › duplicate modules › recovers when a duplicate module is renamed

    TypeError: Cannot read property 'duplicates' of null

      607 |         defaultConfig,
      608 |       ).build();
    > 609 |       expect(data.duplicates).toEqual({});
      610 |       expect(data.map['Strawberry']).toEqual({g: ['/fruits/strawberry.js', 0]});
      611 |       expect(data.map['AnotherStrawberry']).toEqual({
      612 |         g: ['/fruits/another_strawberry.js', 0],
      
      at Object.<anonymous> (packages/jest-haste-map/src/__tests__/index.test.js:609:19)

  ● HasteMap › ignores files that do not exist

    TypeError: Cannot read property 'files' of null

      654 |       .build()
      655 |       .then(({__hasteMapForTest: data}) => {
    > 656 |         expect(Object.keys(data.files).length).toBe(5);
      657 | 
      658 |         // Ensure this file is not part of the file list.
      659 |         expect(data.files['/fruits/invalid/file.js']).toBe(undefined);
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:656:31)

  ● HasteMap › tries to crawl using node as a fallback

    TypeError: Cannot read property 'files' of null

      707 |         expect(node).toBeCalled();
      708 | 
    > 709 |         expect(data.files).toEqual({
      710 |           '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']],
      711 |         });
      712 | 
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:709:19)

  ● HasteMap › tries to crawl using node as a fallback when promise fails once

    TypeError: Cannot read property 'files' of null

      736 |         expect(node).toBeCalled();
      737 | 
    > 738 |         expect(data.files).toEqual({
      739 |           '/fruits/banana.js': ['Banana', 32, 1, ['Strawberry']],
      740 |         });
      741 |       });
      
      at HasteMap.build.then (packages/jest-haste-map/src/__tests__/index.test.js:738:19)

 FAIL  integration_tests/__tests__/only_changed.test.js (26.753s)
  ● gets changed files for hg

    
          ORIGINAL CMD: hg --config ui.username=jest_test init
          STDOUT: null
          STDERR: null
          STATUS: null
          ERROR: Error: spawnSync hg ENOENT

      31 |       ERROR: ${result.error && result.error.toString()}
      32 |     `;
    > 33 |     throw new Error(message);
      34 |   }
      35 | 
      36 |   result.stdout = result.stdout && result.stdout.toString();
      
          
      at run (integration_tests/utils.js:33:11)
      at Object.<anonymous> (integration_tests/__tests__/only_changed.test.js:156:3)
      at step (integration_tests/__tests__/only_changed.test.js:14:349)
      at integration_tests/__tests__/only_changed.test.js:14:579
      at Object.<anonymous> (integration_tests/__tests__/only_changed.test.js:14:260)


Test Suites: 3 failed, 208 passed, 211 total
Tests:       16 failed, 1 skipped, 1772 passed, 1789 total
Snapshots:   688 passed, 688 total
Time:        62.628s
Ran all test suites in 12 projects.
error Command failed with exit code 1.

@SimenB
Copy link
Member

SimenB commented Jan 1, 2018

Does it still happen if you install mercurial?

@cpojer
Copy link
Member

cpojer commented Jan 6, 2018

Hey guys! What's the status of this? The tests are clearly failing on CI, can we get that fixed and merge this PR? :)

@milesj
Copy link
Author

milesj commented Jan 6, 2018

I can't seem to get my fork to build correctly, even outside of this branch. So if anyone wants to take this over, feel free.

@cpojer
Copy link
Member

cpojer commented Feb 7, 2018

I'm gonna close this for now since there aren't any volunteers who are willing to take this over the finish line. If anybody sees this and wants this feature, please send a new PR rebased on top of master, with tests. Thanks!

@cpojer cpojer closed this Feb 7, 2018
@niieani
Copy link
Contributor

niieani commented Feb 7, 2018

@cpojer I'll put this on my backlog and I'll try to handle it within the next month or so.

@SimenB
Copy link
Member

SimenB commented May 22, 2018

For anyone following along, this has been merged in #6185

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants