0

Problem

npm run test runs non-existend tests.
A.k.a: npm run test, npm run compile, npm run rebuild does not remove old no-more-existing test files.

Background

I'm developing an extension for VSCode (in typescript). I set up a couple of automated tests in various files. Later during the process I removed some of the test files. However, npm run test does not seem to be aware of the fact, that tests are deleted - i.e. it still runs them. After removing the test files files, npm run test will still run the tests contained in these files (probably because their javascript-equivalents are still somewhere in the compiled files area)

Concrete Example Workflow

These are example test files:

  • test1.test.ts, contains test1
  • test2.test.ts, contains test2
  • test3.test.ts, contains test3

They will (probably) compile to something like

  • test1.test.js
  • test2.test.js
  • test3.test.js

I run npm run test and test1, test2, test3 get executed.

I remove test1.test.ts and test2.test.ts

I run npm run compile and npm run rebuild

I run npm run test and test1, test2, test3 get executed, even though test2 and test3 should be deleted

Question

How can I make npm to remove files, that should not exist anymore?

ksav
  • 20,015
  • 6
  • 46
  • 66
DarkTrick
  • 2,447
  • 1
  • 21
  • 39

1 Answers1

0

I had the same problem and did the following steps:

Update your tsconfig.json and add the following line (if you use the standard build, which means the compiled js files are in the "out" directory)

"outDir": "out"

Replace the following script definition in your package.json

"compile-tests": "tsc -p . --outDir out"

with

"compile-tests": "tsc -b --clean && tsc -b"

Note that this will only clean the compiled files the typescript compiler knows about. Orphaned js files (without the .ts original) seem to still stick around. In this case you have to fall back to rm -rf (see also here How to delete compiled JS files from previous typescript(.ts) files?)

Update: I ended up using also rimraf (see the linked answer), which has a much cleaner result.

Xogaz
  • 113
  • 1
  • 9