-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathtimeout.test.ts
32 lines (27 loc) · 1.13 KB
/
timeout.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import fs from 'fs/promises'
import path from 'path'
import spawn from 'spawn-please'
import ncu from '../src/'
import chaiSetup from './helpers/chaiSetup'
import stubVersions from './helpers/stubVersions'
chaiSetup()
const bin = path.join(__dirname, '../build/cli.js')
describe('timeout', function () {
it('throw an exception instead of printing to the console when timeout is exceeded', async () => {
const pkgPath = path.join(__dirname, './test-data/ncu/package-large.json')
return ncu({
packageData: await fs.readFile(pkgPath, 'utf-8'),
timeout: 1,
}).should.eventually.be.rejectedWith('Exceeded global timeout of 1ms')
})
it('exit with error when timeout is exceeded', async () => {
return spawn('node', [bin, '--timeout', '1'], {
stdin: '{ "dependencies": { "express": "1" } }',
}).should.eventually.be.rejectedWith('Exceeded global timeout of 1ms')
})
it('completes successfully with timeout', async () => {
const stub = stubVersions('99.9.9', { spawn: true })
await spawn('node', [bin, '--timeout', '100000'], { stdin: '{ "dependencies": { "express": "1" } }' })
stub.restore()
})
})