最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I cannot run multiple test files with Jest? - Stack Overflow

programmeradmin2浏览0评论

I have just started with Jest today. I have a simple test file in my __tests__ directory. Here is the current test file:

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

This runs with no issue. When I add another file, with the same exact code, other than the description:

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

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)

Does this make sense to anyone?

I have just started with Jest today. I have a simple test file in my __tests__ directory. Here is the current test file:

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

This runs with no issue. When I add another file, with the same exact code, other than the description:

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

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)

Does this make sense to anyone?

Share Improve this question edited Aug 9, 2015 at 14:52 David Mulder 27k10 gold badges56 silver badges118 bronze badges asked Jan 24, 2015 at 19:03 jhammjhamm 25k42 gold badges110 silver badges187 bronze badges 5
  • Hmm, there must be something else going on here, either in your environment or around those test blocks. Does this happen when you add any new test file, or just that specific one? – Nick Tomlin Commented Jan 25, 2015 at 0:23
  • 1 Any file I add makes the same thing happen. But if I only leave one file it will always run – jhamm Commented Jan 25, 2015 at 0:34
  • What are the file names of the tests? I wonder if it is a parking issue with jest. Also, It may seem silly, but I'd also try blowing away node_modules and running npm install again. – Nick Tomlin Commented Jan 25, 2015 at 0:42
  • The names are ChangeCalendarView-test.js and ChangeTimePeriod-test.js. I rm'ed my node_modules and pulled down everything fresh, but still had the same problems. – jhamm Commented Jan 25, 2015 at 3:01
  • I've the similar problem. – BILL Commented Aug 9, 2015 at 0:17
Add a comment  | 

3 Answers 3

Reset to default 6

If you want to specify exact multiple files to run tests on, just separate files' names with space.

I've fixed this issue by using babel-jest. Here my package.json

{
  "name": "myapp",
  "version": "0.0.0",
  "dependencies": {
    "classnames": "^2.1.3",
    "dev": "^0.1.3",
    "flux": "^2.0.3",
    "grunt": "^0.4.5",
    "gulp": "^3.9.0",
    "immutable": "^3.7.4",
    "install": "^0.1.8",
    "lodash": "^3.10.0",
    "node-simple-static-server": "^1.1.0",
    "react-bootstrap": "^0.23.7",
    "react-router": "^0.13.3",
    "react-router-bootstrap": "^0.18.0",
    "react-tools": "^0.13.0-beta.2",
    "stackup": "^1.0.1"
  },
  "devDependencies": {
    "babel-jest": "^5.3.0",
    "babelify": "^6.1.2",
    "browser-sync": "latest",
    "browserify-shim": "^3.8.0",
    "del": "~0.1.3",
    "gulp-autoprefixer": "~1.0.1",
    "gulp-bower": "0.0.6",
    "gulp-cache": "~0.2.4",
    "gulp-imagemin": "latest",
    "gulp-jshint": "~1.8.5",
    "gulp-load-plugins": "~0.7.0",
    "gulp-ruby-sass": "~0.7.1",
    "gulp-size": "~1.1.0",
    "gulp-strip-debug": "^1.0.2",
    "gulp-stylus": "~2.0.1",
    "gulp-uglify": "^1.0.2",
    "gulp-useref": "~0.4.4",
    "gulp-util": "~3.0.1",
    "gulp-webserver": "latest",
    "jest-cli": "*",
    "main-bower-files": "~2.6.2",
    "react": "latest",
    "react-tools": "latest",
    "reactify": "latest",
    "strip-debug": "^1.0.1",
    "vinyl-source-stream": "^1.0.0",
    "watchify": "~2.1"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "scriptPreprocessor": "../node_modules/babel-jest",
    "testFileExtensions": [
      "es6",
      "js"
    ],
    "moduleFileExtensions": [
      "js",
      "json",
      "es6"
    ],
    "rootDir": "./app",
    "collectCoverage": true,
    "unmockedModulePathPatterns": [
      "react",
      "events",
      "lodash"
    ]
  },
  "browserify": {
    "transform": [
      "browserify-shim",
      [
        "reactify",
        {
          "es6": true
        }
      ]
    ]
  },
  "browser": {
    "jquery": "./app/bower_components/jquery/dist/jquery.js"
  },
  "browserify-shim": {
    "jquery": "$"
  }
}

The glob patterns Jest uses to detect test files. By default it looks for .js and .jsx files inside of tests folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js. So name your test file with suffix .test .Like pagination.test.js .

发布评论

评论列表(0)

  1. 暂无评论