Skip to content

Commit 31f3f05

Browse files
authored
Merge pull request #93 from microcmsio/update-ghactions
GitHub Actionsワークフローのメンテナンス
2 parents 7d2d0fc + aae0130 commit 31f3f05

File tree

6 files changed

+249
-105
lines changed

6 files changed

+249
-105
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,45 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: ['main']
8+
branches: ["main"]
99
pull_request:
10-
branches: ['main']
10+
branches: ["main"]
1111

1212
jobs:
13-
build:
13+
static-check:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
19+
with:
20+
node-version-file: ".node-version"
21+
cache: "npm"
22+
- run: npm ci
23+
- name: Format Check
24+
run: npm run format
25+
- name: Lint
26+
run: npm run lint
27+
- name: Type Check
28+
run: npm run typecheck
29+
30+
build-and-test:
1431
runs-on: ubuntu-latest
1532

1633
strategy:
1734
matrix:
18-
node-version: [18.x, 20.x]
35+
node-version: [18.x, 20.x, 22.x, 24.x]
1936
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2037

2138
steps:
22-
- uses: actions/checkout@v4
39+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2340
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v4
41+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
2542
with:
2643
node-version: ${{ matrix.node-version }}
27-
cache: 'npm'
44+
cache: "npm"
2845
- run: npm ci
29-
- run: npm run build
30-
- run: npm test
46+
- name: Build
47+
run: npm run build
48+
- name: Unit Tests
49+
run: npm run test

.github/workflows/release.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ name: release
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*"
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-node@v4
12+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
13+
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
1414
with:
15-
node-version: '18.x'
16-
registry-url: 'https://registry.npmjs.org'
15+
node-version-file: ".node-version"
16+
registry-url: "https://registry.npmjs.org"
1717
- name: release on npm
1818
run: |
1919
npm ci
2020
npm run lint
21+
npm run typecheck
2122
npm run test
2223
npm run build
2324
- run: npm publish

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
"scripts": {
2525
"build": "tsup",
2626
"postbuild": "mkdir -p ./dist/umd/ && cp -pR ./dist/iife/* ./dist/umd",
27-
"lint": "eslint ./src",
28-
"lint:fix": "eslint --fix ./src",
27+
"lint": "eslint ./src ./tests",
28+
"lint:fix": "eslint --fix ./src ./tests",
29+
"format": "prettier --check ./src ./tests",
30+
"format:fix": "prettier --write ./src ./tests",
31+
"typecheck": "tsc --noEmit",
2932
"test": "jest --coverage=false",
3033
"test:coverage": "jest --coverage=true"
3134
},

tests/get.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,22 @@ describe('get', () => {
5858
test('Return error message in case of server error', () => {
5959
// Create temporary server error
6060
server.use(
61-
http.get(`${testBaseUrl}/list-type`, () => {
62-
return HttpResponse.json({ message: 'Internal Server Error' }, { status: 500 });
63-
}, { once: true })
61+
http.get(
62+
`${testBaseUrl}/list-type`,
63+
() => {
64+
return HttpResponse.json(
65+
{ message: 'Internal Server Error' },
66+
{ status: 500 },
67+
);
68+
},
69+
{ once: true },
70+
),
6471
);
6572

6673
expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
6774
new Error(
68-
'fetch API response status: 500\n message is `Internal Server Error`'
69-
)
75+
'fetch API response status: 500\n message is `Internal Server Error`',
76+
),
7077
);
7178
});
7279
});

tests/getAllContentIds.test.ts

Lines changed: 124 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,32 @@ describe('getAllContentIds', () => {
1515

1616
test('should fetch all content ids', async () => {
1717
server.use(
18-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
19-
return HttpResponse.json({
18+
http.get(
19+
`${testBaseUrl}/getAllContentIds-list-type`,
20+
() => {
21+
return HttpResponse.json(
22+
{
2023
totalCount: 100,
21-
}, { status: 200 });
22-
}, { once: true }),
23-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
24-
return HttpResponse.json({
24+
},
25+
{ status: 200 },
26+
);
27+
},
28+
{ once: true },
29+
),
30+
http.get(
31+
`${testBaseUrl}/getAllContentIds-list-type`,
32+
() => {
33+
return HttpResponse.json(
34+
{
2535
contents: Array(100)
26-
.fill(null)
27-
.map((_, index) => ({ id: `id${index}` })),
28-
}, { status: 200 });
29-
}, { once: true }),
36+
.fill(null)
37+
.map((_, index) => ({ id: `id${index}` })),
38+
},
39+
{ status: 200 },
40+
);
41+
},
42+
{ once: true },
43+
),
3044
);
3145

3246
const result = await client.getAllContentIds({
@@ -40,32 +54,60 @@ describe('getAllContentIds', () => {
4054

4155
test('should handle pagination and fetch more than limit', async () => {
4256
server.use(
43-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
44-
return HttpResponse.json({
57+
http.get(
58+
`${testBaseUrl}/getAllContentIds-list-type`,
59+
() => {
60+
return HttpResponse.json(
61+
{
4562
totalCount: 250,
46-
}, { status: 200 });
47-
}, { once: true }),
48-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
49-
return HttpResponse.json({
63+
},
64+
{ status: 200 },
65+
);
66+
},
67+
{ once: true },
68+
),
69+
http.get(
70+
`${testBaseUrl}/getAllContentIds-list-type`,
71+
() => {
72+
return HttpResponse.json(
73+
{
5074
contents: Array(100)
51-
.fill(null)
52-
.map((_, index) => ({ id: `id${index}` })),
53-
}, { status: 200 });
54-
}, { once: true }),
55-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
56-
return HttpResponse.json({
75+
.fill(null)
76+
.map((_, index) => ({ id: `id${index}` })),
77+
},
78+
{ status: 200 },
79+
);
80+
},
81+
{ once: true },
82+
),
83+
http.get(
84+
`${testBaseUrl}/getAllContentIds-list-type`,
85+
() => {
86+
return HttpResponse.json(
87+
{
5788
contents: Array(100)
58-
.fill(null)
59-
.map((_, index) => ({ id: `id${index + 100}` })),
60-
}, { status: 200 });
61-
}, { once: true }),
62-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
63-
return HttpResponse.json({
89+
.fill(null)
90+
.map((_, index) => ({ id: `id${index + 100}` })),
91+
},
92+
{ status: 200 },
93+
);
94+
},
95+
{ once: true },
96+
),
97+
http.get(
98+
`${testBaseUrl}/getAllContentIds-list-type`,
99+
() => {
100+
return HttpResponse.json(
101+
{
64102
contents: Array(50)
65-
.fill(null)
66-
.map((_, index) => ({ id: `id${index + 200}` })),
67-
}, { status: 200 });
68-
}, { once: true }),
103+
.fill(null)
104+
.map((_, index) => ({ id: `id${index + 200}` })),
105+
},
106+
{ status: 200 },
107+
);
108+
},
109+
{ once: true },
110+
),
69111
);
70112

71113
const result = await client.getAllContentIds({
@@ -79,18 +121,32 @@ describe('getAllContentIds', () => {
79121

80122
test('should fetch all content ids with alternateField field', async () => {
81123
server.use(
82-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
83-
return HttpResponse.json({
124+
http.get(
125+
`${testBaseUrl}/getAllContentIds-list-type`,
126+
() => {
127+
return HttpResponse.json(
128+
{
84129
totalCount: 100,
85-
}, { status: 200 });
86-
}, { once: true }),
87-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
88-
return HttpResponse.json({
130+
},
131+
{ status: 200 },
132+
);
133+
},
134+
{ once: true },
135+
),
136+
http.get(
137+
`${testBaseUrl}/getAllContentIds-list-type`,
138+
() => {
139+
return HttpResponse.json(
140+
{
89141
contents: Array(100)
90-
.fill(null)
91-
.map((_, index) => ({ url: `id${index}` })),
92-
}, { status: 200 });
93-
}, { once: true }),
142+
.fill(null)
143+
.map((_, index) => ({ url: `id${index}` })),
144+
},
145+
{ status: 200 },
146+
);
147+
},
148+
{ once: true },
149+
),
94150
);
95151

96152
const result = await client.getAllContentIds({
@@ -105,18 +161,34 @@ describe('getAllContentIds', () => {
105161

106162
test('should throw error when alternateField field is not string', async () => {
107163
server.use(
108-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
109-
return HttpResponse.json({
164+
http.get(
165+
`${testBaseUrl}/getAllContentIds-list-type`,
166+
() => {
167+
return HttpResponse.json(
168+
{
110169
totalCount: 100,
111-
}, { status: 200 });
112-
}, { once: true }),
113-
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
114-
return HttpResponse.json({
170+
},
171+
{ status: 200 },
172+
);
173+
},
174+
{ once: true },
175+
),
176+
http.get(
177+
`${testBaseUrl}/getAllContentIds-list-type`,
178+
() => {
179+
return HttpResponse.json(
180+
{
115181
contents: Array(100)
116-
.fill(null)
117-
.map(() => ({ image: { url: 'url', width: 100, height: 100 } })),
118-
}, { status: 200 });
119-
}, { once: true }),
182+
.fill(null)
183+
.map(() => ({
184+
image: { url: 'url', width: 100, height: 100 },
185+
})),
186+
},
187+
{ status: 200 },
188+
);
189+
},
190+
{ once: true },
191+
),
120192
);
121193

122194
await expect(

0 commit comments

Comments
 (0)