Giter Site home page Giter Site logo

jest-resolve-bug's Introduction

jest-resolve-bug

A reproduction for a bug found in the default jest resolver (jest-resolve). This repo accompanies issue #7436 in the jest repo.

Reproduction steps

  1. Clone down this repo
  2. Run npm install
  3. Delete the file src/index.js
  4. Run the command npm run test-bug

The above run returns the following message:

No tests found related to files changed since last commit.

However, we can see that the only test file in the repo (src/index.spec.js) requires this file to run.

Running the command npm test fails as expected with the following message:

FAIL  src/index.spec.js
 โ— Test suite failed to run

   Cannot find module './index' from 'index.spec.js'

   > 1 | const index = require("./index");
       | ^
     2 |
     3 | test("that index returns hello world", () => {
     4 |   expect(index()).toBe("hello world");

     at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
     at Object.<anonymous> (src/index.spec.js:1:1)

Further debugging

At first I believed this was an issue to do with the changedSince command. Upon looking into how this CLI option operates (using the jest-changed-files package), I ran the following command in a node repl in the root of the repo:

require(`jest-changed-files`)
  .getChangedFilesForRoots([process.cwd()], {})
  .then(console.log);

and received the following output:

Promise {
  <pending>,
  domain:
   Domain {
     domain: null,
     _events:
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> { changedFiles:
   Set { '/Users/emilymcdonald/work/jest-resolve-bug/src/index.js' },
  repos:
   { git: Set { '/Users/emilymcdonald/work/jest-resolve-bug' },
     hg: Set {} } }

As can be seen above, the function correctly identifies that the file src/index.js has been modified (in this case, deleted). It is therefore the resolution process that is incorrectly not identifiying the need for src/index.spec.js to run.

jest-resolve-bug's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.