Skip to content

Commit 5ce04c8

Browse files
authored
test: add external dogfood harness for configure-nodejs (#1)
1 parent 8a178a2 commit 5ce04c8

16 files changed

Lines changed: 528 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
inputs:
10+
configure-nodejs-ref:
11+
description: Ref in pwrdrvr/configure-nodejs to validate
12+
default: main
13+
required: false
14+
type: string
15+
16+
env:
17+
CONFIGURE_NODEJS_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.configure-nodejs-ref || 'main' }}
18+
19+
jobs:
20+
unit:
21+
name: Unit Tests
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- name: Checkout configure-nodejs
27+
uses: actions/checkout@v6
28+
with:
29+
repository: pwrdrvr/configure-nodejs
30+
ref: ${{ env.CONFIGURE_NODEJS_REF }}
31+
path: configure-nodejs
32+
33+
- uses: actions/setup-node@v6
34+
with:
35+
node-version: 22.x
36+
37+
- name: Run unit tests
38+
run: npm test
39+
40+
fixture-lookup:
41+
name: Fixture Lookup (${{ matrix.package-manager }})
42+
needs: unit
43+
runs-on: ubuntu-latest
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
include:
48+
- package-manager: npm
49+
fixture: fixtures/npm-basic
50+
install-command: npm ci
51+
lockfile-name: package-lock.json
52+
- package-manager: pnpm
53+
fixture: fixtures/pnpm-basic
54+
install-command: pnpm install --frozen-lockfile
55+
lockfile-name: pnpm-lock.yaml
56+
- package-manager: yarn
57+
fixture: fixtures/yarn-basic
58+
install-command: yarn install --immutable
59+
lockfile-name: yarn.lock
60+
steps:
61+
- uses: actions/checkout@v6
62+
63+
- name: Checkout configure-nodejs
64+
uses: actions/checkout@v6
65+
with:
66+
repository: pwrdrvr/configure-nodejs
67+
ref: ${{ env.CONFIGURE_NODEJS_REF }}
68+
path: configure-nodejs
69+
70+
- name: Configure Node.js
71+
id: configure-nodejs
72+
uses: ./configure-nodejs
73+
with:
74+
working-directory: ${{ matrix.fixture }}
75+
cache-key-suffix: fixture-tests
76+
lookup-only: "true"
77+
78+
- name: Assert resolved action outputs
79+
shell: bash
80+
run: |
81+
test "${{ steps.configure-nodejs.outputs.package-manager }}" = "${{ matrix.package-manager }}"
82+
test "${{ steps.configure-nodejs.outputs.install-command }}" = "${{ matrix.install-command }}"
83+
test "${{ steps.configure-nodejs.outputs.working-directory }}" = "${{ matrix.fixture }}"
84+
test "${{ steps.configure-nodejs.outputs.lockfile-name }}" = "${{ matrix.lockfile-name }}"
85+
86+
- name: Assert lookup-only behavior
87+
working-directory: ${{ matrix.fixture }}
88+
shell: bash
89+
run: |
90+
if [ "${{ steps.configure-nodejs.outputs.cache-hit }}" = "true" ]; then
91+
test ! -d node_modules
92+
else
93+
test -d node_modules
94+
node check.mjs
95+
fi
96+
97+
fixture-validate:
98+
name: Fixture Validate (${{ matrix.package-manager }})
99+
needs: fixture-lookup
100+
runs-on: ubuntu-latest
101+
strategy:
102+
fail-fast: false
103+
matrix:
104+
include:
105+
- package-manager: npm
106+
fixture: fixtures/npm-basic
107+
install-command: npm ci
108+
lockfile-name: package-lock.json
109+
- package-manager: pnpm
110+
fixture: fixtures/pnpm-basic
111+
install-command: pnpm install --frozen-lockfile
112+
lockfile-name: pnpm-lock.yaml
113+
- package-manager: yarn
114+
fixture: fixtures/yarn-basic
115+
install-command: yarn install --immutable
116+
lockfile-name: yarn.lock
117+
steps:
118+
- uses: actions/checkout@v6
119+
120+
- name: Checkout configure-nodejs
121+
uses: actions/checkout@v6
122+
with:
123+
repository: pwrdrvr/configure-nodejs
124+
ref: ${{ env.CONFIGURE_NODEJS_REF }}
125+
path: configure-nodejs
126+
127+
- name: Configure Node.js
128+
id: configure-nodejs
129+
uses: ./configure-nodejs
130+
with:
131+
working-directory: ${{ matrix.fixture }}
132+
cache-key-suffix: fixture-tests
133+
134+
- name: Assert restore behavior
135+
shell: bash
136+
run: |
137+
test "${{ steps.configure-nodejs.outputs.package-manager }}" = "${{ matrix.package-manager }}"
138+
test "${{ steps.configure-nodejs.outputs.install-command }}" = "${{ matrix.install-command }}"
139+
test "${{ steps.configure-nodejs.outputs.working-directory }}" = "${{ matrix.fixture }}"
140+
test "${{ steps.configure-nodejs.outputs.lockfile-name }}" = "${{ matrix.lockfile-name }}"
141+
test "${{ steps.configure-nodejs.outputs.cache-hit }}" = "true"
142+
143+
- name: Validate installed dependency
144+
working-directory: ${{ matrix.fixture }}
145+
run: node check.mjs

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
.DS_Store
3+
4+
fixtures/*/node_modules/
5+
fixtures/*/.pnp.*
6+
fixtures/*/.yarn/install-state.gz
7+
fixtures/*/.yarn/cache/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# configure-nodejs-test
2+
3+
Dogfood and validation harness for [`pwrdrvr/configure-nodejs`](https://github.com/pwrdrvr/configure-nodejs).
4+
5+
The workflow in this repository checks out `pwrdrvr/configure-nodejs` at a configurable ref, runs unit tests against its helper scripts, and exercises npm, pnpm, and Yarn fixtures through the action entrypoint.

fixtures/npm-basic/check.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pc from 'picocolors';
2+
3+
if (typeof pc.green !== 'function') {
4+
throw new Error('Expected picocolors.green to be available after npm install.');
5+
}
6+
7+
console.log(pc.green('npm fixture dependency loaded'));

fixtures/npm-basic/package-lock.json

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

fixtures/npm-basic/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "npm-basic-fixture",
3+
"private": true,
4+
"type": "module",
5+
"dependencies": {
6+
"picocolors": "1.1.1"
7+
}
8+
}

fixtures/pnpm-basic/check.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pc from 'picocolors';
2+
3+
if (typeof pc.green !== 'function') {
4+
throw new Error('Expected picocolors.green to be available after pnpm install.');
5+
}
6+
7+
console.log(pc.green('pnpm fixture dependency loaded'));

fixtures/pnpm-basic/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "pnpm-basic-fixture",
3+
"private": true,
4+
"type": "module",
5+
"packageManager": "pnpm@10.12.1",
6+
"dependencies": {
7+
"picocolors": "1.1.1"
8+
}
9+
}

fixtures/pnpm-basic/pnpm-lock.yaml

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

fixtures/yarn-basic/.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

0 commit comments

Comments
 (0)