Skip to content

Commit 7446b3d

Browse files
committed
Merge branch 'dev' into releases/v2
2 parents df6c6ee + 5e1aba9 commit 7446b3d

File tree

16 files changed

+989
-1508
lines changed

16 files changed

+989
-1508
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- uses: actions/setup-node@v4
2121
with:
22-
node-version-file: '.nvmrc'
22+
node-version-file: '.node-version'
2323
registry-url: 'https://registry.npmjs.org'
2424

2525
- name: Install Yarn

.github/workflows/integration.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: 30 15 * * 0-6
7-
87
push:
98
tags-ignore:
109
- '*.*'

.github/workflows/production.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- uses: actions/setup-node@v4
2121
with:
22-
node-version-file: '.nvmrc'
22+
node-version-file: '.node-version'
2323
registry-url: 'https://registry.npmjs.org'
2424

2525
- name: Install Yarn

.github/workflows/version.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# Setup .npmrc file to publish to npm
3030
- uses: actions/setup-node@v4
3131
with:
32-
node-version-file: '.nvmrc'
32+
node-version-file: '.node-version'
3333
registry-url: 'https://registry.npmjs.org'
3434
scope: '@jamesives'
3535

@@ -60,7 +60,7 @@ jobs:
6060
# Setup .npmrc file to publish to GitHub Packages
6161
- uses: actions/setup-node@v4
6262
with:
63-
node-version-file: '.nvmrc'
63+
node-version-file: '.node-version'
6464
registry-url: 'https://npm.pkg.github.com'
6565
scope: '@jamesives'
6666

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.11.0

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ When contributing to this repository, please first discuss the change you wish t
1515

1616
## Deploying 🚚
1717

18-
In order to deploy and test your own fork of this action, you must commit the `node_modules` dependencies. Be sure to run `nvm use` before installing any dependencies. You can learn more about nvm [here](https://github.com/nvm-sh/nvm/blob/master/README.md).
18+
In order to deploy and test your own fork of this action, you must commit the `node_modules` dependencies. Be sure to switch to the Node version listed in the [.node-version](./.node-version) file first.
1919

2020
To do this you can follow the instructions below:
2121

__tests__/fetch.test.ts

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import {retrieveData, generateExport} from '../src/fetch'
2-
import nock from 'nock'
32

43
jest.setTimeout(1000000)
5-
nock.enableNetConnect()
64

75
describe('fetch', () => {
86
describe('retrieveData', () => {
9-
afterEach(nock.cleanAll)
10-
afterAll(nock.restore)
7+
afterEach(() => {
8+
jest.clearAllMocks()
9+
})
1110

1211
it('should return some data', async () => {
13-
nock('https://jamesiv.es').get('/').reply(200, {
14-
data: '12345'
12+
global.fetch = jest.fn().mockResolvedValue({
13+
ok: true,
14+
json: jest.fn().mockResolvedValue({data: '12345'}),
15+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
1516
})
1617

1718
const data = await retrieveData({
@@ -22,11 +23,11 @@ describe('fetch', () => {
2223
})
2324

2425
it('should handle the triple bracket replacements', async () => {
25-
nock('https://jives.dev/')
26-
.post('/', '{"bestCat":"montezuma"}')
27-
.reply(200, {
28-
data: '12345'
29-
})
26+
global.fetch = jest.fn().mockResolvedValue({
27+
ok: true,
28+
json: jest.fn().mockResolvedValue({data: '12345'}),
29+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
30+
})
3031

3132
const data = await retrieveData({
3233
debug: true,
@@ -45,8 +46,6 @@ describe('fetch', () => {
4546

4647
it('should error if improperly formatted json is passed in', async () => {
4748
try {
48-
nock('https://jamesiv.es').get('/').reply(200)
49-
5049
await retrieveData({
5150
debug: true,
5251
endpoint: 'https://example.com',
@@ -61,8 +60,10 @@ describe('fetch', () => {
6160
})
6261

6362
it('should error if the response is not ok', async () => {
64-
nock('https://jamesiv.es').post('/').reply(404, {
65-
a: 1
63+
global.fetch = jest.fn().mockResolvedValue({
64+
ok: false,
65+
json: jest.fn().mockResolvedValue({a: 1}),
66+
text: jest.fn().mockResolvedValue('{"a":1}')
6667
})
6768

6869
try {
@@ -83,18 +84,18 @@ describe('fetch', () => {
8384
}
8485
})
8586

86-
it('should error if the response is not ok after several retrys', async () => {
87+
it('should error if the response is not ok after several retries', async () => {
8788
jest.setTimeout(1000000)
88-
89-
try {
90-
nock('https://jives.dev').get('/').once().replyWithError({
91-
message: 'This is catastrophic'
92-
})
93-
94-
nock('https://jives.dev').get('/').reply(200, {
95-
data: '12345'
89+
global.fetch = jest
90+
.fn()
91+
.mockRejectedValueOnce(new Error('This is catastrophic'))
92+
.mockResolvedValueOnce({
93+
ok: true,
94+
json: jest.fn().mockResolvedValue({data: '12345'}),
95+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
9696
})
9797

98+
try {
9899
await retrieveData({
99100
debug: true,
100101
endpoint: 'https://jives.dev',
@@ -117,7 +118,7 @@ describe('fetch', () => {
117118
expect(process.env['fetchApiData']).toBe('{"bestCat":"montezuma"}')
118119
})
119120

120-
it('should save non standard file types', async () => {
121+
it('should save non-standard file types', async () => {
121122
await generateExport({
122123
data: 'hello',
123124
format: 'txt',

__tests__/lib.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {exportVariable, setFailed} from '@actions/core'
2-
import nock from 'nock'
32
import {action} from '../src/constants'
43
import run from '../src/lib'
54
import '../src/main'
@@ -15,38 +14,49 @@ jest.mock('@actions/core', () => ({
1514

1615
describe('lib', () => {
1716
beforeEach(() => {
18-
nock('https://jamesiv.es').get('/').reply(200, {
19-
data: '12345'
17+
jest.clearAllMocks()
18+
19+
global.fetch = jest.fn().mockResolvedValue({
20+
json: jest.fn().mockResolvedValue({data: '12345'}),
21+
text: jest.fn().mockResolvedValue('{"data":"12345"}'),
22+
ok: true
2023
})
2124
})
2225

2326
afterEach(() => {
24-
nock.restore()
2527
Object.assign(action, JSON.parse(originalAction))
2628
})
2729

28-
afterEach(nock.cleanAll)
29-
3030
it('should run through the commands', async () => {
3131
Object.assign(action, {
3232
debug: true,
33-
endpoint: 'https://jamesiv.es',
33+
endpoint: 'https://jives.dev',
3434
setOutput: true
3535
})
36+
3637
await run(action)
3738

38-
expect(exportVariable).toHaveBeenCalled()
39+
expect(exportVariable).toHaveBeenCalledTimes(1)
40+
expect(global.fetch).toHaveBeenCalledWith(
41+
'https://jives.dev',
42+
expect.any(Object)
43+
)
3944
})
4045

4146
it('should run through the commands but not save output', async () => {
4247
Object.assign(action, {
4348
debug: true,
44-
endpoint: 'https://jamesiv.es',
49+
endpoint: 'https://jives.dev',
4550
setOutput: false
4651
})
52+
4753
await run(action)
4854

4955
expect(exportVariable).toHaveBeenCalledTimes(0)
56+
expect(global.fetch).toHaveBeenCalledWith(
57+
'https://jives.dev',
58+
expect.any(Object)
59+
)
5060
})
5161

5262
it('should throw an error if no endpoint is provided', async () => {
@@ -58,6 +68,7 @@ describe('lib', () => {
5868
try {
5969
await run(action)
6070
} catch (error) {
71+
console.error(error)
6172
expect(setFailed).toHaveBeenCalled()
6273
}
6374
})
@@ -73,6 +84,7 @@ describe('lib', () => {
7384
try {
7485
await run(action)
7586
} catch (error) {
87+
console.error(error)
7688
expect(setFailed).toHaveBeenCalled()
7789
}
7890
})

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default tseslint.config(
1717
},
1818
rules: {
1919
'jest/no-conditional-expect': 'off',
20-
'@typescript-eslint/ban-types': [
20+
'@typescript-eslint/no-restricted-types': [
2121
'error',
2222
{
2323
types: {

0 commit comments

Comments
 (0)