Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,45 @@ name: Node.js CI

on:
push:
branches: ['main']
branches: ["main"]
pull_request:
branches: ['main']
branches: ["main"]

jobs:
build:
static-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: ".node-version"
cache: "npm"
- run: npm ci
- name: Format Check
run: npm run format
- name: Lint
run: npm run lint
- name: Type Check
run: npm run typecheck

build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x, 24.x]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現行で、24まで出ているので、加えておきました。

# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache: "npm"
- run: npm ci
- run: npm run build
- run: npm test
- name: Build
run: npm run build
- name: Unit Tests
run: npm run test
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ name: release
on:
push:
tags:
- 'v*'
- "v*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
Comment on lines -12 to +13
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

バージョンアップと同時に、pinactでコミットハッシュで固定しました。

with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
node-version-file: ".node-version"
registry-url: "https://registry.npmjs.org"
Comment on lines -15 to +16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

バージョン指定を .node-version ファイルを読むようにしました。

追伸: フォーマットかかっていて、クオーテーションが変わってますが気にせずで。

- name: release on npm
run: |
npm ci
npm run lint
npm run typecheck
npm run test
npm run build
- run: npm publish
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"scripts": {
"build": "tsup",
"postbuild": "mkdir -p ./dist/umd/ && cp -pR ./dist/iife/* ./dist/umd",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src",
"lint": "eslint ./src ./tests",
"lint:fix": "eslint --fix ./src ./tests",
"format": "prettier --check ./src ./tests",
"format:fix": "prettier --write ./src ./tests",
"typecheck": "tsc --noEmit",
"test": "jest --coverage=false",
"test:coverage": "jest --coverage=true"
},
Expand Down
17 changes: 12 additions & 5 deletions tests/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ describe('get', () => {
test('Return error message in case of server error', () => {
// Create temporary server error
server.use(
http.get(`${testBaseUrl}/list-type`, () => {
return HttpResponse.json({ message: 'Internal Server Error' }, { status: 500 });
}, { once: true })
http.get(
`${testBaseUrl}/list-type`,
() => {
return HttpResponse.json(
{ message: 'Internal Server Error' },
{ status: 500 },
);
},
{ once: true },
),
);

expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
new Error(
'fetch API response status: 500\n message is `Internal Server Error`'
)
'fetch API response status: 500\n message is `Internal Server Error`',
),
);
});
});
176 changes: 124 additions & 52 deletions tests/getAllContentIds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,32 @@ describe('getAllContentIds', () => {

test('should fetch all content ids', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

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

test('should handle pagination and fetch more than limit', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 250,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
.fill(null)
.map((_, index) => ({ id: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ id: `id${index + 100}` })),
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
.fill(null)
.map((_, index) => ({ id: `id${index + 100}` })),
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(50)
.fill(null)
.map((_, index) => ({ id: `id${index + 200}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ id: `id${index + 200}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

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

test('should fetch all content ids with alternateField field', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map((_, index) => ({ url: `id${index}` })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map((_, index) => ({ url: `id${index}` })),
},
{ status: 200 },
);
},
{ once: true },
),
);

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

test('should throw error when alternateField field is not string', async () => {
server.use(
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
totalCount: 100,
}, { status: 200 });
}, { once: true }),
http.get(`${testBaseUrl}/getAllContentIds-list-type`, () => {
return HttpResponse.json({
},
{ status: 200 },
);
},
{ once: true },
),
http.get(
`${testBaseUrl}/getAllContentIds-list-type`,
() => {
return HttpResponse.json(
{
contents: Array(100)
.fill(null)
.map(() => ({ image: { url: 'url', width: 100, height: 100 } })),
}, { status: 200 });
}, { once: true }),
.fill(null)
.map(() => ({
image: { url: 'url', width: 100, height: 100 },
})),
},
{ status: 200 },
);
},
{ once: true },
),
);

await expect(
Expand Down
Loading