1

I can build and the code works and correctly excludes the tests using and can run the code with node:

babel src -s -d dist --extensions ".js,.ts,.tsx" --ignore '**/*.test.js' --ignore '**/test/*'

But trying to use babel-node seems to include the tests regardless:

babel-node --extensions '.js,.ts,.tsx' --ignore='src/**/*.test.js' src/index.js

Depending on the ignore pattern I can get different errors but errors inside a test file. eg. src/entity/authentication/authentication.test.js which babel should be ignoring.

I've tried a number of patters:

  • **/*.test.js
  • src/**/*.js
  • /src/**/*.js

I'm sure it something simple that I'm missing.

My babel config if its helpful:

{
"presets": [
  "@babel/preset-env",
  ["@babel/preset-typescript", {
    "isTSX": true,
    "allExtensions": true
  }]
],
"plugins": [
  "babel-plugin-transform-typescript-metadata",
  ["@babel/plugin-proposal-decorators", {"legacy": true}],
  "@babel/plugin-proposal-class-properties",
  "@babel/plugin-transform-runtime"
]

}

pogson
  • 11
  • 1
  • Hi pogson this can help you https://stackoverflow.com/a/35415624/901308 as extension ,no = need. It's important you describe which version of node and babel-node you are using. – heat Mar 01 '20 at 23:56
  • According to `babel-node --version` I'm using 7.8.4. I've tried with and without the equals. It's strange. Seems to do something but I'm not sure what. I get different errors depending on the ignore command. The error occurs in the same test file. ```babel-node --extensions '.js,.ts,.tsx' --ignore 'src/**/*.test.js' src/index.js SyntaxError: Cannot use import statement outside a module``` ```babel-node --extensions '.js,.ts,.tsx' --ignore '/src/**/*.test.js' src/index.js ReferenceError: describe is not defined``` – pogson Mar 02 '20 at 03:49

1 Answers1

0

‍♂️Turns out it was not a babel issue at all it was a typeorm issue. https://github.com/typeorm/typeorm/issues/1654

"entities": [
  "src/entity/**/!(*.test)*.js"
]

Note to self: Always leave a project in working condition prior to taking a long break from it. :( Much time was wasted.

pogson
  • 11
  • 1