在jest中单独运行lint和测试

时间:2018-05-07 21:56:07

标签: javascript testing jestjs lint

我们正在使用jest-runner-eslint运行我们的eslint配置,然后还使用jest进行常规测试。根据{{​​3}},我们进行了常规测试,并且我们的lint测试在我们的配置的“项目字段”中设置为两个单独的项目。

不幸的是,我没有看到如何单独运行lint测试和“真实”测试。运行带有suggestion in the docs错误的jest,因为它假设我们的项目是monorepo,我们正在尝试在monorepo文件夹中运行测试。

一个例子:

$ yarn test --projects lint
yarn run v1.6.0
$ node scripts/test.js --env=jsdom --projects lint
Error: Can't find a root directory while resolving a config file path.
Provided path to resolve: lint

请注意,我们可以一起运行我们的测试,但这两个套件不能单独运行。

我们的jest配置(松散地基于create-react-app)

{
    "projects": [
      {
        "displayName": "test",
        "collectCoverage": true,
        "coverageDirectory": "<rootDir>/coverage",
        "collectCoverageFrom": [
          "src/**/*.{js,jsx,mjs}"
        ],
        "coverageReporters": [
          "text-summary",
          "lcov",
          "json"
        ],
        "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
        "setupFiles": [
          "<rootDir>/config/polyfills.js",
          "<rootDir>/src/setupTest.js"
        ],
        "snapshotSerializers": [
          "enzyme-to-json/serializer"
        ],
        "testMatch": [
          "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
          "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
        ],
        "testEnvironment": "node",
        "testURL": "http://localhost",
        "transform": {
          "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
          "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
          "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
        },
        "transformIgnorePatterns": [
          "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
        ],
        "moduleNameMapper": {
          "^react-native$": "react-native-web"
        },
        "moduleFileExtensions": [
          "web.js",
          "mjs",
          "js",
          "json",
          "web.jsx",
          "jsx",
          "node"
        ]
      },
      {
        "runner": "jest-runner-eslint",
        "displayName": "lint",
        "testMatch": [
          "<rootDir>/src/**/*.js"
        ]
      }
    ]
}

各种版本:

  • OS:macOS Sierra 10.12(虽然我也在Ubuntu 16上看过这个)
  • 节点:v8.11.1
  • Jest:22.4.3
  • jest-runner-eslint:0.5.0

0 个答案:

没有答案