From f6eb6b27a2e8a4f75bdd68eea2c238155e085cf8 Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Mon, 13 Apr 2026 09:37:51 +0700 Subject: [PATCH 1/2] test(e2e): load secret from env --- .env.example | 4 ++++ .gitignore | 1 + README.md | 21 ++++++++++++++++++++- ava-e2e.config.mjs | 12 +++++++----- package.json | 15 ++++++++------- yarn.lock | 5 +++++ 6 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..8d43f854 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +API_ENDPOINT=your.api.endpoint +SCHEME=https +CLIENT_API_KEY=your-client-key +SERVER_API_KEY=your-server-key \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3be354b2..7900b789 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __test __e2e lib .vscode/launch.json +.env diff --git a/README.md b/README.md index 8ff36413..e6d46f9b 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,28 @@ make build make test ``` + #### Run e2e tests -Configure the `apiEndpoint` (with URL scheme) and the `apiKey` info in the [ava-e2e.config.mjs](./ava-e2e.config.mjs), then run the following command. +Set the required secrets for E2E tests using environment variables or a `.env` file in the project root. The following variables are required: + +- `API_ENDPOINT` (e.g. api.example.com, without scheme) +- `SCHEME` (e.g. https or http, defaults to https) +- `CLIENT_API_KEY` (Client SDK role API key) +- `SERVER_API_KEY` (Server SDK role API key for testing with local evaluate) + +You can create a `.env` file in the project root for local development: + +``` +API_ENDPOINT=your.api.endpoint +SCHEME=https +CLIENT_API_KEY=your-client-key +SERVER_API_KEY=your-server-key +``` + +The E2E test config will automatically load these values. + +Then run: ```bash make e2e diff --git a/ava-e2e.config.mjs b/ava-e2e.config.mjs index 4883ab75..3b0810be 100644 --- a/ava-e2e.config.mjs +++ b/ava-e2e.config.mjs @@ -1,3 +1,5 @@ +import 'dotenv/config'; // Loads .env file into process.env + export default { babel: { testOptions: { @@ -10,9 +12,9 @@ export default { '__e2e/__test__/local_evaluation/*.js' ], environmentVariables: { - API_ENDPOINT: '', // replace this. e.g. api.example.com (without scheme) - SCHEME: '', // replace this. e.g. https or http (defaults to https) - CLIENT_API_KEY: '', // replace this. Client SDK role API key - SERVER_API_KEY: '', // replace this. Server SDK role API key for testing with local evaluate + API_ENDPOINT: process.env.API_ENDPOINT || '', // e.g. api.example.com (without scheme) + SCHEME: process.env.SCHEME || '', // e.g. https or http (defaults to https) + CLIENT_API_KEY: process.env.CLIENT_API_KEY || '', // Client SDK role API key + SERVER_API_KEY: process.env.SERVER_API_KEY || '', // Server SDK role API key for testing with local evaluate }, -}; +}; \ No newline at end of file diff --git a/package.json b/package.json index 0d22ddab..7d1ed9a2 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,11 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "dependencies": { - "uuid": "^11.1.0", "@bucketeer/evaluation": "0.0.7", "@improbable-eng/grpc-web": "^0.15.0", "@improbable-eng/grpc-web-node-http-transport": "^0.15.0", - "google-protobuf": "^3.21.4" + "google-protobuf": "^3.21.4", + "uuid": "^11.1.0" }, "devDependencies": { "@ava/babel": "2.0.0", @@ -30,13 +30,15 @@ "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-replace": "^6.0.3", "@types/eslint": "^9.6.1", + "@types/node": "^22.15.35", "@types/node-fetch": "2.6.13", + "@types/sinon": "^17.0.4", + "@types/uuid": "^10.0.0", "@typescript-eslint/eslint-plugin": "^8.46.3", "@typescript-eslint/parser": "^8.46.3", "ava": "6.4.1", - "@types/sinon": "^17.0.4", - "sinon": "^21.0.0", "cpx": "1.5.0", + "dotenv": "^17.4.2", "eslint": "^9.34.0", "eslint-config-prettier": "10.1.8", "eslint-plugin-prettier": "5.5.5", @@ -47,11 +49,10 @@ "replace": "1.2.2", "rollup": "^4.50.2", "semver": "7.7.4", + "sinon": "^21.0.0", "terser": "5.46.2", "typescript": "^5.8.3", "typescript-eslint": "^8.41.0", - "uglify-es": "3.3.9", - "@types/node": "^22.15.35", - "@types/uuid": "^10.0.0" + "uglify-es": "3.3.9" } } diff --git a/yarn.lock b/yarn.lock index 0292b10d..e6b0393b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3004,6 +3004,11 @@ dot-prop@^6.0.1: dependencies: is-obj "^2.0.0" +dotenv@^17.4.2: + version "17.4.2" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-17.4.2.tgz#c07e54a746e11eba021dd9e1047ced5afdc1c034" + integrity sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw== + dunder-proto@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz" From 8feb8315af9f11a8f472c376f83740c846a748ad Mon Sep 17 00:00:00 2001 From: duyhungtnn Date: Mon, 13 Apr 2026 10:15:48 +0700 Subject: [PATCH 2/2] chore: remove duplicate load env sections --- .github/workflows/e2e.yml | 17 ++++------------- README.md | 4 ++-- ava-e2e.config.mjs | 6 ------ 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 00061a2f..6a879937 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -47,17 +47,8 @@ jobs: run: make build - name: e2e test run: | - API_ENDPOINT="${{ secrets.E2E_API_ENDPOINT }}" - SCHEME="${{ secrets.E2E_SCHEME }}" - if [ -z "$SCHEME" ]; then - SCHEME="https" - fi - CLIENT_API_KEY="${{ secrets.E2E_CLIENT_API_KEY }}" - SERVER_API_KEY="${{ secrets.E2E_SERVER_API_KEY }}" - - sed -i -e "s||${API_ENDPOINT}|" \ - -e "s||${SCHEME}|" \ - -e "s||${CLIENT_API_KEY}|" \ - -e "s||${SERVER_API_KEY}|" \ - ava-e2e.config.mjs + echo "API_ENDPOINT=${{ secrets.E2E_API_ENDPOINT }}" > .env + echo "SCHEME=${{ secrets.E2E_SCHEME || 'https' }}" >> .env + echo "CLIENT_API_KEY=${{ secrets.E2E_CLIENT_API_KEY }}" >> .env + echo "SERVER_API_KEY=${{ secrets.E2E_SERVER_API_KEY }}" >> .env make e2e diff --git a/README.md b/README.md index e6d46f9b..712a0cb0 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ make test #### Run e2e tests -Set the required secrets for E2E tests using environment variables or a `.env` file in the project root. The following variables are required: +Set the required secrets for E2E tests using environment variables or a `.env` file in the project root. The following variables are required, except for `SCHEME`, which is optional and defaults to `https`: - `API_ENDPOINT` (e.g. api.example.com, without scheme) -- `SCHEME` (e.g. https or http, defaults to https) +- `SCHEME` (optional; e.g. https or http, defaults to https) - `CLIENT_API_KEY` (Client SDK role API key) - `SERVER_API_KEY` (Server SDK role API key for testing with local evaluate) diff --git a/ava-e2e.config.mjs b/ava-e2e.config.mjs index 3b0810be..08b97aaf 100644 --- a/ava-e2e.config.mjs +++ b/ava-e2e.config.mjs @@ -11,10 +11,4 @@ export default { '__e2e/__test__/*.js', '__e2e/__test__/local_evaluation/*.js' ], - environmentVariables: { - API_ENDPOINT: process.env.API_ENDPOINT || '', // e.g. api.example.com (without scheme) - SCHEME: process.env.SCHEME || '', // e.g. https or http (defaults to https) - CLIENT_API_KEY: process.env.CLIENT_API_KEY || '', // Client SDK role API key - SERVER_API_KEY: process.env.SERVER_API_KEY || '', // Server SDK role API key for testing with local evaluate - }, }; \ No newline at end of file