From 7776e640beea235c491058a3fd2efea9080bbc67 Mon Sep 17 00:00:00 2001 From: 1emu Date: Wed, 17 Apr 2024 11:50:49 -0300 Subject: [PATCH] chore: add jest config & setup to mock envs --- babel.config.js | 3 +++ jest.setup.ts | 7 +++++++ package-lock.json | 4 ++++ package.json | 14 +++++++++++++- src/clients/Governance.ts | 3 ++- src/constants/heroku.ts | 1 + tsconfig.json | 2 +- 7 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 babel.config.js create mode 100644 jest.setup.ts create mode 100644 src/constants/heroku.ts diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..9b00636 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ['@babel/preset-env', '@babel/preset-typescript'], +} diff --git a/jest.setup.ts b/jest.setup.ts new file mode 100644 index 0000000..82184fc --- /dev/null +++ b/jest.setup.ts @@ -0,0 +1,7 @@ +jest.mock('./src/constants/heroku', () => ({ + HEROKU_APP_NAME: 'test', +})) +jest.mock('./src/constants/grants', () => ({ + GRANT_VP_THRESHOLD: null, + MAX_LOWER_TIER_GRANT_FUNDING: 20000, +})) diff --git a/package-lock.json b/package-lock.json index c9fa8c5..27e5b5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,9 @@ "zod": "^3.22.4" }, "devDependencies": { + "@babel/core": "^7.24.4", + "@babel/preset-env": "^7.24.4", + "@babel/preset-typescript": "^7.24.1", "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@esbuild-plugins/node-modules-polyfill": "^0.2.2", "@storybook/addon-essentials": "^7.4.0", @@ -85,6 +88,7 @@ "@typescript-eslint/parser": "^6.11.0", "@vitejs/plugin-basic-ssl": "^1.0.2", "@vitejs/plugin-react-swc": "^3.3.2", + "babel-jest": "^29.7.0", "concurrently": "^6.0.0", "dotenv": "^16.3.1", "eslint": "^8.15.0", diff --git a/package.json b/package.json index b580c24..24d36be 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,14 @@ "storybook": "storybook dev -p 6006", "build-storybook": "storybook build" }, + "jest": { + "watchman": false, + "setupFilesAfterEnv": ["/jest.setup.ts"], + "roots": [ + "/src/" + ], + "testEnvironment": "node" + }, "repository": { "type": "git", "url": "git+https://github.com/decentraland/governance-ui.git" @@ -67,6 +75,9 @@ "zod": "^3.22.4" }, "devDependencies": { + "@babel/core": "^7.24.4", + "@babel/preset-env": "^7.24.4", + "@babel/preset-typescript": "^7.24.1", "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@esbuild-plugins/node-modules-polyfill": "^0.2.2", "@storybook/addon-essentials": "^7.4.0", @@ -98,6 +109,7 @@ "@typescript-eslint/parser": "^6.11.0", "@vitejs/plugin-basic-ssl": "^1.0.2", "@vitejs/plugin-react-swc": "^3.3.2", + "babel-jest": "^29.7.0", "concurrently": "^6.0.0", "dotenv": "^16.3.1", "eslint": "^8.15.0", @@ -129,4 +141,4 @@ "*.{js,jsx,ts,tsx}": "eslint --cache --fix", "*.{js,jsx,ts,tsx,css,json}": "prettier --write" } -} \ No newline at end of file +} diff --git a/src/clients/Governance.ts b/src/clients/Governance.ts index 1fa5b69..92da86f 100644 --- a/src/clients/Governance.ts +++ b/src/clients/Governance.ts @@ -2,6 +2,7 @@ import snakeCase from 'lodash/snakeCase' import { SpecState } from '../components/Debug/UploadBadgeSpec' import { GOVERNANCE_API } from '../constants' +import { HEROKU_APP_NAME } from '../constants/heroku' import { DetailedScores, SnapshotConfig, @@ -98,7 +99,7 @@ export type GetProposalsFilter = ProposalListFilter & { } const getGovernanceApiUrl = () => { - if (import.meta.env.VITE_HEROKU_APP_NAME) { + if (HEROKU_APP_NAME) { return `https://governance.decentraland.vote/api` } diff --git a/src/constants/heroku.ts b/src/constants/heroku.ts new file mode 100644 index 0000000..f419883 --- /dev/null +++ b/src/constants/heroku.ts @@ -0,0 +1 @@ +export const HEROKU_APP_NAME = import.meta.env.VITE_HEROKU_APP_NAME diff --git a/tsconfig.json b/tsconfig.json index 3c74aa8..bc939e8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,7 @@ "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src", "vite.config.ts", "scripts"], + "include": ["src", "vite.config.ts", "scripts", "babel.config.js", "jest.setup.ts"], "exclude": ["node_modules", "**/node_modules/*"], "references": [{ "path": "./tsconfig.node.json" }] }