Skip to content

Commit 26c409d

Browse files
danezjackiewmachariakodiakhq[bot]
authored
chore: introduce vitests for tests (#5269)
* 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>
1 parent 57ee933 commit 26c409d

34 files changed

+8782
-7822
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = {
2626
'import/extensions': [2, 'ignorePackages'],
2727
'n/no-process-exit': 0,
2828
'n/no-sync': 0,
29+
'no-magic-numbers': 'off',
2930
'sort-destructure-keys/sort-destructure-keys': 2,
3031
'unicorn/consistent-destructuring': 0,
3132
// TODO: harmonize with filename snake_case in other Netlify Dev projects

.github/workflows/e2e-test.yml renamed to .github/workflows/e2e-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: E2E Testing for CLI
1+
name: Tests
22

33
on:
44
push:
@@ -11,6 +11,7 @@ on:
1111

1212
jobs:
1313
e2e:
14+
name: E2E
1415
runs-on: ${{ matrix.os }}
1516
timeout-minutes: 20
1617
env:
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
integration:
11+
name: Integration
12+
runs-on: ${{ matrix.os }}
13+
timeout-minutes: 15
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, macOS-latest, windows-latest]
17+
node-version: [14.x, '*']
18+
shard: ['1/2', '2/2']
19+
20+
exclude:
21+
- os: macOS-latest
22+
node-version: '14.x'
23+
- os: windows-latest
24+
node-version: '14.x'
25+
fail-fast: false
26+
steps:
27+
# Sets an output parameter if this is a release PR
28+
- name: Check for release
29+
id: release-check
30+
# For windows we have to use $env:
31+
run: |-
32+
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
33+
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
34+
if: "${{ startsWith(github.head_ref, 'release-') }}"
35+
# This improves Windows network performance, we need this since we open many ports in our tests
36+
- name: Increase Windows port limit and reduce time wait delay
37+
run: |
38+
netsh int ipv4 set dynamicport tcp start=1025 num=64511
39+
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters /v TcpTimedWaitDelay /t REG_DWORD /d 30 /f
40+
if: "${{ matrix.os == 'windows-latest' && !steps.release-check.outputs.IS_RELEASE }}"
41+
- name: Git checkout
42+
uses: actions/checkout@v3
43+
with:
44+
fetch-depth: 0
45+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
46+
- name: Use Node.js ${{ matrix.node-version }}
47+
uses: actions/setup-node@v3
48+
with:
49+
node-version: ${{ matrix.node-version }}
50+
cache: 'npm'
51+
cache-dependency-path: 'npm-shrinkwrap.json'
52+
check-latest: true
53+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
54+
- name: Setup Deno
55+
uses: denoland/setup-deno@v1
56+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
57+
with:
58+
deno-version: v1.x
59+
- name: Install core dependencies
60+
run: npm ci --no-audit
61+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
62+
- name: Determine which tests to run
63+
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
64+
uses: haya14busa/action-cond@v1
65+
id: changed
66+
with:
67+
cond: ${{ github.event_name == 'pull_request' }}
68+
if_true: '--changed=${{ github.event.pull_request.base.sha }}' # on pull requests test with the project graph only the affected tests
69+
if_false: '' # on the base branch run all the tests as security measure
70+
- name: Generate self-signed certificates
71+
run: npm run certs
72+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
73+
shell: bash
74+
- name: Prepare tests
75+
run: npm run test:init
76+
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
77+
- name: Tests
78+
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
79+
run: npm run test:ci:vitest:integration -- --shard=${{ matrix.shard }} ${{ steps.changed.outputs.value }}
80+
env:
81+
# GitHub secrets are not available when running on PR from forks
82+
# We set a flag so we can skip tests that access Netlify API
83+
NETLIFY_TEST_DISABLE_LIVE:
84+
${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
85+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
86+
# NETLIFY_TEST_GITHUB_TOKEN is used to avoid reaching GitHub API limits in exec-fetcher.js
87+
NETLIFY_TEST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
# Changes the polling interval used by the file watcher
89+
CHOKIDAR_INTERVAL: 20
90+
CHOKIDAR_USEPOLLING: 1
91+
- name: Get test coverage flags
92+
id: test-coverage-flags
93+
# For windows we have to use $env:
94+
run: |-
95+
os=${{ matrix.os }}
96+
node=$(node --version)
97+
echo "os=${os/-latest/}" >> $GITHUB_OUTPUT
98+
echo "os=${os/-latest/}" >> $env:GITHUB_OUTPUT
99+
echo "node=node_${node/.*.*/}" >> $GITHUB_OUTPUT
100+
echo "node=node_${node/.*.*/}" >> $env:GITHUB_OUTPUT
101+
shell: bash
102+
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
103+
- uses: codecov/codecov-action@v3
104+
continue-on-error: true
105+
with:
106+
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
107+
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'

.github/workflows/main.yml renamed to .github/workflows/legacy-tests.yml

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Testing for CLI
1+
name: Tests
22

33
on:
44
push:
@@ -7,45 +7,8 @@ on:
77
branches: [main]
88

99
jobs:
10-
build:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
matrix:
14-
os: [ubuntu-latest, macOS-latest, windows-latest]
15-
node-version: ['*']
16-
steps:
17-
# Sets an output parameter if this is a release PR
18-
- name: Check for release
19-
id: release-check
20-
# For windows we have to use $env:
21-
run: |-
22-
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
23-
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
24-
if: "${{ startsWith(github.head_ref, 'release-') }}"
25-
- name: Git checkout
26-
uses: actions/checkout@v3
27-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
28-
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v3
30-
with:
31-
node-version: ${{ matrix.node-version }}
32-
cache: 'npm'
33-
cache-dependency-path: 'npm-shrinkwrap.json'
34-
check-latest: true
35-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
36-
- name: Install core dependencies
37-
run: npm ci --no-audit
38-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
39-
- name: Install site dependencies
40-
run: npm run site:build:install
41-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
42-
- name: Linting
43-
run: npm run format:ci
44-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
45-
- name: Run unit tests
46-
run: npm run test:ci:ava:unit
47-
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
48-
test:
10+
integration:
11+
name: Legacy Integration
4912
runs-on: ${{ matrix.os }}
5013
timeout-minutes: 30
5114
strategy:
@@ -147,9 +110,3 @@ jobs:
147110
file: coverage/coverage-final.json
148111
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
149112
if: '${{ !steps.release-check.outputs.IS_RELEASE }}'
150-
all:
151-
needs: [build, test]
152-
runs-on: ubuntu-latest
153-
steps:
154-
- name: Log success
155-
run: echo "Finished running all tests"

.github/workflows/unit-tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit:
11+
name: Unit
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macOS-latest, windows-latest]
16+
node-version: ['*']
17+
steps:
18+
# Sets an output parameter if this is a release PR
19+
- name: Check for release
20+
id: release-check
21+
# For windows we have to use $env:
22+
run: |-
23+
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
24+
echo "IS_RELEASE=true" >> $env:GITHUB_OUTPUT
25+
if: "${{ startsWith(github.head_ref, 'release-') }}"
26+
- name: Git checkout
27+
uses: actions/checkout@v3
28+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
29+
- name: Use Node.js ${{ matrix.node-version }}
30+
uses: actions/setup-node@v3
31+
with:
32+
node-version: ${{ matrix.node-version }}
33+
cache: 'npm'
34+
cache-dependency-path: 'npm-shrinkwrap.json'
35+
check-latest: true
36+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
37+
- name: Install core dependencies
38+
run: npm ci --no-audit
39+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
40+
- name: Install site dependencies
41+
run: npm run site:build:install
42+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
43+
- name: Linting
44+
run: npm run format:ci
45+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
46+
- name: Run unit tests
47+
run: npm run test:ci:ava:unit
48+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
49+
- name: Run vitest unit tests
50+
run: npm run test:ci:vitest:unit
51+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'

e2e.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const config = {
22
files: ['e2e/**/*.e2e.mjs'],
33
cache: true,
4-
// eslint-disable-next-line no-magic-numbers
54
concurrency: 5,
65
failFast: false,
76
failWithoutAssertions: false,

0 commit comments

Comments
 (0)