Cannot find module with **/*.test.js

1.1k views Asked by At

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": []
}
1

There are 1 answers

0
J. Hesters On BEST ANSWER

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

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