Skip to content

Commit 4218f07

Browse files
committed
test: error on timeout
1 parent 8ec5c25 commit 4218f07

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/index.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ it('should handles module not exist', async () => {
3636
})
3737

3838
it('should throw error on timeout', async () => {
39+
jest.useRealTimers()
3940
const VM = (await import('../src')).default
4041

41-
const vm = VM({ timeout: 10 })
42+
const vm = VM({ timeout: 20 })
4243

4344
await vm.require([
4445
{
4546
path: 'timeout.js',
46-
src: 'module.exports = () => new Promise((resolve) => setTimeout(resolve, 30))',
47+
src: 'module.exports = () => new Promise((resolve) => {})',
4748
},
4849
])
4950

5051
expect(vm.exec('timeout.js')).rejects.toThrow()
52+
// eslint-disable-next-line no-promise-executor-return
53+
await new Promise((resolve) => setTimeout(resolve, 30))
5154

5255
vm.terminate()
5356
})

0 commit comments

Comments
 (0)