-3

I'm trying to set up testing for my Next.js project. I want to test it with RITEway which is based on tape. I want a test command that finds all files in my src/ folder that end with .test.js.

Here is the commend I came up with:

"test": "NODE_ENV=test node -r @babel/register src/**/*.test.js",

I get the error:

Error: Cannot find module '/path/to/project/src/**/*.test.js'

How can I tell node to find all files ending in .test.js in my src/ folder?

Extra context:

My testing files live in src/features/<feature>/<feature.test.js>, e.g.:

"test": "NODE_ENV=test node -r @babel/register src/features/home/home-page-component.test.js",

Works to find a single file and run it.

"test": "NODE_ENV=test node -r @babel/register src/**/**/*.test.js",

Works to find all folders in features, but ignores files like src/<file>.test.js, which I also want to run.

I had to install @babel/register and @babel/core for Node to process absolute imports and newer syntax.

My .babelrc is:

{
  "env": {
    "test": {
      "plugins": [
        [
          "module-resolver",
          {
            "root": [
              "."
            ],
            "alias": {
              "features": "./src/features"
            }
          }
        ]
      ]
    }
  },
  "presets": [
    [
      "next/babel"
    ]
  ],
  "plugins": []
}
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
  • The `node` command only takes one script to run, and doesn't accept a regex (or glob, as that pattern actually is is). Per [the docs](https://www.npmjs.com/package/riteway#troubleshooting) you want to use the riteway cli. – jonrsharpe Sep 20 '20 at 11:56
  • @jonrsharpe Thanks, I tried that. Running `"test": "NODE_ENV=test riteway -r @babel/register src/**/*.test.js",` (is that what you mean?) finds files on lower levels `src/.test.js` but then doesn't run the deeper nested files like `src/features/home/home-page-component.test.js`, but I want to run all `.test.js` files. – J. Hesters Sep 20 '20 at 12:01
  • Note that the docs suggest you should *quote* the glob - you want to pass it to `riteway`, rather than letting your shell expand it. – jonrsharpe Sep 20 '20 at 12:02
  • @jonrsharpe That works! Thank you very much! Do you want to post it as an answer so I can accept it? – J. Hesters Sep 20 '20 at 12:04

1 Answers1

0

As Jon Sharpe said, you have to feed the regex into riteway.

"test": "NODE_ENV=test riteway -r @babel/register 'src/**/*.test.js'",
J. Hesters
  • 13,117
  • 31
  • 133
  • 249