From 6ba589fa9b8cf7e5754d6f9a9f95a7da61bd9486 Mon Sep 17 00:00:00 2001 From: Daniel Kamar Date: Sun, 17 Dec 2023 16:15:46 +0000 Subject: [PATCH 01/13] Update package deps --- .github/workflows/build-test.yml | 2 +- package-lock.json | 81 +++++++++++++++++++++++++++++++- package.json | 12 +++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a275bf5..2652d2d 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -30,7 +30,7 @@ jobs: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - run: rm -rf node_modules package-lock.json # - run: npm cache clean --force - - run: npm install + # - run: npm install - run: npm ci - run: npm run build --if-present - run: npm test \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e40ddaa..af19d44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@reduxjs/toolkit": "^1.9.7", "@vercel/analytics": "1.1.1", "antd": "5.11.3", - "babel-plugin-import": "^1.13.8", "cors": "^2.8.5", "dotenv": "16.3.1", "firebase": "^10.6.0", @@ -49,6 +48,7 @@ "jest-styled-components": "7.2.0", "postcss": "^8", "tailwindcss": "^3.3.5", + "ts-jest": "^29.1.1", "typescript": "^5" } }, @@ -3769,6 +3769,18 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -7459,6 +7471,12 @@ "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -7517,6 +7535,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -10303,6 +10327,61 @@ "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==", "dev": true }, + "node_modules/ts-jest": { + "version": "29.1.1", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", + "integrity": "sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "^7.5.3", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", diff --git a/package.json b/package.json index c7a5ac3..9bc9a57 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,17 @@ "test": "jest --watchAll", "test:ci": "jest --ci" }, + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ]}, "dependencies": { "@ant-design/cssinjs": "^1.18.1", "@ant-design/icons": "5.2.6", @@ -51,6 +62,7 @@ "jest-styled-components": "7.2.0", "postcss": "^8", "tailwindcss": "^3.3.5", + "ts-jest": "^29.1.1", "typescript": "^5" } } From 6ea1c589871e2509923b6a4c0ba0800e91170c43 Mon Sep 17 00:00:00 2001 From: Daniel Kamar Date: Sun, 17 Dec 2023 16:17:20 +0000 Subject: [PATCH 02/13] fix(actions): for npm ci --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2652d2d..a275bf5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -30,7 +30,7 @@ jobs: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - run: rm -rf node_modules package-lock.json # - run: npm cache clean --force - # - run: npm install + - run: npm install - run: npm ci - run: npm run build --if-present - run: npm test \ No newline at end of file From 336ac21d96391b0453aecf1f5f222c520f418e71 Mon Sep 17 00:00:00 2001 From: Daniel Kamar Date: Sun, 17 Dec 2023 16:19:54 +0000 Subject: [PATCH 03/13] fix(github-actions): no cache --- .github/workflows/build-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index a275bf5..2cd44ec 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -28,9 +28,9 @@ jobs: key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} restore-keys: | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - - run: rm -rf node_modules package-lock.json + # - run: rm -rf node_modules package-lock.json # - run: npm cache clean --force - - run: npm install + # - run: npm install - run: npm ci - run: npm run build --if-present - run: npm test \ No newline at end of file From ac9b698e92c06de17f3a41b009dbd122e850af25 Mon Sep 17 00:00:00 2001 From: Daniel Kamar Date: Sun, 17 Dec 2023 17:03:54 +0000 Subject: [PATCH 04/13] Update jest.config.js --- jest.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index a4e1c62..0c9fc31 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,8 @@ module.exports = { '!/node_modules/', ], - testEnvironment: 'jsdom', + preset: 'ts-jest', + testEnvironment: 'node', testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], testPathIgnorePatterns: ['/node_modules/', '/.next/', '/.out/', '/public/'], From 281e8d4625f0826a6ea0cb06794013c48b2c22dc Mon Sep 17 00:00:00 2001 From: Daniel Kamar Date: Sun, 17 Dec 2023 21:18:07 +0000 Subject: [PATCH 05/13] fix(tests): jest configs run --- .jest/setupTests.ts | 6 + .../layout/__snapshots__/Header.test.tsx.snap | 8 +- __tests__/components/navbar/Menu.test.tsx | 33 +- .../__snapshots__/Hamburger.test.tsx.snap | 22 +- .../navbar/__snapshots__/Menu.test.tsx.snap | 3 +- jest.config.js | 30 +- package-lock.json | 563 +++++++++++++++++- package.json | 22 +- tsconfig.json | 3 +- 9 files changed, 637 insertions(+), 53 deletions(-) create mode 100644 .jest/setupTests.ts diff --git a/.jest/setupTests.ts b/.jest/setupTests.ts new file mode 100644 index 0000000..2b6a998 --- /dev/null +++ b/.jest/setupTests.ts @@ -0,0 +1,6 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; +// import '@testing-library/jest-dom/extend-expect'; \ No newline at end of file diff --git a/__tests__/components/layout/__snapshots__/Header.test.tsx.snap b/__tests__/components/layout/__snapshots__/Header.test.tsx.snap index 4685e11..fce96f6 100644 --- a/__tests__/components/layout/__snapshots__/Header.test.tsx.snap +++ b/__tests__/components/layout/__snapshots__/Header.test.tsx.snap @@ -146,16 +146,16 @@ exports[`Header check the snapshot 1`] = ` class="ant-col ant-col-xs-4 ant-col-xs-offset-20 ant-col-sm-3 ant-col-sm-offset-21 ant-col-md-0" >
diff --git a/__tests__/components/navbar/Menu.test.tsx b/__tests__/components/navbar/Menu.test.tsx index 0bc01e2..8ddfdb9 100644 --- a/__tests__/components/navbar/Menu.test.tsx +++ b/__tests__/components/navbar/Menu.test.tsx @@ -1,4 +1,5 @@ -import { render } from '@testing-library/react'; +// import { render } from '@testing-library/react'; +import { fireEvent, render, screen } from "@testing-library/react"; import Menu from '../../../components/navbar/menu'; import { MenuItems } from '../../../components/navbar/menu'; @@ -8,16 +9,32 @@ describe('Menu', () => { const mode = 'horizontal'; const onClick = jest.fn(); const selectedKeys = ['home']; + // const items: MenuItems = { + // leftMenu: [ + // { key: 'home', text: 'Home', path: '/' }, + // { key: 'about', text: 'About', path: '/about' } + // ], + // rightMenu: [ + // { key: 'register', text: 'Register', path: '/register' }, + // { key: 'sign-in', text: 'Sign In', path: '/sign-in' } + // ] + // }; + const items: MenuItems = { leftMenu: [ - { key: 'home', text: 'Home', path: '/' }, - { key: 'about', text: 'About', path: '/about' } - ], - rightMenu: [ - { key: 'register', text: 'Register', path: '/register' }, - { key: 'sign-in', text: 'Sign In', path: '/sign-in' } - ] + { key: 'home', text: 'Home', path: '/' }, + { key: 'about', text: 'About', path: '/about' } + ], + rightMenu: [ + { key: 'register', text: 'Register', path: '/register' }, + { key: 'sign-in', text: 'Sign In', path: '/sign-in' } + ], + length: 2, // Update length based on menu items + pop: () => ({ key: 'removed', text: 'Removed', path: '' }), // Implement or mock function + push: (menuItem) => { /* Implement or mock function */ return 3; }, // Update return value + concat: (menuItems) => ({ ...items, leftMenu: [...items.leftMenu, ...menuItems] }), // Implement or mock function }; + const { asFragment } = render(
-
-
-
+ class="sc-bdfCDU gcCQLz" + > +
+
+
`; diff --git a/__tests__/components/navbar/__snapshots__/Menu.test.tsx.snap b/__tests__/components/navbar/__snapshots__/Menu.test.tsx.snap index bf9f76d..451e4cb 100644 --- a/__tests__/components/navbar/__snapshots__/Menu.test.tsx.snap +++ b/__tests__/components/navbar/__snapshots__/Menu.test.tsx.snap @@ -3,8 +3,7 @@ exports[`Menu check the snapshot 1`] = `