From f50da13d7a0db46031a52b4f86963d31f86a8efe Mon Sep 17 00:00:00 2001 From: ErikSin <67773827+ErikSin@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:05:28 -0700 Subject: [PATCH] test: load env variables so `npm test` works locally (#742) (#790) We [set environment variables in CI][0] so that `npm test` works, but it doesn't work locally because Jest isn't loading them. This loads them when running Jest. [0]: https://github.com/digidem/comapeo-mobile/blob/9b6cf8f71a0d960174c7e8cd5ce1b6bb8f1dd5a7/.github/workflows/ci.yml#L72-L75 Co-authored-by: Evan Hahn Co-authored-by: Gregor MacLennan --- package-lock.json | 25 +++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 747870eec..5b2bfc2d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -125,6 +125,7 @@ "babel-jest": "^29.6.3", "babel-plugin-transform-inline-environment-variables": "^0.4.4", "date-fns": "^3.6.0", + "dotenv-cli": "^7.4.2", "eslint": "^8.19.0", "eslint-config-prettier": "^9.1.0", "execa": "^8.0.1", @@ -12799,6 +12800,30 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-7.4.2.tgz", + "integrity": "sha512-SbUj8l61zIbzyhIbg0FwPJq6+wjbzdn9oEtozQpZ6kW2ihCcapKVZj49oCT3oPM+mgQm+itgvUQcG5szxVrZTA==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-cli/node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/dotenv-expand": { "version": "11.0.6", "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-11.0.6.tgz", diff --git a/package.json b/package.json index aaae80c60..8d5e185b9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "ios-no-backend-rebuild": "expo run:ios", "prestart": "npm run build:translations && npm run build:intl-polyfills", "start": "expo start", - "test": "jest", + "test": "dotenv jest", "lint:prettier": "prettier \"src/**/*.{js,ts,jsx,tsx}\" --check", "lint:eslint": "eslint . --ext .js,.jsx,.ts,.tsx --cache --ignore-path .gitignore", "lint:types": "tsc --noEmit", @@ -143,6 +143,7 @@ "babel-jest": "^29.6.3", "babel-plugin-transform-inline-environment-variables": "^0.4.4", "date-fns": "^3.6.0", + "dotenv-cli": "^7.4.2", "eslint": "^8.19.0", "eslint-config-prettier": "^9.1.0", "execa": "^8.0.1",