Skip to content

Commit ae32077

Browse files
author
Lukas Holzer
authored
chore: make test running independent from netlify build (#4583)
1 parent 33109e1 commit ae32077

File tree

16 files changed

+192
-222
lines changed

16 files changed

+192
-222
lines changed

.github/workflows/workflow.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,48 @@ on:
77
types: [opened, synchronize, reopened]
88
jobs:
99
test:
10+
runs-on: ${{ matrix.os }}
11+
timeout-minutes: 20
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macOS-latest, windows-latest]
15+
node-version: ['*']
16+
include:
17+
- os: ubuntu-latest
18+
node-version: '12.20.0'
19+
fail-fast: false
20+
steps:
21+
# Sets an output parameter if this is a release PR
22+
- name: Check for release
23+
id: release-check
24+
run: echo "::set-output name=IS_RELEASE::true"
25+
if: ${{ startsWith(github.head_ref, 'release-') }}
26+
- uses: actions/checkout@v3
27+
with:
28+
fetch-depth: 0
29+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
30+
- uses: nrwl/nx-set-shas@v3
31+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
32+
- name: Node.js ${{ matrix.node-version }}
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
cache: 'npm'
37+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
38+
- name: Install npm@7
39+
run: npm install -g npm@7
40+
if: ${{ matrix.node-version == '12.20.0' && !steps.release-check.outputs.IS_RELEASE }}
41+
- name: Install dependencies
42+
run: npm ci
43+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
44+
- name: Build
45+
run: npx nx affected --target=build
46+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
47+
- name: Tests
48+
run: npx nx affected --target=test:ci --exclude=@netlify/build --parallel=3
49+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
50+
51+
test-build:
1052
runs-on: ${{ matrix.os }}
1153
timeout-minutes: 20
1254
strategy:
@@ -69,6 +111,7 @@ jobs:
69111
uses: denoland/setup-deno@v1
70112
with:
71113
deno-version: v1.x
114+
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
72115
- name: Node.js ${{ matrix.node-version }}
73116
uses: actions/setup-node@v3
74117
with:
@@ -85,7 +128,7 @@ jobs:
85128
run: npm run build
86129
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
87130
- name: Tests
88-
run: npm run test:ci
131+
run: npx lerna run test:ci --scope @netlify/build
89132
if: ${{ !steps.release-check.outputs.IS_RELEASE }}
90133
env:
91134
# split tests across multiple machines

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ packages/*/tests/**/fixtures/**
44
packages/*/lib
55
# don't lint changelog files as they get auto-generated
66
CHANGELOG.md
7+
coverage

ava.base.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import fs from 'fs'
1+
import fs, { existsSync } from 'fs'
22
import path from 'path'
33
import process from 'process'
4-
import { fileURLToPath } from 'url'
54

65
import { isCI } from 'ci-info'
76

8-
// `tests-metadata.json` is created by running `npm run test:measure`
9-
const testData = JSON.parse(fs.readFileSync(fileURLToPath(new URL('tests-metadata.json', import.meta.url))))
7+
// `tests-metadata.json` is created by running `npx lerna run test:measure --scope @netlify/build`
8+
const testData = existsSync('tests-metadata.json') ? JSON.parse(fs.readFileSync('tests-metadata.json', 'utf-8')) : {}
109

1110
const getOrder = (file) => {
1211
const fileRelative = path.relative(process.cwd(), file).replace(/\\/g, '/')

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"default": {
44
"runner": "nx/tasks-runners/default",
55
"options": {
6-
"cacheableOperations": ["build", "test"]
6+
"cacheableOperations": ["build", "test", "test:ci"]
77
}
88
}
99
},

package-lock.json

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"format:ci": "prettier --check ."
1717
},
1818
"workspaces": [
19+
"tools",
1920
"packages/*"
2021
],
2122
"keywords": [
@@ -55,8 +56,6 @@
5556
"eslint-config-prettier": "^8.5.0",
5657
"eslint-plugin-ava": "^13.2.0",
5758
"eslint-plugin-import": "^2.26.0",
58-
"execa": "^6.1.0",
59-
"globby": "^13.1.1",
6059
"husky": "^8.0.0",
6160
"lerna": "^5.5.2",
6261
"lint-staged": "^13.0.3",

packages/build/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"prebuild": "rm -rf lib",
2525
"build": "cp -a src lib/",
2626
"pretest": "tsd .",
27-
"test": "ava",
27+
"test": "ava tests/time/tests.js",
2828
"test:ci": "c8 -r lcovonly -r text -r json ava",
29-
"test:measure": "node tools/tests_duration.mjs"
29+
"test:measure": "../../tools/tests-duration.js"
3030
},
3131
"keywords": [
3232
"nodejs",

packages/build/tests-metadata.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"tests/env/tests.js": {
3+
"order": 0,
4+
"machine": 0
5+
},
6+
"tests/plugins_list/tests.js": {
7+
"order": 1,
8+
"machine": 0
9+
},
10+
"tests/telemetry/tests.js": {
11+
"order": 2,
12+
"machine": 0
13+
},
14+
"tests/unit/logger/tests.js": {
15+
"order": 3,
16+
"machine": 0
17+
},
18+
"tests/functions/tests.js": {
19+
"order": 4,
20+
"machine": 1
21+
},
22+
"tests/monitor/tests.js": {
23+
"order": 5,
24+
"machine": 1
25+
},
26+
"tests/mutate_headers_redirects/tests.js": {
27+
"order": 6,
28+
"machine": 1
29+
},
30+
"tests/plugins_events/tests.js": {
31+
"order": 7,
32+
"machine": 1
33+
},
34+
"tests/stack/tests.js": {
35+
"order": 8,
36+
"machine": 1
37+
},
38+
"tests/status/tests.js": {
39+
"order": 9,
40+
"machine": 1
41+
},
42+
"tests/time/tests.js": {
43+
"order": 10,
44+
"machine": 1
45+
},
46+
"tests/constants/tests.js": {
47+
"order": 11,
48+
"machine": 2
49+
},
50+
"tests/deploy/tests.js": {
51+
"order": 12,
52+
"machine": 2
53+
},
54+
"tests/error/tests.js": {
55+
"order": 13,
56+
"machine": 2
57+
},
58+
"tests/mutate_save/tests.js": {
59+
"order": 14,
60+
"machine": 2
61+
},
62+
"tests/mutate/tests.js": {
63+
"order": 15,
64+
"machine": 2
65+
},
66+
"tests/utils_build/tests.js": {
67+
"order": 16,
68+
"machine": 2
69+
},
70+
"tests/core/tests.js": {
71+
"order": 17,
72+
"machine": 3
73+
},
74+
"tests/edge_functions/tests.js": {
75+
"order": 18,
76+
"machine": 3
77+
},
78+
"tests/install/tests.js": {
79+
"order": 19,
80+
"machine": 3
81+
},
82+
"tests/log/tests.js": {
83+
"order": 20,
84+
"machine": 3
85+
},
86+
"tests/manifest/tests.js": {
87+
"order": 21,
88+
"machine": 3
89+
},
90+
"tests/plugins/tests.js": {
91+
"order": 22,
92+
"machine": 3
93+
},
94+
"tests/steps/tests.js": {
95+
"order": 23,
96+
"machine": 3
97+
}
98+
}

packages/cache-utils/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"prebuild": "rm -rf lib",
1515
"build": "tsc",
1616
"test": "ava",
17-
"test:ci": "c8 -r lcovonly -r text -r json ava",
18-
"test:measure": "node tools/tests_duration.mjs"
17+
"test:ci": "c8 -r lcovonly -r text -r json ava"
1918
},
2019
"keywords": [
2120
"nodejs",

packages/config/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"prebuild": "rm -rf lib",
2222
"build": "tsc",
2323
"test": "ava",
24-
"test:ci": "c8 -r lcovonly -r text -r json ava",
25-
"test:measure": "node tools/tests_duration.mjs",
26-
"lint": "eslint . --ignore-path ../../.gitignore"
24+
"test:ci": "c8 -r lcovonly -r text -r json ava"
2725
},
2826
"keywords": [
2927
"javascript",

0 commit comments

Comments
 (0)