From f203f821365160c50a6cb49b6e3384b3a6c1225a Mon Sep 17 00:00:00 2001 From: Jan Nanista Date: Fri, 8 Dec 2023 13:59:55 -0800 Subject: [PATCH] chore: Use jest in create-lz-oapp --- packages/create-lz-oapp/.mocharc.json | 5 -- packages/create-lz-oapp/jest.config.cjs | 17 ++++++ packages/create-lz-oapp/package.json | 8 +-- .../test/utilities/cloning.test.ts | 24 ++++---- packages/create-lz-oapp/tsconfig.json | 2 +- packages/create-lz-oapp/tsconfig.test.json | 7 +++ packages/utils-evm-test/package.json | 2 +- yarn.lock | 56 +------------------ 8 files changed, 42 insertions(+), 79 deletions(-) delete mode 100644 packages/create-lz-oapp/.mocharc.json create mode 100644 packages/create-lz-oapp/jest.config.cjs create mode 100644 packages/create-lz-oapp/tsconfig.test.json diff --git a/packages/create-lz-oapp/.mocharc.json b/packages/create-lz-oapp/.mocharc.json deleted file mode 100644 index 4ddf3f6e5..000000000 --- a/packages/create-lz-oapp/.mocharc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extensions": ["ts"], - "spec": ["**/*.test.*"], - "loader": "ts-node/esm" -} diff --git a/packages/create-lz-oapp/jest.config.cjs b/packages/create-lz-oapp/jest.config.cjs new file mode 100644 index 000000000..efe80e021 --- /dev/null +++ b/packages/create-lz-oapp/jest.config.cjs @@ -0,0 +1,17 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: "ts-jest", + testEnvironment: "node", + testTimeout: 15000, + moduleNameMapper: { + "^@/(.*)\\.js$": "/src/$1", + }, + transform: { + // ts-jest does not yet work great with node16 module resolution + // so we need to help it a little + // + // See https://github.com/kulshekhar/ts-jest/issues/4207 for the issue + // And https://github.com/kulshekhar/ts-jest/issues/4198 for another one + "^.+\\.tsx?$": ["ts-jest", { tsconfig: "tsconfig.test.json" }], + }, +}; diff --git a/packages/create-lz-oapp/package.json b/packages/create-lz-oapp/package.json index ea46d038d..99280c43d 100644 --- a/packages/create-lz-oapp/package.json +++ b/packages/create-lz-oapp/package.json @@ -27,7 +27,7 @@ "dev": "npx tsup --watch", "lint": "npx eslint '**/*.{js,ts,json}'", "start": "./cli.cjs", - "test": "mocha --parallel" + "test": "jest --config jest.config.cjs" }, "dependencies": { "yoga-wasm-web": "~0.3.3" @@ -35,11 +35,10 @@ "devDependencies": { "@layerzerolabs/io-utils": "~0.0.1", "@tanstack/react-query": "^5.8.4", - "@types/mocha": "^10.0.6", + "@types/jest": "^29.5.10", "@types/prompts": "^2.4.9", "@types/react": "^18.2.38", "@types/which": "~3.0.3", - "chai": "^4.3.10", "commander": "^11.1.0", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", @@ -48,11 +47,12 @@ "ink-select-input": "^5.0.0", "ink-spinner": "^5.0.0", "ink-text-input": "^5.0.1", - "mocha": "^10.0.0", + "jest": "^29.7.0", "prompts": "^2.4.2", "react": "^18.2.0", "react-devtools-core": "^4.28.5", "tiged": "^2.12.5", + "ts-jest": "^29.1.1", "ts-node": "^10.9.1", "typescript": "^5.2.2", "which": "~4.0.0" diff --git a/packages/create-lz-oapp/test/utilities/cloning.test.ts b/packages/create-lz-oapp/test/utilities/cloning.test.ts index 428b99fcc..71459e1f2 100644 --- a/packages/create-lz-oapp/test/utilities/cloning.test.ts +++ b/packages/create-lz-oapp/test/utilities/cloning.test.ts @@ -1,31 +1,29 @@ -import { expect } from 'chai' -import { describe, it } from 'mocha' -import { createExampleGitURL } from '../../src/utilities/cloning.js' +import { createExampleGitURL } from '@/utilities/cloning.js' describe('utilities/cloning', () => { describe('createExampleGitURL', () => { const REPO_URL = 'git@github.com:LayerZero-Labs/lz-utils' it('should return the repository field if directory and ref are not specified', () => { - expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).to.eql(REPO_URL) + expect(createExampleGitURL({ repository: REPO_URL, id: 'dummy', label: 'Dummy' })).toEqual(REPO_URL) }) it('should return the repository field with directory if directory is specified', () => { - expect(createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' })).to.eql( - `${REPO_URL}/dir` - ) + expect( + createExampleGitURL({ repository: REPO_URL, directory: 'dir', id: 'dummy', label: 'Dummy' }) + ).toEqual(`${REPO_URL}/dir`) expect( createExampleGitURL({ repository: REPO_URL, directory: '/dir', id: 'dummy', label: 'Dummy' }) - ).to.eql(`${REPO_URL}/dir`) + ).toEqual(`${REPO_URL}/dir`) expect( createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: '', id: 'dummy', label: 'Dummy' }) - ).to.eql(`${REPO_URL}/dir`) + ).toEqual(`${REPO_URL}/dir`) }) it('should return the repository field with directory and ref if directory and ref are specified', () => { expect( createExampleGitURL({ repository: REPO_URL, directory: 'dir', ref: 'ref', id: 'dummy', label: 'Dummy' }) - ).to.eql(`${REPO_URL}/dir#ref`) + ).toEqual(`${REPO_URL}/dir#ref`) expect( createExampleGitURL({ repository: REPO_URL, @@ -34,14 +32,14 @@ describe('utilities/cloning', () => { id: 'dummy', label: 'Dummy', }) - ).to.eql(`${REPO_URL}/dir#ref`) + ).toEqual(`${REPO_URL}/dir#ref`) }) it('should return the repository field with ref if only ref specified', () => { - expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).to.eql( + expect(createExampleGitURL({ repository: REPO_URL, ref: 'ref', id: 'dummy', label: 'Dummy' })).toEqual( `${REPO_URL}#ref` ) - expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).to.eql( + expect(createExampleGitURL({ repository: REPO_URL, ref: '#ref', id: 'dummy', label: 'Dummy' })).toEqual( `${REPO_URL}#ref` ) }) diff --git a/packages/create-lz-oapp/tsconfig.json b/packages/create-lz-oapp/tsconfig.json index 77a5670af..fb99fcf26 100644 --- a/packages/create-lz-oapp/tsconfig.json +++ b/packages/create-lz-oapp/tsconfig.json @@ -10,7 +10,7 @@ "lib": ["dom", "dom.Iterable", "es2022"], "resolveJsonModule": false, "target": "esnext", - "types": ["mocha", "node"], + "types": ["jest", "node"], "paths": { "@/*": ["./src/*"] } diff --git a/packages/create-lz-oapp/tsconfig.test.json b/packages/create-lz-oapp/tsconfig.test.json new file mode 100644 index 000000000..c17742ae6 --- /dev/null +++ b/packages/create-lz-oapp/tsconfig.test.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "moduleResolution": "Node10" + } +} diff --git a/packages/utils-evm-test/package.json b/packages/utils-evm-test/package.json index bdbc5b3dd..843c20943 100644 --- a/packages/utils-evm-test/package.json +++ b/packages/utils-evm-test/package.json @@ -12,7 +12,7 @@ "scripts": { "lint": "npx eslint '**/*.{js,ts,json}'", "pretest": "npx hardhat compile", - "test": "jest --pasWithNoTests" + "test": "jest --passWithNoTests" }, "devDependencies": { "@ethersproject/abi": "^5.7.0", diff --git a/yarn.lock b/yarn.lock index 069b74224..0d0beb1e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2731,11 +2731,6 @@ resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz" integrity sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag== -"@types/mocha@^10.0.6": - version "10.0.6" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.6.tgz#818551d39113081048bdddbef96701b4e8bb9d1b" - integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg== - "@types/mute-stream@^0.0.4": version "0.0.4" resolved "https://registry.yarnpkg.com/@types/mute-stream/-/mute-stream-0.0.4.tgz#77208e56a08767af6c5e1237be8888e2f255c478" @@ -3424,11 +3419,6 @@ assert-plus@1.0.0, assert-plus@^1.0.0: resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" integrity sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw== -assertion-error@^1.1.0: - version "1.1.0" - resolved "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz" - integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== - ast-parents@^0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/ast-parents/-/ast-parents-0.0.1.tgz#508fd0f05d0c48775d9eccda2e174423261e8dd3" @@ -4067,19 +4057,6 @@ catering@^2.1.0, catering@^2.1.1: resolved "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz" integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w== -chai@^4.3.10: - version "4.3.10" - resolved "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz" - integrity sha512-0UXG04VuVbruMUYbJ6JctvH0YnC/4q3/AkT18q4NaITo91CUm0liMS9VqzT9vZhVQ/1eqPanMWjBM+Juhfb/9g== - dependencies: - assertion-error "^1.1.0" - check-error "^1.0.3" - deep-eql "^4.1.3" - get-func-name "^2.0.2" - loupe "^2.3.6" - pathval "^1.1.1" - type-detect "^4.0.8" - chalk@5.3.0, chalk@^5.2.0: version "5.3.0" resolved "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz" @@ -4112,13 +4089,6 @@ chardet@^0.7.0: resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== -check-error@^1.0.3: - version "1.0.3" - resolved "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz" - integrity sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg== - dependencies: - get-func-name "^2.0.2" - checkpoint-store@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/checkpoint-store/-/checkpoint-store-1.1.0.tgz#04e4cb516b91433893581e6d4601a78e9552ea06" @@ -4734,13 +4704,6 @@ dedent@^1.0.0: resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.5.1.tgz#4f3fc94c8b711e9bb2800d185cd6ad20f2a90aff" integrity sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg== -deep-eql@^4.1.3: - version "4.1.3" - resolved "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz" - integrity sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw== - dependencies: - type-detect "^4.0.0" - deep-extend@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" @@ -6467,11 +6430,6 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-func-name@^2.0.1, get-func-name@^2.0.2: - version "2.0.2" - resolved "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz" - integrity sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ== - get-intrinsic@^1.0.2, get-intrinsic@^1.1.3: version "1.2.1" resolved "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz" @@ -8551,13 +8509,6 @@ loose-envify@^1.1.0, loose-envify@^1.4.0: dependencies: js-tokens "^3.0.0 || ^4.0.0" -loupe@^2.3.6: - version "2.3.7" - resolved "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz" - integrity sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA== - dependencies: - get-func-name "^2.0.1" - lowercase-keys@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" @@ -9579,11 +9530,6 @@ path-type@^4.0.0: resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -pathval@^1.1.1: - version "1.1.1" - resolved "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz" - integrity sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ== - pbkdf2@^3.0.17: version "3.1.2" resolved "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz" @@ -11428,7 +11374,7 @@ type-check@^0.4.0, type-check@~0.4.0: dependencies: prelude-ls "^1.2.1" -type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.8: +type-detect@4.0.8, type-detect@^4.0.8: version "4.0.8" resolved "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==