Skip to content

Commit

Permalink
generalized test exclusion from build
Browse files Browse the repository at this point in the history
  • Loading branch information
karmaniverous committed Dec 18, 2022
1 parent 0cb464b commit cea889a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ assertion syntax.

The default configuration will recognize any file as a test file that...

- has a `.test.*js*` extension (i.e. `.test.cjs`, `.test.js`, `.test.mjs`, or
`.test.ts`).
- is not located in `node_modules`.
- has `.test.` just before its file name extension (i.e. `example.test.js`).
- is not located in the `node_modules` or `lib` directories.

The sample code packages tests next to the source code they exercise. If you
prefer to segregate your tests into a directory outside [`src`](./src/) (e.g.
`test`), that will work as well.

Either way, all test files will be excluded from the build.
Either way, all test files meeting the above conditions will be excluded from
the build.

To enable `mocha`-specific linting in your test files, add the following
directive at the top of every test file:
Expand Down
6 changes: 6 additions & 0 deletions build.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('./babel.config');

module.exports = (api) => ({
...config(api),
ignore: [/\.test\.\w+$/],
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"require": [
"@babel/register"
],
"spec": "**/*.test.*js*"
"spec": "**/*.test.!(*.*)"
},
"release-it": {
"github": {
Expand All @@ -71,7 +71,7 @@
}
},
"scripts": {
"build": "rimraf ./lib && babel src -d lib --ignore **/*.test.cjs,**/*.test.js,**/*.test.mjs,**/*.test.ts",
"build": "rimraf ./lib && babel src -d lib --config-file ./build.config.js",
"release": "dotenv -c -- release-it",
"test": "mocha"
}
Expand Down

0 comments on commit cea889a

Please sign in to comment.