feat: split out unit and e2e test step so ci coverage works for vitest #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: [push] | |
jobs: | |
tests: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
node: ['18.x'] | |
os: [ubuntu-latest] | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Use Node ${{ matrix.node }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node }} | |
cache: 'npm' # You can active this cache when your repo has a lockfile | |
- name: Install deps (with cache) | |
run: npm install | |
- name: Install playwright | |
run: npx playwright install chromium | |
- name: Load .env file | |
uses: xom9ikk/dotenv@v2 | |
with: | |
mode: test | |
- name: Next.js cache | |
uses: actions/cache@v3 | |
with: | |
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node | |
path: | | |
~/.npm | |
${{ github.workspace }}/.next/cache | |
# Generate a new cache whenever packages or source files change. | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} | |
# If source files changed but packages didn't, rebuild from a prior cache. | |
restore-keys: | | |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | |
- 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/[email protected] | |
with: | |
languages: js | |
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 unit tests | |
shell: bash | |
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 {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 | |
- name: Upload test results | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: test results | |
path: | | |
playwright/test-results |