Skip to content

Commit 31d678d

Browse files
authored
Update to next.js and typescript (#152)
1 parent b9c084d commit 31d678d

File tree

176 files changed

+34383
-37545
lines changed

Some content is hidden

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

176 files changed

+34383
-37545
lines changed

.codecov.yml

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

.github/workflows/node.js.yml

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

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

1212
jobs:
1313
build:
@@ -16,15 +16,17 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [14.x, 16.x, 18.x]
19+
node-version: [24.x]
2020

2121
steps:
22-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v6
2323
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v2
24+
uses: actions/setup-node@v6
2525
with:
2626
node-version: ${{ matrix.node-version }}
2727
cache: npm
2828
- run: npm ci
2929
- run: npm test -- --silent --coverage --coverageReporters text lcov
30-
- run: bash <(curl -s https://codecov.io/bash)
30+
- run: npm run lint
31+
- run: npm run build
32+

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ test_examples/
2828
!.yarn/plugins
2929
!.yarn/sdks
3030
!.yarn/versions
31-
.pnp.*
31+
.pnp.*
32+
33+
.next/
34+
*.tsbuildinfo
35+
next-env.d.ts
36+
.claude/settings.local.json

.nvmrc

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

__tests__/currencies.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import axios from 'axios';
4+
import MockAdapter from 'axios-mock-adapter';
5+
import { GET } from '../src/app/api/currencies/route';
6+
import { NextRequest } from 'next/server';
7+
8+
const daily = fs.readFileSync(path.join(__dirname, './daily.zip'));
9+
10+
describe('currencies API', () => {
11+
let mock: MockAdapter;
12+
13+
beforeEach(() => {
14+
mock = new MockAdapter(axios);
15+
mock.onGet(/.*eurofxref\.zip$/).reply(200, daily);
16+
});
17+
18+
afterEach(() => mock.restore());
19+
20+
it('should return supported currencies', async () => {
21+
const request = new NextRequest('http://localhost:3000/api/currencies');
22+
const response = await GET(request);
23+
const currencies = await response.json();
24+
25+
expect(response.status).toBe(200);
26+
expect(currencies).toEqual(['USD', 'JPY']);
27+
});
28+
});
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import fs from 'fs';
22
import path from 'path';
33
import axios from 'axios';
44
import MockAdapter from 'axios-mock-adapter';
5-
import { handler } from '../currencyRates';
5+
import { GET } from '../src/app/api/currencyRates/route';
6+
import { NextRequest } from 'next/server';
67

78
const daily = fs.readFileSync(path.join(__dirname, './daily.zip'));
89
const historical = fs.readFileSync(path.join(__dirname, './hist.zip'));
910

10-
describe('currencyRates', () => {
11-
let mock;
11+
describe('currencyRates API', () => {
12+
let mock: MockAdapter;
13+
1214
beforeEach(() => {
1315
mock = new MockAdapter(axios);
1416
mock.onGet(/.*eurofxref\.zip$/).reply(200, daily);
@@ -18,8 +20,11 @@ describe('currencyRates', () => {
1820
afterEach(() => mock.restore());
1921

2022
it('should return daily rates', async () => {
21-
const res = await handler();
22-
const rates = {
23+
const request = new NextRequest('http://localhost:3000/api/currencyRates');
24+
const response = await GET(request);
25+
const rates = await response.json();
26+
27+
const expectedRates = {
2328
'2018-09-17': {
2429
USD: 1.1691,
2530
JPY: 130.77
@@ -34,19 +39,16 @@ describe('currencyRates', () => {
3439
}
3540
};
3641

37-
expect(res).toEqual({
38-
statusCode: 200,
39-
body: JSON.stringify(rates)
40-
});
42+
expect(response.status).toBe(200);
43+
expect(rates).toEqual(expectedRates);
4144
});
4245

4346
it('should return specific currencies', async () => {
44-
const res = await handler({
45-
queryStringParameters: {
46-
currencies: ['USD']
47-
}
48-
});
49-
const rates = {
47+
const request = new NextRequest('http://localhost:3000/api/currencyRates?currencies=USD');
48+
const response = await GET(request);
49+
const rates = await response.json();
50+
51+
const expectedRates = {
5052
'2018-09-17': {
5153
USD: 1.1691
5254
},
@@ -58,9 +60,7 @@ describe('currencyRates', () => {
5860
}
5961
};
6062

61-
expect(res).toEqual({
62-
statusCode: 200,
63-
body: JSON.stringify(rates)
64-
});
63+
expect(response.status).toBe(200);
64+
expect(rates).toEqual(expectedRates);
6565
});
66-
});
66+
});

eslint.config.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig, globalIgnores } from "eslint/config";
2+
import nextVitals from "eslint-config-next/core-web-vitals";
3+
import nextTs from "eslint-config-next/typescript";
4+
5+
const eslintConfig = defineConfig([
6+
...nextVitals,
7+
...nextTs,
8+
// Override default ignores of eslint-config-next.
9+
globalIgnores([
10+
// Default ignores of eslint-config-next:
11+
".next/**",
12+
"out/**",
13+
"build/**",
14+
"next-env.d.ts",
15+
]),
16+
]);
17+
18+
export default eslintConfig;

jest.config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Config } from 'jest'
2+
import nextJest from 'next/jest.js'
3+
import { createRequire } from 'module'
4+
5+
const require = createRequire(import.meta.url)
6+
7+
const createJestConfig = nextJest({
8+
dir: './',
9+
})
10+
11+
const config: Config = {
12+
coverageProvider: 'v8',
13+
testEnvironment: 'jsdom',
14+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
15+
moduleNameMapper: {
16+
'^@/(.*)$': '<rootDir>/src/$1',
17+
'^uuid$': require.resolve('uuid'),
18+
},
19+
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
20+
transformIgnorePatterns: [
21+
'node_modules/(?!(uuid|d3-array|d3-scale-chromatic|react-dates)/)',
22+
],
23+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
24+
globals: {
25+
'ts-jest': {
26+
useESM: true,
27+
},
28+
},
29+
}
30+
31+
export default createJestConfig(config)

0 commit comments

Comments
 (0)