From c0e2a48b2c1256a3a25db9007ce3b444301e04f2 Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:15:41 +0800 Subject: [PATCH 1/7] feat: rename main.yml to ci.yml --- .github/workflows/{main.yml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{main.yml => ci.yml} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/ci.yml From 2b8d15f8b21f8c83760e1e3fed14d399c528666d Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:15:57 +0800 Subject: [PATCH 2/7] feat: separate build and test stage in ci --- .github/workflows/ci.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af2ee829..7fe74c04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,23 @@ jobs: - name: Start test containers run: npm run setup:test - - name: Build and test - run: npm run build && npm run test-start + - name: Build + run: npm run build + + - if: env.DD_SERVICE_NAME != '' && env.DD_API_KEY != '' + name: Configure Datadog Test Visibility + uses: datadog/test-visibility-github-action@v1.0.5 + with: + languages: javascript + service-name: ${{ secrets.DD_SERVICE_NAME }} + api-key: ${{ secrets.DD_API_KEY }} + + - name: Run tests + shell: bash + run: npm run test-start + env: + # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action + NODE_OPTIONS: -r ${{ env.DD_TRACE_PACKAGE }} - name: Stop test containers run: npm run teardown From cac0c91d80f1ef6f037352c3f3e32a5bb2e506c8 Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:26:38 +0800 Subject: [PATCH 3/7] fix: update node_options setting if dd_trace_package does not exist --- .github/workflows/ci.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fe74c04..b4f30c88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,13 +43,7 @@ jobs: restore-keys: | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - - name: Start test containers - run: npm run setup:test - - - name: Build - run: npm run build - - - if: env.DD_SERVICE_NAME != '' && env.DD_API_KEY != '' + - if: secrets.DD_SERVICE_NAME != '' && secrets.DD_API_KEY != '' name: Configure Datadog Test Visibility uses: datadog/test-visibility-github-action@v1.0.5 with: @@ -57,12 +51,19 @@ jobs: service-name: ${{ secrets.DD_SERVICE_NAME }} api-key: ${{ secrets.DD_API_KEY }} + - name: Start test containers + run: npm run setup:test + + - name: Build + run: npm run build + - name: Run tests shell: bash run: npm run test-start env: - # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action - NODE_OPTIONS: -r ${{ env.DD_TRACE_PACKAGE }} + # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action, + # but might not be available if repository does not have the required env vars set. + NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('-r {0}', env.DD_TRACE_PACKAGE) || '' }} - name: Stop test containers run: npm run teardown From a19de352160e80e68d60df16554337c6bfc5f12d Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:30:33 +0800 Subject: [PATCH 4/7] feat: move secret into env for use in conditional checks --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4f30c88..6431d559 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,8 +43,11 @@ jobs: restore-keys: | ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- - - if: secrets.DD_SERVICE_NAME != '' && secrets.DD_API_KEY != '' - name: Configure Datadog Test Visibility + - name: Configure Datadog Test Visibility + env: + DD_SERVICE_NAME: ${{ secrets.DD_SERVICE_NAME }} + DD_API_KEY: ${{ secrets.DD_API_KEY }} + if: env.DD_SERVICE_NAME != '' && env.DD_API_KEY != '' uses: datadog/test-visibility-github-action@v1.0.5 with: languages: javascript From 5aa424b7b9577678f9673431f18d0acf4bbcf745 Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:32:42 +0800 Subject: [PATCH 5/7] fix: use correct arg for datadog test visibility action --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6431d559..8d3cfad1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: if: env.DD_SERVICE_NAME != '' && env.DD_API_KEY != '' uses: datadog/test-visibility-github-action@v1.0.5 with: - languages: javascript + languages: js service-name: ${{ secrets.DD_SERVICE_NAME }} api-key: ${{ secrets.DD_API_KEY }} From 71ace10bad6ff196e03eaa2cc7a0003409e1cabc Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:44:55 +0800 Subject: [PATCH 6/7] feat: add extra node_options for vitest --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d3cfad1..f07def3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,8 @@ jobs: env: # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action, # but might not be available if repository does not have the required env vars set. - NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('-r {0}', env.DD_TRACE_PACKAGE) || '' }} + # --import dd-trace/register.js is required for vitest + NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('--import dd-trace/register.js -r {0}', env.DD_TRACE_PACKAGE) || '--import dd-trace/register.js' }} - name: Stop test containers run: npm run teardown From b69014d7c3c77fae48be44e5a40a90667d447e37 Mon Sep 17 00:00:00 2001 From: Kar Rui Lau <karrui@open.gov.sg> Date: Tue, 23 Jul 2024 13:56:13 +0800 Subject: [PATCH 7/7] feat: split out unit and e2e test step so ci coverage works for vitest --- .github/workflows/ci.yml | 14 +++++++++++--- package.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f07def3e..17028fbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,14 +60,22 @@ jobs: - name: Build run: npm run build - - name: Run tests + - name: Run unit tests shell: bash - run: npm run test-start + run: npm run test:unit env: # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action, # but might not be available if repository does not have the required env vars set. # --import dd-trace/register.js is required for vitest - NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('--import dd-trace/register.js -r {0}', env.DD_TRACE_PACKAGE) || '--import dd-trace/register.js' }} + NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('--import {0}/.datadog/lib/node_modules/dd-trace/register.js -r {1}', github.workspace, env.DD_TRACE_PACKAGE) || '' }} + + - name: Run e2e tests + shell: bash + run: npm run test-e2e-start + env: + # env.DD_TRACE_PACKAGE is provided by the Datadog GitHub Action, + # but might not be available if repository does not have the required env vars set. + NODE_OPTIONS: ${{ env.DD_TRACE_PACKAGE && format('-r {0}', env.DD_TRACE_PACKAGE) || '' }} - name: Stop test containers run: npm run teardown diff --git a/package.json b/package.json index 9af574be..4554f92e 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "test:e2e": "dotenv -e .env.test playwright test", "test-dev": "start-server-and-test dev http://127.0.0.1:3000 test", "test-dev:unit": "dotenv -e .env.test vitest", - "test-start": "start-server-and-test start http://127.0.0.1:3000 test", + "test-e2e-start": "start-server-and-test start http://127.0.0.1:3000 test:e2e", "postinstall": "npm run generate && npm run build:theme", "storybook": "storybook dev -p 6006", "build-storybook": "storybook build"