forked from ncipollo/release-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtifactPathValidator.test.ts
60 lines (47 loc) · 1.69 KB
/
ArtifactPathValidator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const directoryMock = jest.fn()
const warnMock = jest.fn()
import {ArtifactPathValidator} from "../src/ArtifactPathValidator";
const pattern = 'pattern'
jest.mock('@actions/core', () => {
return {warning: warnMock};
})
jest.mock('fs', () => {
return {
statSync: () => {
return {isDirectory: directoryMock}
}
};
})
describe("ArtifactPathValidator", () => {
beforeEach(() => {
warnMock.mockClear()
directoryMock.mockClear()
})
it("warns and filters out path which points to a directory", () => {
const paths = ['path1', 'path2']
directoryMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
const validator = new ArtifactPathValidator(false, paths, pattern)
const result = validator.validate()
expect(warnMock).toBeCalled()
expect(result).toEqual(['path2'])
})
it("warns when no glob results are produced and empty results shouldn't throw", () => {
const validator = new ArtifactPathValidator(false, [], pattern)
const result = validator.validate()
expect(warnMock).toBeCalled()
})
it("throws when no glob results are produced and empty results shouild throw", () => {
const validator = new ArtifactPathValidator(true, [], pattern)
expect(() => {
validator.validate()
}).toThrow()
})
it("throws when path points to directory", () => {
const paths = ['path1', 'path2']
directoryMock.mockReturnValueOnce(true).mockReturnValueOnce(false)
const validator = new ArtifactPathValidator(true, paths, pattern)
expect(() => {
validator.validate()
}).toThrow()
})
})