Skip to content

Mocha fails to reload watched files #4016

@geigerzaehler

Description

@geigerzaehler

Under certain circumstances Mocha fails to reload source files in watch mode. Specifically, if a file is watched and modified but only required by a file that is not watched then the modified file is not reloaded and the change is not visible to the test suite.

This issue can be addressed by adding the unwatched files to --watch-files

Steps to Reproduce

Create the following three files

// lib-a/index.js
module.exports = true
// lib-b/index.js
module.exports = require('../lib-a')
// test/main.js
const assert = require('assert')
const value = require('../lib-b')
it('works', function () {
  assert(value)
})

Now run

mocha --watch --watch-files lib-a,test

The test suite passes.

Now modify lib-a/index.js so that the exported value is false. This will retrigger the tests but they will still succeed.

If lib-b is add to the --watch-files list then the modification results in a test failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificstatus: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions