Skip to content

Commit 6000c93

Browse files
committed
clearRequireCache
1 parent 6989e6a commit 6000c93

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

test/constants.test.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test('constants with MOUNT starting with c:', async function (t) {
9191
}
9292
})
9393

94-
test('constants with MOUNT starting with file:', { skip: isWindows }, async function (t) {
94+
test('constants with MOUNT starting with file:', async function (t) {
9595
t.plan(1)
9696

9797
const rig = () => {
@@ -113,11 +113,15 @@ test('constants with MOUNT starting with file:', { skip: isWindows }, async func
113113
const { teardown } = rig()
114114
t.teardown(teardown)
115115

116+
if (isWindows) {
117+
t.exception(() => require('../constants'))
118+
return
119+
}
116120
const constants = require('../constants')
117121
t.ok(constants.MOUNT === 'file:///custom/mount')
118122
})
119123

120-
test('constants with MOUNT starting with ./', { skip: isWindows }, async function (t) {
124+
test('constants with MOUNT starting with ./', async function (t) {
121125
t.plan(1)
122126

123127
const rig = () => {
@@ -139,11 +143,15 @@ test('constants with MOUNT starting with ./', { skip: isWindows }, async functio
139143
const { teardown } = rig()
140144
t.teardown(teardown)
141145

146+
if (isWindows) {
147+
t.exception(() => require('../constants'))
148+
return
149+
}
142150
const constants = require('../constants')
143151
t.ok(constants.MOUNT === 'file:///custom/mount')
144152
})
145153

146-
test('constants with MOUNT starting with ../', { skip: isWindows }, async function (t) {
154+
test('constants with MOUNT starting with ../', async function (t) {
147155
t.plan(1)
148156

149157
const rig = () => {
@@ -165,11 +173,15 @@ test('constants with MOUNT starting with ../', { skip: isWindows }, async functi
165173
const { teardown } = rig()
166174
t.teardown(teardown)
167175

176+
if (isWindows) {
177+
t.exception(() => require('../constants'))
178+
return
179+
}
168180
const constants = require('../constants')
169181
t.ok(constants.MOUNT === 'file:///custom/mount')
170182
})
171183

172-
test('constants with MOUNT starting with /', { skip: isWindows }, async function (t) {
184+
test('constants with MOUNT starting with /', async function (t) {
173185
t.plan(1)
174186

175187
const rig = () => {
@@ -191,6 +203,11 @@ test('constants with MOUNT starting with /', { skip: isWindows }, async function
191203
const { teardown } = rig()
192204
t.teardown(teardown)
193205

206+
if (isWindows) {
207+
t.exception(() => require('../constants'))
208+
return
209+
}
210+
194211
const constants = require('../constants')
195212
t.ok(constants.MOUNT === 'file:///custom/mount')
196213
})

test/helper.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ global.Pear = null
44
const { isWindows } = require('which-runtime')
55
const IPC = require('pear-ipc')
66
const fs = require('bare-fs')
7+
const { pathToFileURL } = require('url-file-url')
78

89
const dirname = __dirname
910
const socketPath = isWindows ? '\\\\.\\pipe\\pear-api-test-ipc' : 'test.sock'
@@ -15,7 +16,8 @@ class Helper {
1516
static rig ({
1617
ipc = { ref: noop, unref: noop },
1718
state = {},
18-
runtimeArgv
19+
runtimeArgv,
20+
clearRequireCache
1921
} = {}) {
2022
if (global.Pear !== null) throw Error(`Prior Pear global not cleaned up: ${global.Pear}`)
2123

@@ -39,6 +41,9 @@ class Helper {
3941
global.Pear = new TestAPI(ipc, state, { worker })
4042

4143
return () => {
44+
if (clearRequireCache) {
45+
delete require.cache[pathToFileURL(require.resolve(clearRequireCache))]
46+
}
4247
global.Pear = null
4348
}
4449
}

test/teardown.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('teardown default', { skip: isWindows }, async function (t) {
1313

1414
const dir = path.join(dirname, 'fixtures', 'teardown-default')
1515

16-
const teardown = Helper.rig({ runtimeArgv: [dir] })
16+
const teardown = Helper.rig({ runtimeArgv: [dir], clearRequireCache: '../teardown' })
1717
t.teardown(teardown)
1818

1919
const pipe = Pear.run(dir)
@@ -27,7 +27,7 @@ test('teardown with position', { skip: isWindows }, async function (t) {
2727

2828
const dir = path.join(dirname, 'fixtures', 'teardown-with-position')
2929

30-
const teardown = Helper.rig({ runtimeArgv: [dir] })
30+
const teardown = Helper.rig({ runtimeArgv: [dir], clearRequireCache: '../teardown' })
3131
t.teardown(teardown)
3232

3333
const pipe = Pear.run(dir)

0 commit comments

Comments
 (0)