-
Notifications
You must be signed in to change notification settings - Fork 21
/
package.test.ts
39 lines (36 loc) · 1.41 KB
/
package.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
33
34
35
36
37
38
39
import { expect, test } from '@oclif/test'
import { validatePkg } from './package'
import * as fs from 'fs-extra'
import { request } from '@zendesk/zcli-core'
describe('package', () => {
describe('validatePkg', () => {
test
.stub(fs, 'pathExistsSync', () => true)
.stub(fs, 'readFile', () => Promise.resolve('file content'))
.stub(request, 'requestAPI', () => Promise.resolve({ status: 200 }))
.it('should return true if package is valid', async () => {
expect(await validatePkg('./app-path')).to.equal(true)
})
test
.stub(fs, 'pathExistsSync', () => true)
.stub(fs, 'readFile', () => Promise.resolve('file content'))
.stub(request, 'requestAPI', () => Promise.resolve({ status: 400, data: { description: 'invalid location' } }))
.it('should throw if package has validation errors', async () => {
try {
await validatePkg('./app-path')
} catch (error: any) {
expect(error.message).to.equal('invalid location')
}
})
test
.stub(fs, 'pathExistsSync', () => false)
.stub(fs, 'readFile', () => Promise.reject(new Error('Package not found at ./bad-path')))
.it('should throw if app path is invalid', async () => {
try {
await validatePkg('./bad-path')
} catch (error: any) {
expect(error.message).to.equal('Package not found at ./bad-path')
}
})
})
})