How about separation of the tests completely?
Something like:
- scripts
- tsconfig.json
- src
- app.ts
- dist
- app.js
- tests
- tsconfig.json
- src
- appTest.ts
- bin
- appTest.js
Then scripts/tsconfig.json
will look like:
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
...
}
And tests/tsconfig.json
will look like:
"compilerOptions": {
"outDir": "bin",
"rootDir": "src",
...
}
Edit
I checked this solution in webstorm, and there are two options:
(1) tests files importing from scripts/dist
:
scripts/tsconfig.json
:
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true
}
tests/tsconfig.json
:
"compilerOptions": {
"outDir": "bin",
"rootDir": "src"
}
tests/src/apptest.ts
:
import * as app from "../../scripts/dist/app";
...
result in tests/bin
will look like:
- tests
- bin
- apptest.js
And when you refactor in scripts
, let's say scripts/src/app.ts
then it indeed has no effect on tests/src/apptest.ts
, but compiling it will fail because of the refactor in the source.
So you'll know that you need to change the test files (though it won't be automatic).
(2) tests files importing from scripts/src
:
The scripts/tsconfig.json
file doesn't need to have the declaration
option on because we'll use the source directly.
tests/src/apptest.ts
:
import * as app from "../../scripts/dist/src";
...
Refactoring the source will change the test files as desired, but the output in tests/bin
is this:
- tests
- bin
- scripts
- src
- app.js
- tests
- src
- apptest.js
If you don't mind this structure for tests/bin
then you get what you asked for without the need to use other tools.