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

Cannot have multiple tests files in the same folder #227

Closed
mjhamm75 opened this issue Jan 25, 2015 · 12 comments
Closed

Cannot have multiple tests files in the same folder #227

mjhamm75 opened this issue Jan 25, 2015 · 12 comments

Comments

@mjhamm75
Copy link

I have jest installed globally and when I run the command jest it says that I am Using Jest CLI v0.2.1. Here is my test file:

describe('ChangeTimePeriod', function() {
    it('true', function() {
        expect(3).toBe(3);
    })
});

When I have a single file in my ___tests___ directory everything works fine, but if I add any other test file, then I get this error

/usr/local/lib/node_modules/jest-cli/node_modules/node-worker-pool/Worker.js:93
    throw new Error('Received unexpected data from child process: ' + data);
          ^
Error: Received unexpected data from child process: {
  "error": "Error: ENOENT, open '/usr/local/lib/node_modules/jest-cli/.haste_cache/cache-react-calendar-component'\n\n"
}

  at Worker._onStdout (/usr/local/lib/node_modules/jest-cli/node_modules/node-worker-pool/Worker.js:93:11)
  at Socket.emit (events.js:95:17)
  at Socket.<anonymous> (_stream_readable.js:765:14)
  at Socket.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:427:10)
  at emitReadable (_stream_readable.js:423:5)
  at readableAddChunk (_stream_readable.js:166:9)
  at Socket.Readable.push (_stream_readable.js:128:10)
  at Pipe.onread (net.js:529:21)

I have tried deleting the files, changing the names and basically anything I can think of, but I have no idea what to do next. Any ideas?

@neemzy
Copy link

neemzy commented Feb 24, 2015

+1 here, any hints on this ?

Edit : FWIW, running jest once with sudo fixed the problem (I can now run it without). It seems to be an obscure permission-related issue with Jest's own .haste_cache folder or something.

@mjhamm75
Copy link
Author

Nope. I just wrote a script to loop through and run each individually.
Total hack but it works
On Tue, Feb 24, 2015 at 2:08 PM Tom Panier notifications@github.com wrote:

+1 here, any hints on this ?


Reply to this email directly or view it on GitHub
#227 (comment).

@tomatau
Copy link

tomatau commented Mar 24, 2015

Did anyone find any more information about this? I'm getting it when I enable one test file that was working just fine until now.

If I comment out all the code and gradually uncomment each line -- the error doesn't come back... but randomly when a test fails whilst developing later - the error will come back again and I need to go through this pointless comment/uncomment process to make it go away.

@mjhamm75
Copy link
Author

When I run with sudo I don't have any issues
On Tue, Mar 24, 2015 at 11:19 AM Thomas notifications@github.com wrote:

Did anyone find any more informatino about this? I'm getting it when I
enable one test file that was working just fine until now.


Reply to this email directly or view it on GitHub
#227 (comment).

@tomatau
Copy link

tomatau commented Mar 24, 2015

Sudo really shouldn't be required for running tests

@mjhamm75
Copy link
Author

agreed, but just saying that it works.

On Tue, Mar 24, 2015 at 4:42 PM Thomas notifications@github.com wrote:

Sudo really shouldn't be required for running tests


Reply to this email directly or view it on GitHub
#227 (comment).

@wuct
Copy link

wuct commented May 5, 2015

I find out that jest use the name in the package.json to create a cache file in the .haste_cache folder. So if I use a scoped package name, eg: @username/project-name, Jest will also include the / into the path of the cache file. It turns out to be an ENOENT error.

@whroman
Copy link

whroman commented Jun 1, 2015

+1

Node v0.10.36
Jest v0.4.5

@ericvicenti
Copy link

I also encountered this issue, but I managed to fix it. It looks like jest was looking through my dist files and got confused, because I fixed it by adding "testPathDirs": [ "<rootDir>/src" ], to my config.

Here is the whole jest config in my package.json:

  "devDependencies": {
    "babel-jest": "^5.2.0",
    "jest-cli": "^0.4.5"
  },
  "scripts": {
    "test": "BABEL_JEST_STAGE=0 jest"
  },
  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
    "testFileExtensions": [
      "js"
    ],
    "testPathDirs": [
      "<rootDir>/src"
    ],
    "moduleFileExtensions": [
      "js"
    ]
  }

grebaldi added a commit to reduct/component that referenced this issue Jul 23, 2015
@VirtueMe
Copy link

VirtueMe commented Aug 3, 2015

I had a similar problem on Ubuntu, found out that I installed jest-cli with sudo and as of that the .haste_cache is write protected unless your run your test with sudo.

My solution, sudo chown -R $(whoami) . && sudo chgrp -R $(whoami) . in the /usr/lib/node_modules/jest-cli/ folder. Afterwards I can run the npm test without using sudo.

It would be nice if jest-cli used a local .jest-haste-cache folder under the root folder of the project to avoid problems like these.

@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

this should work fine in jest 0.6.0.

@github-actions
Copy link

This issue 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 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants