Skip to content

Commit

Permalink
Clear module test path from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Nov 8, 2019
1 parent 35d8a0c commit 234f2e7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,39 +335,39 @@ describe('ts-node', function () {
}
})

const moduleTestPath = require.resolve('../tests/module')

afterEach(() => {
// Re-enable project after every test.
registered.enabled(true)
})

it('should be able to require typescript', function () {
const m = require('../tests/module')
const m = require(moduleTestPath)

expect(m.example('foo')).to.equal('FOO')
})

it('should support dynamically disabling', function () {
const path = require.resolve('../tests/module')

delete require.cache[path]
delete require.cache[moduleTestPath]

expect(registered.enabled(false)).to.equal(false)
expect(() => require(path)).to.throw(/Unexpected token/)
expect(() => require(moduleTestPath)).to.throw(/Unexpected token/)

delete require.cache[path]
delete require.cache[moduleTestPath]

expect(registered.enabled()).to.equal(false)
expect(() => require(path)).to.throw(/Unexpected token/)
expect(() => require(moduleTestPath)).to.throw(/Unexpected token/)

delete require.cache[path]
delete require.cache[moduleTestPath]

expect(registered.enabled(true)).to.equal(true)
expect(() => require(path)).to.not.throw()
expect(() => require(moduleTestPath)).to.not.throw()

delete require.cache[path]
delete require.cache[moduleTestPath]

expect(registered.enabled()).to.equal(true)
expect(() => require(path)).to.not.throw()
expect(() => require(moduleTestPath)).to.not.throw()
})

it('should support compiler scopes', function () {
Expand Down Expand Up @@ -401,7 +401,9 @@ describe('ts-node', function () {
join(TEST_DIR, 'scope/b/index.ts')
])

expect(() => require('../tests/module')).to.throw()
delete require.cache[moduleTestPath]

expect(() => require(moduleTestPath)).to.throw()
})

it('should compile through js and ts', function () {
Expand Down

0 comments on commit 234f2e7

Please sign in to comment.