Preact-cli: npm test doesn't work on newly created project

Created on 17 Apr 2018  路  12Comments  路  Source: preactjs/preact-cli

Do you want to request a feature or report a bug?
This is a Bug request.

What is the current behaviour?
Running npm test on a newly created project with preact create default myApp results in

$ npm run test

> [email protected] test C:\Projects\myApp
> jest ./tests

No tests found
In C:\Projects\myApp
  8 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
  testPathIgnorePatterns: \\node_modules\\ - 8 matches
Pattern: ./tests - 0 matches

If the current behaviour is a bug, please provide the steps to reproduce.

  • preact create default myApp
  • cd myApp
  • npm test

What is the expected behaviour?
The expected behaviour is, that tests should run without failure.

Please mention other relevant information.

  • Node v.8.9.4
  • NPM v.5.6.0
  • OS: Windows 10
  • CLI v.2.2.1
Good first bug bug help wanted

All 12 comments

no reactions? 馃槃 this is actually something, that should work out of the box

The output clearly says that there are no tests. This is not a bug.

There are tests automatically generated by the CLI under src/tests. The npm command should look inside there but it doesn't. Changing the path of the command doesn't work either.

It looks like a bug in Jest on Windows. The same command working fine on Mac/Linux.

Facing the same problem, (on windows)
I got this workaround:

  1. Rename tests to __tests__
  2. Change setupFiles path to match
  3. Use jest directly from script.

so what I did was the following

  • deleted __mocks__ since I don't need it
  • changed the test script to just only jest, so my test script looks like
"scripts": {
    "test": "jest"
  },

Still a pity that npm test doesn't work out of the box with Preact CLI. Fix is needed here for sure.

Running jest tests works instead of jest ./tests from the cli. @prateekbh would you consider a PR for this.

Seems like the tests directory was supposed to end up at the repo root, but the default template has it in src/tests. Personally I'd prefer it at the repo root. In that setup, we'll have to add this to the package.json "jest" field:

"jest": {
  "testRegex": "(/(__tests__|tests)/.*|(\\.|/)(test|spec))\\.jsx?$"
}

Might be worth moving this issue over to the default template's repo.

I can fix this once I reach home or let's just leave it to the world

This has been always a problem in my projects, always had to fix manually. The other open PR had conflicts and was out of date. So decided to submit a PR.

Check out- https://github.com/preactjs-templates/default/pull/20

Before the PR is merged, you can use the branch in my fork as a source where this is fixed.
preact create amitsarangi/default#bug/preact-cli-issue-555-tests-do-not-work-on-windows <my-project-name>

i tried to reproduce it locally and seems it is fixed @amitsarangi :

  • $ preact create default testy
  • $ cd testy
  • $ npm test

ran it on VirutalBox with Windows 7, macOS 10.13.6 and Ubuntu 14.04

@oieduardorabelo Yeah the PR is merged, and this issue can be closed now.

Was this page helpful?
0 / 5 - 0 ratings