Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

npm test fails #10

Closed
johngriffin opened this issue Feb 28, 2018 · 11 comments
Closed

npm test fails #10

johngriffin opened this issue Feb 28, 2018 · 11 comments
Labels

Comments

@johngriffin
Copy link

johngriffin commented Feb 28, 2018

Hi, great library! Unfortunately npm test is failing for me, running on Mac OS X High Sierra.

I've tried removing node_modules and doing an npm install. No dice. Looks like the path is wrong in package.json.

FAIL  src/App.test.js
  ● Test suite failed to run

    ENOENT: no such file or directory, stat '/Users/john/dev/drizzle/\config\polyfills.js'
        at Error (native)
      
      at Object.fs.statSync (fs.js:981:18)
      at Object.statSync (node_modules/graceful-fs/polyfills.js:297:22)

Test Suites: 1 failed, 1 total
@drjiro
Copy link

drjiro commented Mar 1, 2018

HI, I also try it on Mac. If you try it on not Windows, It may occur for Win32 file system, so that change from "\" to "/". Modify the following lines in 'package.json'.

line 76
"/config/polyfills.js"

line 85-86
"^.+\.css$": "/config/jest/cssTransform.js",
"^(?!.*\.(js|jsx|css|json)$)": "/config/jest/fileTransform.js"

I will pass the test. However, I cannot run it on Chrome by another problem.

@pemulis
Copy link
Contributor

pemulis commented Mar 1, 2018

I have the same error as @johngriffin, and got past it by changing just line 76 of package.json:

"<rootDir>/config/polyfills.js"

But now I have a new error:

FAIL  src/App.test.js
● Test suite failed to run

Your test suite must contain at least one test.
  
  at onResult (node_modules/jest/node_modules/jest-cli/build/TestRunner.js:189:18)
      at <anonymous>
  at process._tickCallback (internal/process/next_tick.js:160:7)

Working on debugging that!

@pemulis
Copy link
Contributor

pemulis commented Mar 1, 2018

Part of the problem might be that I still had my local test server running while trying to reinstall my node modules. (I had run npm run start in a different Terminal tab.) So I rebooted that, deleted my node_modules/ directory, and reinstalled.

Getting this error now, which leads me to believe I need to change more lines in package.json, as @drjiro suggested:

   FAIL  src/App.test.js
    ● Test suite failed to run

Cannot find module '/Users/j/Coding/cryptokittybox/\config\jest\cssTransform.js'
  
  at Function.Module._resolveFilename (module.js:555:15)
  at Function.Module._load (module.js:482:25)
  at Module.require (module.js:604:17)
  at require (internal/module.js:11:18)

  Test Suites: 1 failed, 1 total
  Tests:       0 total
  Snapshots:   0 total
  Time:        1.673s
  Ran all test suites.

@pemulis
Copy link
Contributor

pemulis commented Mar 1, 2018

Here's what I changed in package.json to get the test to pass:

Line 76
"<rootDir>/config/polyfills.js"

Lines 85-86
"^.+/.css$": "<rootDir>/config/jest/cssTransform.js",

"^(?!.*/.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"

I was still getting a "Cannot find module" error until I added to those lines.

@am17torres
Copy link

am17torres commented Mar 26, 2018

I'm on OS X Sierra using Visual Studio Code 1.21.1

@pemulis, are you sure your snippet is correct?
Shouldn't "^.+/.css$" actually be "^.+\\.css$"
And the same for "^(?!.*/.(js|jsx|css|json)$)": -> "^(?!.*\\.(js|jsx|css|json)$)":

Doing that got rid of the error Your test suite must contain at least one test. In src/App.test.js and scripts/test.js.

Update 1:

  • Bumped jest and babel-jest to 22.4.1 because the VS Code jest extension was complaining.

screen shot 2018-03-26 at 12 25 09 am

Now I'm getting SyntaxError: Identifier 'jest' has already been declared. Not sure if that is the result of bumping the version which is probably unrelated to this issue. Jest@18 is running the test.js as a test per the comment here

Had to include scripts in the testPathIgnorePatterns block.

"testPathIgnorePatterns": [
    "<rootDir>/(build|docs|node_modules|scripts)"
],

Update 2:

The latest VS Code error is [Jest] ReferenceError: document is not defined despite the package.json script test including --env=jsdom. Again unrelated to this project itself since the test technically passes, but I'll capture any findings for those using the same editor.

FIx: replace testEnvironment from node to jsdom

Complete package.json

{
  "name": "drizzle-box",
  "version": "1.0.0",
  "devDependencies": {
    "autoprefixer": "6.5.1",
    "babel-core": "6.17.0",
    "babel-eslint": "7.1.1",
    "babel-jest": "22.4.1",
    "babel-loader": "6.2.7",
    "babel-preset-react-app": "^2.0.1",
    "case-sensitive-paths-webpack-plugin": "1.1.4",
    "chalk": "1.1.3",
    "connect-history-api-fallback": "1.3.0",
    "cross-spawn": "4.0.2",
    "css-loader": "0.26.0",
    "detect-port": "1.0.1",
    "dotenv": "2.0.0",
    "drizzle": "^1.0.1",
    "drizzle-react": "^1.0.1",
    "drizzle-react-components": "^1.0.1",
    "eslint": "3.8.1",
    "eslint-config-react-app": "^0.5.0",
    "eslint-loader": "1.6.0",
    "eslint-plugin-flowtype": "2.21.0",
    "eslint-plugin-import": "2.0.1",
    "eslint-plugin-jsx-a11y": "2.2.3",
    "eslint-plugin-react": "6.4.1",
    "extract-text-webpack-plugin": "1.0.1",
    "file-loader": "0.9.0",
    "filesize": "3.3.0",
    "fs-extra": "0.30.0",
    "gzip-size": "3.0.0",
    "html-webpack-plugin": "2.24.0",
    "http-proxy-middleware": "0.17.2",
    "jest": "22.4.1",
    "json-loader": "0.5.4",
    "object-assign": "4.1.0",
    "path-exists": "2.1.0",
    "postcss-loader": "1.0.0",
    "promise": "7.1.1",
    "react-dev-utils": "^0.4.2",
    "recursive-readdir": "2.1.0",
    "strip-ansi": "3.0.1",
    "style-loader": "0.13.1",
    "truffle-contract": "^1.1.8",
    "truffle-hdwallet-provider": "0.0.3",
    "url-loader": "0.5.7",
    "webpack": "1.14.0",
    "webpack-dev-server": "1.16.2",
    "webpack-manifest-plugin": "1.1.0",
    "whatwg-fetch": "1.0.0",
    "zeppelin-solidity": "^1.6.0"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.2",
    "react-router-redux": "^4.0.7",
    "redux": "^3.6.0",
    "redux-auth-wrapper": "^1.0.0",
    "redux-saga": "^0.15.3",
    "redux-thunk": "^2.2.0"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom",
    "chain": "geth --datadir=\"/tmp/eth/60/01\" --nodiscover --maxpeers 0 --port 30301 --rpc --rpcapi \"db,eth,net,web3\" --rpcport 8101 --verbosity 6 console"
  },
  "jest": {
    "collectCoverageFrom": [
      "<rootDir>/src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>/(build|docs|node_modules|scripts)"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "node_modules/.+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    }
  },
  "babel": {
    "presets": [
      "react-app"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  }
}

@stale
Copy link

stale bot commented Jan 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 16, 2019
@JakeGlascock
Copy link

Had a clean unbox of drizzle. I get 'ReferenceError: [BABEL] /apps/drizzle01202019/app/src/App.test.js: Unknown option: base.configFile. Check out http://babeljs.io/docs/usage/options/ for more information about options.' at the
npm run test
step.

Using nvm to use v11.7.0 of node, npm v6.5.0.

After much research (doge style), I found a solution.

truffle unbox must use npm and not yarn as facebook/create-react-app#5259 was the error I was getting. This solution suggested using yarn as

as it's reportedly correctly hoisting packages

So after unboxing, I deleted the app/node_modules directory and re-installed from the app directory with

yarn install

Yarn v1.13.0

After that, the out of the box test that comes with the drizzle box passed using

yarn run test

@stale stale bot removed the wontfix label Jan 20, 2019
@adrianmcli
Copy link
Contributor

@JakeGlascock thanks for commenting and letting us know the workaround. But unfortunately, we can't expect our users to have Yarn installed. It's likely that this will remain broken until NPM or Babel fixes things.

@JakeGlascock
Copy link

@adrianmcli Fair enough. Just wanted to make sure I helped out as I am excited about the Truffle/Drizzle combo and looking forward to all the great things it will be used to do.

@stale
Copy link

stale bot commented Mar 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 26, 2019
@stale
Copy link

stale bot commented Apr 2, 2019

This issue has been closed, but can be re-opened if further comments indicate that the problem persists. Feel free to tag maintainers if there is no reply to further comments.

@stale stale bot closed this as completed Apr 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants