Skip to content

Commit

Permalink
chore: introduce vitests for tests (#5269)
Browse files Browse the repository at this point in the history
* chore: introduce vitests for ESM unit tests

* chore: shard vitest and allow integration tests with vitest

* chore: test renaming

* chore: rename E2E tests too

* Apply suggestions from code review

Co-authored-by: Jackie Macharia <jackline.macharia@netlify.com>

* chore: organize test workflows

Co-authored-by: Jackie Macharia <jackline.macharia@netlify.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 6, 2022
1 parent 57ee933 commit 26c409d
Show file tree
Hide file tree
Showing 34 changed files with 8,782 additions and 7,822 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'import/extensions': [2, 'ignorePackages'],
'n/no-process-exit': 0,
'n/no-sync': 0,
'no-magic-numbers': 'off',
'sort-destructure-keys/sort-destructure-keys': 2,
'unicorn/consistent-destructuring': 0,
// TODO: harmonize with filename snake_case in other Netlify Dev projects
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E Testing for CLI
name: Tests

on:
push:
Expand All @@ -11,6 +11,7 @@ on:

jobs:
e2e:
name: E2E
runs-on: ${{ matrix.os }}
timeout-minutes: 20
env:
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
integration:
name: Integration
runs-on: ${{ matrix.os }}
timeout-minutes: 15
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [14.x, '*']
shard: ['1/2', '2/2']

exclude:
- os: macOS-latest
node-version: '14.x'
- os: windows-latest
node-version: '14.x'
fail-fast: false
steps:
# Sets an output parameter if this is a release PR
- name: Check for release
id: release-check
# For windows we have to use $env:
run: |-
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
if: "${{ startsWith(github.head_ref, 'release-') }}"
# This improves Windows network performance, we need this since we open many ports in our tests
- name: Increase Windows port limit and reduce time wait delay
run: |
netsh int ipv4 set dynamicport tcp start=1025 num=64511
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters /v TcpTimedWaitDelay /t REG_DWORD /d 30 /f
if: "${{ matrix.os == 'windows-latest' && !steps.release-check.outputs.IS_RELEASE }}"
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'npm-shrinkwrap.json'
check-latest: true
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Setup Deno
uses: denoland/setup-deno@v1
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
with:
deno-version: v1.x
- name: Install core dependencies
run: npm ci --no-audit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Determine which tests to run
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
uses: haya14busa/action-cond@v1
id: changed
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: '--changed=${{ github.event.pull_request.base.sha }}' # on pull requests test with the project graph only the affected tests
if_false: '' # on the base branch run all the tests as security measure
- name: Generate self-signed certificates
run: npm run certs
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
shell: bash
- name: Prepare tests
run: npm run test:init
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
- name: Tests
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
run: npm run test:ci:vitest:integration -- --shard=${{ matrix.shard }} ${{ steps.changed.outputs.value }}
env:
# GitHub secrets are not available when running on PR from forks
# We set a flag so we can skip tests that access Netlify API
NETLIFY_TEST_DISABLE_LIVE:
${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
# NETLIFY_TEST_GITHUB_TOKEN is used to avoid reaching GitHub API limits in exec-fetcher.js
NETLIFY_TEST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Changes the polling interval used by the file watcher
CHOKIDAR_INTERVAL: 20
CHOKIDAR_USEPOLLING: 1
- name: Get test coverage flags
id: test-coverage-flags
# For windows we have to use $env:
run: |-
os=${{ matrix.os }}
node=$(node --version)
echo "os=${os/-latest/}" >> $GITHUB_OUTPUT
echo "os=${os/-latest/}" >> $env:GITHUB_OUTPUT
echo "node=node_${node/.*.*/}" >> $GITHUB_OUTPUT
echo "node=node_${node/.*.*/}" >> $env:GITHUB_OUTPUT
shell: bash
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
- uses: codecov/codecov-action@v3
continue-on-error: true
with:
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
49 changes: 3 additions & 46 deletions .github/workflows/main.yml → .github/workflows/legacy-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Testing for CLI
name: Tests

on:
push:
Expand All @@ -7,45 +7,8 @@ on:
branches: [main]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: ['*']
steps:
# Sets an output parameter if this is a release PR
- name: Check for release
id: release-check
# For windows we have to use $env:
run: |-
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
if: "${{ startsWith(github.head_ref, 'release-') }}"
- name: Git checkout
uses: actions/checkout@v3
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'npm-shrinkwrap.json'
check-latest: true
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Install core dependencies
run: npm ci --no-audit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Install site dependencies
run: npm run site:build:install
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Linting
run: npm run format:ci
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Run unit tests
run: npm run test:ci:ava:unit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
test:
integration:
name: Legacy Integration
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
Expand Down Expand Up @@ -147,9 +110,3 @@ jobs:
file: coverage/coverage-final.json
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
all:
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Log success
run: echo "Finished running all tests"
51 changes: 51 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
unit:
name: Unit
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: ['*']
steps:
# Sets an output parameter if this is a release PR
- name: Check for release
id: release-check
# For windows we have to use $env:
run: |-
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
if: "${{ startsWith(github.head_ref, 'release-') }}"
- name: Git checkout
uses: actions/checkout@v3
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: 'npm-shrinkwrap.json'
check-latest: true
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Install core dependencies
run: npm ci --no-audit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Install site dependencies
run: npm run site:build:install
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Linting
run: npm run format:ci
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Run unit tests
run: npm run test:ci:ava:unit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
- name: Run vitest unit tests
run: npm run test:ci:vitest:unit
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
1 change: 0 additions & 1 deletion e2e.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const config = {
files: ['e2e/**/*.e2e.mjs'],
cache: true,
// eslint-disable-next-line no-magic-numbers
concurrency: 5,
failFast: false,
failWithoutAssertions: false,
Expand Down
Loading

1 comment on commit 26c409d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Package size: 247 MB

Please sign in to comment.