rrdelaney / reason-scripts

:beginner: Create a ReasonML and React development environment
MIT License
628 stars 58 forks source link

Default Tests Not Found #74

Closed AdamBrodzinski closed 6 years ago

AdamBrodzinski commented 6 years ago

Hello,

I'm using the latest 1.0.0-beta4 and when I do a yarn test the test that's included does not run. I'm pretty sure at some point in the past it did run however. I'm more than happy to setup a repro and give more info but I wasn't sure if this was a known problem.

However, i've figured out how to narrow it down and make those tests pass.

Option 1 First I have to remove the .bs.js to get it to see the js file then change the _test to .test... eg change app_test.bs.js to app.test.js then jest picks up the file and shows me the pass/fail as expected. This isn't useable of course but at least shines some light onto a file pattern matching issue.

Option 2 Put the tests in a __tests__ directory and turn on subdirs in the bsconfig.

OSX 10.12.4 bs-platform - 4.0.3 1.0.0-beta-4

Thanks for all you're hard work! ๐Ÿบ ๐ŸŽ‰

rrdelaney commented 6 years ago

Hi there ๐Ÿ˜ tests are broken right now for Reason-scripts, and we donโ€™t have a good plan to fix it.

The problem is that compiling to ES6 modules entirely breaks Jest, because BuckleScript also compiles node_modules to ES6 modules. Jest doesnโ€™t process these, so everything ends up broken. Itโ€™s a choice of either ES6 modules at the moment, or tests ๐Ÿ˜•

AdamBrodzinski commented 6 years ago

Ah ok good to know, and thanks for the super fast response!

So I have my bsconfig set to commonjs, is it expected to break in both cases of es6 or commonjs? Everything works as long as I do either of the 2 work around options above with commonjs (fresh install with react boilerplate + subdirs config).

{
  "name": "reason-scripts",
  "sources": [{ "dir": "src", "subdirs": true }],
  "bs-dependencies": ["reason-react", "@glennsl/bs-jest", "bs-fetch"],
  "reason": {
    "react-jsx": 2
  },
  "refmt": 3,
  "package-specs": {
    "module": "commonjs",
    "in-source": true
  },
  "suffix": ".bs.js"
}

and package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "reason-scripts": "1.0.0-beta4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "@glennsl/bs-jest": "^0.4.3",
    "bs-fetch": "^0.3.0",
    "bs-platform": "^4.0.3",
    "reason-react": "^0.5.3"
  }
}
RawToast commented 6 years ago

I've had issues with reason-scripts for tests and coverage for some time and ended up calling jest instead for simple testing.

"test": "jest --env=jsdom --testMatch='**/test/*test.{js, re}' --watch"

Also stuck on 0.8.0 since I can't get code coverage to work with later versions ๐Ÿ˜ฟ

@rrdelaney Bit of an issue high-jack, I noticed reason-scripts development slowed down and is now part of reasonml-old, I presume users should be looking to migrate away from these scripts? Are there plans for a successor project? Or should I stop being lazy and learn how to configure my projects? ๐Ÿ˜†

rrdelaney commented 6 years ago

@RawToast Best way to run a Reason project in my experience is to use bsb -init && yarn add --dev parcel. There's no hacks like bs-loader had and is a much more stable setup.