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

How to exclude tests from outside the src folder #4606

Closed
randytorres opened this issue Jun 13, 2018 · 6 comments
Closed

How to exclude tests from outside the src folder #4606

randytorres opened this issue Jun 13, 2018 · 6 comments

Comments

@randytorres
Copy link

I'm using react-scripts "1.1.4" and running yarn test is including a folder outside of the src directory. I thought based on this issue that was fixed #544. Is this a bug or is there a way to exclude anything outside of the src folder.

@bugzpodder
Copy link

Can you provide a full repo? It's hard to tell what's wrong without seeing any source code.

@randytorres
Copy link
Author

Its a private repo so i cant but theres no custom configuration related to jest. Heres our package.json and an image of the folder structure if that helps. Should it automatically exclude anything outside of the src folder?

{
  "name": "",
  "license": "UNLICENSED",
  "private": true,
  "version": "0.1.0",
  "homepage": "",
  "dependencies": {
    "animated": "^0.2.1",
    "apollo-boost": "^0.1.4",
    "apollo-cache-inmemory": "^1.1.12",
    "apollo-cache-persist": "^0.1.1",
    "apollo-client": "^2.2.8",
    "apollo-link": "^1.2.1",
    "apollo-link-http": "^1.5.3",
    "apollo-link-state": "^0.4.1",
    "classnames": "^2.2.5",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "final-form": "^4.4.0",
    "final-form-set-field-data": "^1.0.1",
    "graphql": "^0.13.2",
    "graphql-tag": "^2.8.0",
    "js-cookie": "^2.2.0",
    "json-2-csv": "^2.2.0",
    "link-to-inbox": "^1.2.0",
    "lodash": "^4.17.5",
    "material-ui": "^0.19.4",
    "moment": "^2.19.1",
    "numbro": "^2.0.6",
    "object-diff": "^0.0.4",
    "object-hash": "^1.2.0",
    "pre-commit": "^1.2.2",
    "prop-types": "^15.6.0",
    "query-string": "^5.0.1",
    "react": "^16.2.0",
    "react-animate-on-scroll": "^1.3.2",
    "react-apollo": "^2.1.1",
    "react-dom": "^16.0.0",
    "react-final-form": "^3.1.5",
    "react-flexbox-grid": "^1.1.5",
    "react-intl": "^2.4.0",
    "react-loadable": "^5.3.1",
    "react-recaptcha": "^2.3.5",
    "react-router-config": "^1.0.0-beta.4",
    "react-router-dom": "^4.2.0",
    "react-router-prop-types": "^0.0.2",
    "react-scripts": "^1.0.14",
    "react-stripe-elements": "^1.3.2",
    "react-test-renderer": "^16.2.0",
    "react-toastify": "^4.0.1",
    "react-transition-group": "^1.2.0",
    "recordrtc": "^5.4.6",
    "source-map-explorer": "^1.5.0",
    "uuid": "^3.2.1"
  },
  "scripts": {
    "analyze": "source-map-explorer build/static/js/main.*",
    "build-css": "node-sass-chokidar src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path=src/modules/core/styles src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start --host 0.0.0.0",
    "start": "PORT=80 npm-run-all -p watch-css start-js",
    "build": "npm run build-css && react-scripts build",
    "test": "react-scripts test --env=jsdom --verbose",
    "coverage": "react-scripts test --coverage --env=jsdom --no-cache",
    "deploy": "npm run build && gh-pages -d build",
    "lint": "eslint ./src",
    "ratchet": "jest-coverage-ratchet",
    "styleguide": "npm-run-all -p watch-css styleguidist",
    "styleguidist": "styleguidist server",
    "styleguide-build": "styleguidist build"
  },
  "devDependencies": {
    "eslint": "4.9.0",
    "eslint-config-airbnb": "16.1.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "6.0.2",
    "eslint-plugin-react": "7.4.0",
    "gh-pages": "^1.0.0",
    "ip": "^1.1.5",
    "jest-coverage-ratchet": "^0.2.3",
    "node-sass-chokidar": "0.0.3",
    "npm-run-all": "^4.0.2",
    "react-router-test-context": "^0.1.0",
    "react-styleguidist": "^7.0.17"
  },
  "jest": {
    "coverageThreshold": {
      "global": {
        "lines": 39.7,
        "statements": 29.79,
        "functions": 27.12,
        "branches": 23.75
      }
    },
    "coverageReporters": [
      "json-summary",
      "text",
      "text-summary"
    ]
  }
}

frontend

@bugzpodder
Copy link

Thanks for the extra information. What is the output of the test run and which tests were run but wasn't suppose to? I don't see any other directories in the screenshot.

@randytorres
Copy link
Author

I had to remove the tests but they were in the root directory like this

.snapguidist
 -- __snapshots__
 ---- test1.snap
 ---- test2.snap

and the output was 10 obsolete snapshot files found, press u to remove them.

@ianschmitz
Copy link
Contributor

It appears the config for jest has roots set to the root of the project.

I suspect this is to be more lenient on how users want to organize their tests (in src/..., vs in a separate tests directory in the root for example).

@Timer Timer added this to the 2.0.0 milestone Jun 14, 2018
@Timer Timer modified the milestones: 2.0.x, 2.0.0-final, 2.0.0 Sep 26, 2018
@Timer
Copy link
Contributor

Timer commented Sep 27, 2018

This should be strict on test matching in v2:

    testMatch: [
      '<rootDir>/src/**/__tests__/**/*.{js,jsx}',
      '<rootDir>/src/**/?(*.)(spec|test).{js,jsx}',
    ],

Please let us know if this still doesn't work right.

@Timer Timer closed this as completed Sep 27, 2018
@lock lock bot locked and limited conversation to collaborators Jan 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants