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

Using Jest, "no such file or directory" for .env.example #1492

Closed
faceleg opened this issue Jan 30, 2018 · 1 comment
Closed

Using Jest, "no such file or directory" for .env.example #1492

faceleg opened this issue Jan 30, 2018 · 1 comment

Comments

@faceleg
Copy link

faceleg commented Jan 30, 2018

Using Jest, "no such file or directory" for .env.example

  • .env.example file exists at <project-root>
  • jest tests run fine normally with NODE_ENV=test jest

I've tried adding rootDir in config to <project-root>, did not solve the issue.

I'm excited to get this working as I'm evaluating it for use for my team.

Wallaby config:

module.exports = function () {
  return {
    files: ['src/**/*.js', '!src/**/__tests__/*.js'],

    tests: ['src/**/__tests__/*.js'],

    env: {
      type: 'node',
      runner: 'node',
    },

    testFramework: 'jest',
  };
};

Jest config:

{
    "setupFiles": [
      "<rootDir>/webpack/jest/jest.js"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "testResultsProcessor": "./node_modules/jest-junit",
    "transform": {
      "^.+\\.(js|jsx)$": "babel-jest",
      "\\.(gql|graphql)$": "jest-transform-graphql",
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/webpack/jest/file-transform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {
      "^.+\\.css$": "identity-obj-proxy",
      "^react-native$": "react-native-web"
    }
  }

Full error:

Error: ENOENT: no such file or directory, open '.env.example'
at Object.fs.openSync (fs.js:663:18)
at Object.fs.readFileSync (fs.js:568:33)
at Object.config (<project-root>/node_modules/dotenv-safe/index.js:32:42)
at Object.<anonymous> (<project-root>/webpack/jest/jest.js:5:24)
at Runtime._execModule (<project-root>/node_modules/jest-runtime/build/index.js:513:13)
at Runtime.requireModule (<project-root>/node_modules/jest-runtime/build/index.js:329:14)
at new Runtime (<project-root>/node_modules/jest-runtime/build/index.js:170:14)
at runTest (<project-root>/node_modules/jest-cli/build/runTest.js:78:19)
at promise.then (<project-root>/node_modules/jest-cli/build/TestRunner.js:197:14)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)

Code editor or IDE name and version

IntelliJ IDEA v2017.3.3

OS name and version

OSX 10.13.2 (17C88)

@faceleg faceleg closed this as completed Jan 30, 2018
@faceleg
Copy link
Author

faceleg commented Jan 30, 2018

We use setupFiles, the error was thrown from code in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant