Skip to content

Commit a56739f

Browse files
author
Kristian Djaković
authored
Merge pull request #66 from infinum/recommended-type-checked
Recommended type checked
2 parents bb8faf3 + 8936a6d commit a56739f

Some content is hidden

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

41 files changed

+258
-61
lines changed

.eslintrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,14 @@
1212
],
1313
"parserOptions": {
1414
"project": ["./tsconfig.json"]
15-
}
15+
},
16+
"overrides": [
17+
{
18+
"files": ["*.ts", "*.tsx"],
19+
"extends": ["plugin:@typescript-eslint/recommended-requiring-type-checking"],
20+
"rules": {
21+
"@typescript-eslint/no-misused-promises": "off"
22+
}
23+
}
24+
]
1625
}

__mocks__/matchMedia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Object.defineProperty(window, 'matchMedia', {
22
writable: true,
3-
value: jest.fn().mockImplementation((query) => ({
3+
value: jest.fn().mockImplementation((query: string) => ({
44
matches: false,
55
media: query,
66
onchange: null,

__tests__/pages/_error.test.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import CustomErrorPage, { ICustomErrorPageProps } from '@/pages/_error';
2+
import { render, screen } from 'test-utils';
3+
import NextErrorComponent from 'next/error';
4+
import { axe } from 'jest-axe';
5+
import { NextPageContext } from 'next';
6+
import Bugsnag from '@bugsnag/js';
7+
8+
jest.mock('@bugsnag/js', () => ({ notify: jest.fn() }));
9+
10+
describe('CustomErrorPage', () => {
11+
it('should be accessible', async () => {
12+
const context = {} as NextPageContext;
13+
14+
const props = (await NextErrorComponent.getInitialProps(context)) as ICustomErrorPageProps;
15+
16+
const { container } = render(<CustomErrorPage {...props} />);
17+
18+
const results = await axe(container);
19+
20+
expect(results).toHaveNoViolations();
21+
});
22+
23+
it('should show heading and subheading', async () => {
24+
const context = {} as NextPageContext;
25+
26+
const props = (await NextErrorComponent.getInitialProps(context)) as ICustomErrorPageProps;
27+
28+
render(<CustomErrorPage {...props} />);
29+
30+
expect(screen.getByRole('heading', { name: /404/i })).toBeInTheDocument();
31+
expect(screen.getByRole('heading', { name: /Error occurred!/i })).toBeInTheDocument();
32+
expect(screen.getByRole('img', { name: /presentation/i })).toHaveAttribute(
33+
'src',
34+
'/images/infinum-contruction.png'
35+
);
36+
});
37+
38+
it('should notify Bugnsag', () => {
39+
const props = { statusCode: 404, hasGetInitialPropsRun: false, err: new Error('Does not exist') };
40+
41+
render(<CustomErrorPage {...props} />);
42+
43+
// eslint-disable-next-line @typescript-eslint/unbound-method
44+
expect(Bugsnag.notify).toHaveBeenCalled();
45+
});
46+
});

jest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { server } from '@/mocks/server';
77
import '@testing-library/jest-dom/extend-expect';
88
import 'jest-axe/extend-expect';
99

10+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
1011
jest.mock('next/router', () => require('next-router-mock'));
1112

1213
// In order to run `jest-axe` assertions for components containing

next.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ module.exports = {
2929
if (
3030
process.env.NEXT_PUBLIC_BUGSNAG_API_KEY &&
3131
process.env.NODE_ENV === 'production' &&
32-
process.env.NEXT_PUBLIC_NEXT_APP_ENV !== 'development'
32+
process.env.NEXT_PUBLIC_NEXT_APP_ENV !== 'development' &&
33+
process.env.SITE_URL
3334
) {
3435
config.plugins.push(
3536
new BugsnagBuildReporterPlugin(

package-lock.json

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "next build",
99
"postbuild": "next-sitemap",
1010
"start": "next start",
11-
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.d.ts",
11+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.d.ts --report-unused-disable-directives",
1212
"lint:next": "next lint",
1313
"test": "jest",
1414
"test:coverage": "jest --coverage",
@@ -34,6 +34,7 @@
3434
"@chakra-ui/utils": "~2.0.15",
3535
"@datx/core": "~3.0.0",
3636
"@datx/jsonapi": "~3.0.0",
37+
"@datx/jsonapi-types": "~3.0.0",
3738
"@datx/swr": "~3.0.0",
3839
"@emotion/react": "~11.11.0",
3940
"@emotion/styled": "~11.11.0",
@@ -104,8 +105,8 @@
104105
"lint-staged": "~13.2.1",
105106
"msw": "~1.2.2",
106107
"msw-storybook-addon": "~1.8.0",
107-
"node-fetch": "~2.6.12",
108108
"next-router-mock": "~0.9.7",
109+
"node-fetch": "~2.6.12",
109110
"plop": "~3.1.2",
110111
"prettier": "~2.8.7",
111112
"react-intersection-observer": "~9.5.2",

scripts/i18next-cli.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ declare module 'i18next' {
4242

4343
fs.readdir(readPath, (err, files) => {
4444
if (err) {
45-
return console.log(`Unable to scan directory: ${err}`);
45+
console.log(`Unable to scan directory: ${err}`);
46+
47+
return;
4648
}
4749

4850
const names = files.map((file) => getNameData(file.replace('.json', '')));
4951
const template = generate(names);
5052

5153
fs.writeFile(savePath, template, (err) => {
5254
if (err) {
53-
return console.log(`Unable to save: ${err}`);
55+
console.log(`Unable to save: ${err}`);
56+
57+
return;
5458
}
5559

5660
console.log('The file was saved!');

scripts/test-utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import theme from '@/styles/theme';
1212
import { MockedRequest, matchRequestUrl } from 'msw';
1313
import common from '../public/locales/en-US/common.json';
1414

15+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1516
i18n.use(initReactI18next).init({
1617
lng: 'en-US',
1718
fallbackLng: 'en-US',

src/components/shared/auth/LoginForm/LoginForm.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('LoginForm', () => {
6262
it('should not display error when value is valid', async () => {
6363
server.use(
6464
rest.post(MOCKED_URLS.Session, async (req, res, ctx) => {
65-
const body = await req.json();
65+
const body = await req.json<{ data?: { attributes?: { email?: string } } }>();
6666
const emailOverride = body.data?.attributes?.email || undefined;
6767

6868
return res(

0 commit comments

Comments
 (0)