Skip to content

Commit 48285b1

Browse files
authored
Merge pull request #416 from github/full-esm-support
Full esm support
2 parents 85ee911 + 0d2c53c commit 48285b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6659
-9123
lines changed

.babelrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.eslintrc.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
{
22
"env": {
3-
"commonjs": true,
4-
"es6": true,
5-
"jest": true,
3+
"es2022": true,
64
"node": true
75
},
86
"extends": "eslint:recommended",
97
"globals": {
108
"Atomics": "readonly",
11-
"SharedArrayBuffer": "readonly"
9+
"SharedArrayBuffer": "readonly",
10+
"vi": "readonly",
11+
"describe": "readonly",
12+
"test": "readonly",
13+
"expect": "readonly",
14+
"beforeEach": "readonly",
15+
"afterEach": "readonly"
1216
},
1317
"parserOptions": {
14-
"ecmaVersion": 2020,
18+
"ecmaVersion": 2022,
1519
"sourceType": "module"
1620
},
1721
"rules": {}

__tests__/functions/actions-status.test.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import * as core from '@actions/core'
2-
import {actionStatus} from '../../src/functions/action-status'
3-
import {truncateCommentBody} from '../../src/functions/truncate-comment-body'
4-
import {API_HEADERS} from '../../src/functions/api-headers'
1+
import {vi, expect, test, beforeEach} from 'vitest'
2+
import {actionStatus} from '../../src/functions/action-status.js'
3+
import {truncateCommentBody} from '../../src/functions/truncate-comment-body.js'
4+
import {API_HEADERS} from '../../src/functions/api-headers.js'
55

66
var context
77
var octokit
88
beforeEach(() => {
9-
jest.clearAllMocks()
10-
11-
jest.spyOn(core, 'debug').mockImplementation(() => {})
12-
jest.spyOn(core, 'warning').mockImplementation(() => {})
9+
vi.clearAllMocks()
1310

1411
process.env.GITHUB_SERVER_URL = 'https://github.com'
1512
process.env.GITHUB_RUN_ID = '12345'
@@ -32,15 +29,15 @@ beforeEach(() => {
3229
octokit = {
3330
rest: {
3431
reactions: {
35-
createForIssueComment: jest.fn().mockReturnValueOnce({
32+
createForIssueComment: vi.fn().mockReturnValueOnce({
3633
data: {}
3734
}),
38-
deleteForIssueComment: jest.fn().mockReturnValueOnce({
35+
deleteForIssueComment: vi.fn().mockReturnValueOnce({
3936
data: {}
4037
})
4138
},
4239
issues: {
43-
createComment: jest.fn().mockReturnValueOnce({
40+
createComment: vi.fn().mockReturnValueOnce({
4441
data: {}
4542
})
4643
}

__tests__/functions/admin.test.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import {isAdmin} from '../../src/functions/admin'
2-
import {COLORS} from '../../src/functions/colors'
1+
import {isAdmin} from '../../src/functions/admin.js'
2+
import {vi, expect, test, beforeEach} from 'vitest'
3+
import {COLORS} from '../../src/functions/colors.js'
34
import * as github from '@actions/github'
45
import * as core from '@actions/core'
56

6-
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
7-
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
8-
// const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
7+
const debugMock = vi.spyOn(core, 'debug')
8+
const warningMock = vi.spyOn(core, 'warning')
99

1010
class NotFoundError extends Error {
1111
constructor(message) {
@@ -24,8 +24,7 @@ class WildError extends Error {
2424
var context
2525
var octokit
2626
beforeEach(() => {
27-
jest.clearAllMocks()
28-
jest.spyOn(core, 'info').mockImplementation(() => {})
27+
vi.clearAllMocks()
2928
process.env.INPUT_ADMINS_PAT = 'faketoken'
3029
process.env.INPUT_ADMINS =
3130
'MoNaLiSa,@lisamona,octoawesome/octo-awEsome-team,bad$user'
@@ -35,24 +34,24 @@ beforeEach(() => {
3534
}
3635

3736
octokit = {
38-
request: jest.fn().mockReturnValueOnce({
37+
request: vi.fn().mockReturnValueOnce({
3938
status: 204
4039
}),
4140
rest: {
4241
orgs: {
43-
get: jest.fn().mockReturnValueOnce({
42+
get: vi.fn().mockReturnValueOnce({
4443
data: {id: '12345'}
4544
})
4645
},
4746
teams: {
48-
getByName: jest.fn().mockReturnValueOnce({
47+
getByName: vi.fn().mockReturnValueOnce({
4948
data: {id: '567890'}
5049
})
5150
}
5251
}
5352
}
5453

55-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
54+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
5655
return octokit
5756
})
5857
})
@@ -117,11 +116,11 @@ test('runs isAdmin checks for an org team and finds a valid user', async () => {
117116

118117
// This only handles the global failure case of any 404 in the admin.js file
119118
test('runs isAdmin checks for an org team and does not find the org', async () => {
120-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
119+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
121120
return {
122121
rest: {
123122
orgs: {
124-
get: jest
123+
get: vi
125124
.fn()
126125
.mockRejectedValueOnce(
127126
new NotFoundError('Reference does not exist')
@@ -139,16 +138,16 @@ test('runs isAdmin checks for an org team and does not find the org', async () =
139138

140139
// This only handles the global failure case of any 404 in the admin.js file
141140
test('runs isAdmin checks for an org team and does not find the team', async () => {
142-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
141+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
143142
return {
144143
rest: {
145144
orgs: {
146-
get: jest.fn().mockReturnValueOnce({
145+
get: vi.fn().mockReturnValueOnce({
147146
data: {id: '12345'}
148147
})
149148
},
150149
teams: {
151-
getByName: jest
150+
getByName: vi
152151
.fn()
153152
.mockRejectedValueOnce(
154153
new NotFoundError('Reference does not exist')
@@ -166,19 +165,19 @@ test('runs isAdmin checks for an org team and does not find the team', async ()
166165

167166
// This test correctly tests if a user is a member of a team or not. If they are in a team a 204 is returned. If they are not a 404 is returned like in this test example
168167
test('runs isAdmin checks for an org team and does not find the user in the team', async () => {
169-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
168+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
170169
return {
171-
request: jest
170+
request: vi
172171
.fn()
173172
.mockRejectedValueOnce(new NotFoundError('Reference does not exist')),
174173
rest: {
175174
orgs: {
176-
get: jest.fn().mockReturnValueOnce({
175+
get: vi.fn().mockReturnValueOnce({
177176
data: {id: '12345'}
178177
})
179178
},
180179
teams: {
181-
getByName: jest.fn().mockReturnValueOnce({
180+
getByName: vi.fn().mockReturnValueOnce({
182181
data: {id: '567890'}
183182
})
184183
}
@@ -193,19 +192,19 @@ test('runs isAdmin checks for an org team and does not find the user in the team
193192
})
194193

195194
test('runs isAdmin checks for an org team and an unexpected status code is received from the request method with octokit', async () => {
196-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
195+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
197196
return {
198-
request: jest.fn().mockReturnValueOnce({
197+
request: vi.fn().mockReturnValueOnce({
199198
status: 500
200199
}),
201200
rest: {
202201
orgs: {
203-
get: jest.fn().mockReturnValueOnce({
202+
get: vi.fn().mockReturnValueOnce({
204203
data: {id: '12345'}
205204
})
206205
},
207206
teams: {
208-
getByName: jest.fn().mockReturnValueOnce({
207+
getByName: vi.fn().mockReturnValueOnce({
209208
data: {id: '567890'}
210209
})
211210
}
@@ -221,19 +220,19 @@ test('runs isAdmin checks for an org team and an unexpected status code is recei
221220
})
222221

223222
test('runs isAdmin checks for an org team and an unexpected error is thrown from any API call', async () => {
224-
jest.spyOn(github, 'getOctokit').mockImplementation(() => {
223+
vi.spyOn(github, 'getOctokit').mockImplementation(() => {
225224
return {
226-
request: jest
225+
request: vi
227226
.fn()
228227
.mockRejectedValueOnce(new WildError('something went boom')),
229228
rest: {
230229
orgs: {
231-
get: jest.fn().mockReturnValueOnce({
230+
get: vi.fn().mockReturnValueOnce({
232231
data: {id: '12345'}
233232
})
234233
},
235234
teams: {
236-
getByName: jest.fn().mockReturnValueOnce({
235+
getByName: vi.fn().mockReturnValueOnce({
237236
data: {id: '567890'}
238237
})
239238
}

__tests__/functions/branch-ruleset-checks.test.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import {branchRulesetChecks} from '../../src/functions/branch-ruleset-checks'
1+
import {branchRulesetChecks} from '../../src/functions/branch-ruleset-checks.js'
2+
import {vi, expect, test, beforeEach} from 'vitest'
23
import * as core from '@actions/core'
3-
import {COLORS} from '../../src/functions/colors'
4-
import {SUGGESTED_RULESETS} from '../../src/functions/suggested-rulesets'
5-
import {ERROR} from '../../src/functions/templates/error'
4+
import {COLORS} from '../../src/functions/colors.js'
5+
import {SUGGESTED_RULESETS} from '../../src/functions/suggested-rulesets.js'
6+
import {ERROR} from '../../src/functions/templates/error.js'
7+
8+
const debugMock = vi.spyOn(core, 'debug')
9+
const infoMock = vi.spyOn(core, 'info')
10+
const warningMock = vi.spyOn(core, 'warning')
611

712
var context
813
var octokit
914
var data
1015
var rulesets
1116

12-
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
13-
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
14-
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
15-
1617
class ForbiddenError extends Error {
1718
constructor(message) {
1819
super(message)
@@ -21,10 +22,7 @@ class ForbiddenError extends Error {
2122
}
2223

2324
beforeEach(() => {
24-
jest.spyOn(core, 'info').mockImplementation(() => {})
25-
jest.spyOn(core, 'debug').mockImplementation(() => {})
26-
jest.spyOn(core, 'warning').mockImplementation(() => {})
27-
jest.clearAllMocks()
25+
vi.clearAllMocks()
2826

2927
data = {
3028
branch: 'main'
@@ -79,7 +77,7 @@ beforeEach(() => {
7977
octokit = {
8078
rest: {
8179
repos: {
82-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
80+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
8381
}
8482
}
8583
}
@@ -89,7 +87,7 @@ test('finds that no branch protections or rulesets are defined', async () => {
8987
octokit = {
9088
rest: {
9189
repos: {
92-
getBranchRules: jest.fn().mockReturnValueOnce({data: []})
90+
getBranchRules: vi.fn().mockReturnValueOnce({data: []})
9391
}
9492
}
9593
}
@@ -119,7 +117,7 @@ test('finds that the branch ruleset is missing the deletion rule', async () => {
119117
octokit = {
120118
rest: {
121119
repos: {
122-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
120+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
123121
}
124122
}
125123
}
@@ -150,7 +148,7 @@ test('finds that the branch ruleset is missing the dismiss_stale_reviews_on_push
150148
octokit = {
151149
rest: {
152150
repos: {
153-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
151+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
154152
}
155153
}
156154
}
@@ -175,7 +173,7 @@ test('finds that all suggested branch rulesets are defined', async () => {
175173
octokit = {
176174
rest: {
177175
repos: {
178-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
176+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
179177
}
180178
}
181179
}
@@ -214,7 +212,7 @@ test('finds that all suggested branch rulesets are defined but required reviews
214212
octokit = {
215213
rest: {
216214
repos: {
217-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
215+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
218216
}
219217
}
220218
}
@@ -252,7 +250,7 @@ test('should still pass even with many required reviewers', async () => {
252250
octokit = {
253251
rest: {
254252
repos: {
255-
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
253+
getBranchRules: vi.fn().mockReturnValueOnce({data: rulesets})
256254
}
257255
}
258256
}
@@ -271,7 +269,7 @@ test('fails due to a 403 from the GitHub API due to a repository being private o
271269
octokit = {
272270
rest: {
273271
repos: {
274-
getBranchRules: jest
272+
getBranchRules: vi
275273
.fn()
276274
.mockRejectedValueOnce(
277275
new ForbiddenError(ERROR.messages.upgrade_or_public.message)
@@ -293,7 +291,7 @@ test('fails due to an unknown 403 from the GitHub API', async () => {
293291
octokit = {
294292
rest: {
295293
repos: {
296-
getBranchRules: jest
294+
getBranchRules: vi
297295
.fn()
298296
.mockRejectedValueOnce(new ForbiddenError(errorMessage))
299297
}

__tests__/functions/check-input.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {checkInput} from '../../src/functions/check-input'
1+
import {checkInput} from '../../src/functions/check-input.js'
2+
import {expect, test} from 'vitest'
23

34
test('checks an input an finds that it is valid', async () => {
45
expect(checkInput('production')).toStrictEqual('production')

0 commit comments

Comments
 (0)