-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.test.ts
174 lines (143 loc) · 4.45 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import * as core from "@actions/core";
import { run } from "../src/main";
import { normalizeSeparators, tempfile } from "../src/utils";
const defaultEnv = {
'INPUT_FILES-SEPARATOR': '\n',
'INPUT_FILES-FROM-SOURCE-FILE-SEPARATOR': '\n',
'INPUT_EXCLUDED-FILES-SEPARATOR': '\n',
'INPUT_EXCLUDED-FILES-FROM-SOURCE-FILE-SEPARATOR': '\n',
'INPUT_FOLLOW-SYMBOLIC-LINKS': 'true',
'INPUT_ESCAPE-PATHS': 'false',
INPUT_SEPARATOR: ' ',
'INPUT_STRIP-TOP-LEVEL-DIR': 'true',
'INPUT_WORKING-DIRECTORY': '.',
'INPUT_INCLUDE-DELETED-FILES': 'false',
INPUT_FILES: '',
'INPUT_FILES-FROM-SOURCE-FILE': ''
}
function mockedEnv(testEnvVars: {[key: string]: string}) {
for (const key in testEnvVars) {
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]
}
}
test('returns the paths of the filtered files (input files, input source files)', async () => {
mockedEnv({
...defaultEnv,
INPUT_FILES: '__tests__/**/*.test.ts\n*.sh',
'INPUT_FILES-FROM-SOURCE-FILE':
'__tests__/source-files.txt\n__tests__/source-files.txt'
})
const EXPECTED_FILENAMES = [
'.github/workflows/greetings.yml',
'CODE_OF_CONDUCT.md',
'CONTRIBUTING.md',
'HISTORY.md',
'README.md',
'__tests__/cleanup.test.ts',
'__tests__/getDeletedFiles.test.ts',
'__tests__/getFilesFromSourceFile.test.ts',
'__tests__/main.test.ts',
'__tests__/util.test.ts'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)
// @ts-ignore
core.setOutput = jest.fn()
await run()
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})
test('returns the paths of the all other files (input files)', async () => {
mockedEnv({
...defaultEnv,
INPUT_FILES: '!__tests__\n!*.md\n!dist\n!jest\n!.*\n!src/main.ts\n!lib',
})
const EXPECTED_FILENAMES = [
'LICENSE',
'action.yml',
'jest.config.js',
'package.json',
'renovate.json',
'src/cleanup.ts',
'src/utils.ts',
'tsconfig.json',
'yarn.lock'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)
// @ts-ignore
core.setOutput = jest.fn()
await run()
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})
test('returns the paths of the filtered files (input files)', async () => {
mockedEnv({
...defaultEnv,
'INPUT_INCLUDE-DELETED-FILES': 'true',
INPUT_FILES: '__tests__/*.test.ts\n__tests__/**.txt\n*.sh',
'INPUT_BASE-SHA': '99561ef',
INPUT_SHA: '2eb2427'
})
const EXPECTED_FILENAMES = [
'__tests__/cleanup.test.ts',
'__tests__/getDeletedFiles.test.ts',
'__tests__/getFilesFromSourceFile.test.ts',
'__tests__/main.test.ts',
'__tests__/source-files.txt',
'__tests__/util.test.ts',
'entrypoint.sh'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)
// @ts-ignore
core.setOutput = jest.fn()
await run()
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})
test('returns the paths of the filtered files (input source files)', async () => {
mockedEnv({
...defaultEnv,
'INPUT_FILES-FROM-SOURCE-FILE':
'__tests__/source-files.txt\n__tests__/source-files.txt\n__tests__/source-files.txt'
})
const EXPECTED_FILENAMES = [
'.github/workflows/greetings.yml',
'CODE_OF_CONDUCT.md',
'CONTRIBUTING.md',
'HISTORY.md',
'README.md'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)
// @ts-ignore
core.setOutput = jest.fn()
await run()
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})
test('returns the paths of the filtered files in the paths-output-file', async () => {
mockedEnv({
...defaultEnv,
'INPUT_FILES-FROM-SOURCE-FILE':
'__tests__/source-files.txt\n__tests__/source-files.txt\n__tests__/source-files.txt'
})
const EXPECTED_FILENAMES = [
'.github/workflows/greetings.yml',
'CODE_OF_CONDUCT.md',
'CONTRIBUTING.md',
'HISTORY.md',
'README.md'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)
// @ts-ignore
core.setOutput = jest.fn()
const pathsOutputFile = tempfile('.txt')
// @ts-ignore
tempfile = jest.fn().mockReturnValue(pathsOutputFile)
await run()
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
expect(core.setOutput).toHaveBeenNthCalledWith(
2,
'paths-output-file',
pathsOutputFile
)
})