Skip to content

Stale test files in out/ keep running after they are deleted or renamed #30

Description

@Chirag6722

npm run compile is plain tsc -p ./ with no clean step, and out/ is never emptied. tsc writes new output over old but does not remove .js for sources that no longer exist. The mocha loader then globs whatever is there:

const files = fs.readdirSync(testsRoot).filter((f) => f.endsWith('.test.js'));

So a test file that has been deleted, renamed, or that simply belongs to a different branch keeps getting executed from out/ indefinitely.

This is not theoretical, it bit me while working on #1. Switching between branches left out/test/suite/ holding compiled tests from branches that were not checked out, and the run failed with no mocha output at all and the host exiting after about four seconds, which looks nothing like a test failure and sends you hunting through your own change for a startup crash that is not there. rm -rf out && npm run compile fixed it.

The quieter half is worse than the loud half: when a stale file happens to still pass, the suite reports a pass count that includes tests that are not in the tree you are looking at. I quoted such a number in an earlier PR before I noticed.

A clean step on pretest would settle it, something like:

"clean": "node -e \"require('fs').rmSync('out',{recursive:true,force:true})\"",
"pretest": "npm run clean && npm run compile"

Worth keeping it off compile itself so npm run watch and the F5 debug loop stay fast, and only paying the full rebuild where correctness of the file set actually matters.

Happy to send this one if you want it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions