Skip to content

Commit 329788f

Browse files
committed
Add back shortcut for test:unit for husky
1 parent 475b0aa commit 329788f

File tree

6 files changed

+146
-34
lines changed

6 files changed

+146
-34
lines changed

.github/workflows/changeset-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ jobs:
247247
exit 0
248248
fi
249249
EXT_VERSION=$(node -p "require('./packages/reactor-extension/package.json').version")
250-
pnpm --filter reactor-extension run build
250+
pnpm --filter reactor-extension-alloy run build
251251
node scripts/deployExtensionToReactor.mjs "${EXT_VERSION}"
252252
253253
- name: Restore extension workspace protocol for @adobe/alloy

.github/workflows/deployExtensionRelease.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: pnpm version ${{ github.event.inputs.version }} --no-commit-hooks
4343
working-directory: packages/reactor-extension
4444
- name: Build extension (refresh extension.json)
45-
run: pnpm --filter reactor-extension run build
45+
run: pnpm --filter reactor-extension-alloy run build
4646
- name: Commit and push
4747
run: |
4848
git config user.name "$GITHUB_ACTOR"
@@ -89,7 +89,7 @@ jobs:
8989
run: pnpm version ${{ github.event.inputs.version }} --no-commit-hooks
9090
working-directory: packages/reactor-extension
9191
- name: Build extension (refresh extension.json)
92-
run: pnpm --filter reactor-extension run build
92+
run: pnpm --filter reactor-extension-alloy run build
9393
- name: Commit and push
9494
run: |
9595
git config user.name "$GITHUB_ACTOR"

.github/workflows/extension-quality.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ jobs:
3232
- name: Install dependencies
3333
run: pnpm install --frozen-lockfile
3434
- name: Build all packages
35-
run: pnpm -r run build
35+
run: pnpm run build:all
3636
- name: Run ${{ matrix.check }}
3737
run: |
3838
if [ "${{ matrix.check }}" = "build" ]; then
39-
pnpm --filter reactor-extension run build
39+
pnpm run build:all
4040
else
4141
pnpm run ${{ matrix.check }}
4242
fi
@@ -64,6 +64,6 @@ jobs:
6464
- name: Install dependencies
6565
run: pnpm install --frozen-lockfile
6666
- name: Build all packages
67-
run: pnpm -r run build
67+
run: pnpm run build:all
6868
- name: Run test:${{ matrix.test }}
69-
run: pnpm --filter reactor-extension run test:${{ matrix.test }}
69+
run: pnpm --filter reactor-extension-alloy run test:${{ matrix.test }}

package.json

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,20 @@
2323
},
2424
"scripts": {
2525
"clean": "rimraf dist distTest libEs5 libEs6 types",
26-
"lint": "eslint --cache --fix \"*.{js,cjs,mjs,jsx}\" \"{sandboxes/*/src,packages/*/src,packages/*/scripts,test,scripts}/**/*.{js,cjs,mjs,jsx}\"",
26+
"lint": "eslint --cache --fix \"*.{js,cjs,mjs,jsx}\" \"{sandboxes/*/src,packages/*/src,packages/*/scripts,test,scripts}/**/*.{js,cjs,mjs,jsx}\" && pnpm --filter reactor-extension-alloy run lint",
2727
"format": "prettier --write \"*.{html,js,cjs,mjs,jsx}\" \"{sandboxes/*/src,packages/*/src,packages/*/scripts,packages/*/test,test,scripts}/**/*.{html,js,cjs,mjs,jsx}\"",
28-
"format:check": "prettier --check \"*.{html,js,cjs,mjs,jsx}\" \"{sandboxes/*/src,packages/*/src,packages/*/scripts,test,scripts}/**/*.{html,js,cjs,mjs,jsx}\"",
28+
"format:check": "prettier --check \"*.{html,js,cjs,mjs,jsx}\" \"{sandboxes/*/src,packages/*/src,packages/*/scripts,packages/*/test,test,scripts}/**/*.{html,js,cjs,mjs,jsx}\"",
2929
"types": "tsc",
30-
"test": "pnpm exec playwright install chromium && vitest run && pnpm run test:scripts",
31-
"test:coverage": "rimraf coverage && pnpm exec playwright install chromium && vitest run --coverage",
32-
"test:unit": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=unit --project=reactor-extension/unit",
33-
"test:unit:core": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=unit",
34-
"test:unit:extension": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=reactor-extension/unit",
35-
"test:unit:debug": "pnpm exec playwright install chromium && vitest --config ./vitest.config.js --project=unit --project=reactor-extension/unit --no-file-parallelism --browser=chromium --browser.provider=playwright --browser.headless=false",
36-
"test:unit:watch": "pnpm exec playwright install chromium && vitest --config ./vitest.config.js --project=unit --project=reactor-extension/unit",
37-
"test:unit:coverage": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=unit --project=reactor-extension/unit --coverage",
38-
"test:integration": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=integration --project=reactor-extension/integration",
39-
"test:integration:core": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=integration",
40-
"test:integration:extension": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=reactor-extension/integration",
41-
"test:integration:debug": "pnpm exec playwright install chromium && vitest --config ./vitest.config.js --project=integration --project=reactor-extension/integration --no-file-parallelism --browser=chromium --browser.provider=playwright --browser.headless=false",
42-
"test:integration:watch": "pnpm exec playwright install chromium && vitest --config ./vitest.config.js --project=integration --project=reactor-extension/integration",
43-
"test:integration:coverage": "pnpm exec playwright install chromium && vitest run --config ./vitest.config.js --project=integration --project=reactor-extension/integration --coverage",
30+
"test": "node scripts/runTests.js",
31+
"test:coverage": "node scripts/runTests.js --coverage",
32+
"test:unit": "node scripts/runTests.js --mode=unit",
33+
"test:unit:core": "node scripts/runTests.js --mode=unit --package=core",
34+
"test:unit:extension": "node scripts/runTests.js --mode=unit --package=extension",
35+
"test:unit:watch:extension": "node scripts/runTests.js --watch --mode=unit --package=extension",
36+
"test:integration:core": "node scripts/runTests.js --mode=integration --package=core",
37+
"test:integration:extension": "node scripts/runTests.js --mode=integration --package=extension",
38+
"test:integration:watch:extension": "node scripts/runTests.js --watch --mode=integration --package=extension",
39+
"test:integration:debug": "node scripts/runTests.js --debug --mode=integration",
4440
"test:functional": "pnpm exec playwright install chromium && EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" testcafe chromium",
4541
"test:functional:custom": "node scripts/helpers/runFunctionalTests.js",
4642
"test:functional:watch": "pnpm exec playwright install chromium && EDGE_BASE_PATH=\"ee-pre-prd\" ALLOY_ENV=\"int\" ./scripts/watchFunctionalTests.js --browsers chromium",
@@ -50,13 +46,14 @@
5046
"test:scripts": "vitest run --config=./scripts/specs/vitest.config.js",
5147
"dev": "concurrently --names build,sandbox \"rollup -c -w --environment SANDBOX_SERVICE_WORKER\" \"REACT_APP_NONCE=123 pnpm run --filter @adobe/alloy-sandbox-browser start\"",
5248
"build": "pnpm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN,SERVICE_WORKER,SERVICE_WORKER_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
49+
"build:all": "pnpm run build && pnpm --filter reactor-extension-alloy run build",
5350
"build:watch": "pnpm run clean && rollup -c --watch --environment BASE_CODE_MIN,STANDALONE",
5451
"build:custom": "node scripts/alloyBuilder.js",
55-
"build:extension": "pnpm run build && pnpm --filter reactor-extension run build",
56-
"test:extension": "pnpm --filter reactor-extension run test",
57-
"package:extension": "pnpm --filter reactor-extension run package",
58-
"sandbox:extension": "pnpm --filter reactor-extension run sandbox",
59-
"dev:extension": "pnpm --filter reactor-extension run dev",
52+
"build:extension": "pnpm run build:all",
53+
"test:extension": "pnpm --filter reactor-extension-alloy run test",
54+
"package:extension": "pnpm --filter reactor-extension-alloy run package",
55+
"sandbox:extension": "pnpm --filter reactor-extension-alloy run sandbox",
56+
"dev:extension": "pnpm --filter reactor-extension-alloy run dev",
6057
"prepare": "husky",
6158
"build:lib": "babel packages/core/src -d libEs5 --env-name npmEs5 && babel packages/core/src -d libEs6 --env-name npmEs6 && echo '{\"type\":\"commonjs\"}' > libEs5/package.json && echo '{\"type\":\"module\"}' > libEs6/package.json",
6259
"prepack": "pnpm run clean && pnpm run build:lib && pnpm run types",

packages/reactor-extension/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"prepare": "husky",
3131
"prepush-msg": "echo 'Running pre-push scripts...' && exit 0",
3232
"sandbox": "./scripts/buildExtensionManifest.mjs && reactor-sandbox",
33-
"test": "pnpm exec playwright install chromium && vitest run && pnpm run test:functional",
33+
"test": "pnpm -C ../.. run build:lib && pnpm run build:alloy:preinstalled && pnpm -C ../.. run test:unit:extension && pnpm -C ../.. run test:integration:extension && pnpm run test:functional",
3434
"test:coverage": "pnpm run clean && rimraf coverage && pnpm run build:alloy:preinstalled && pnpm exec playwright install chromium && vitest run --coverage",
35-
"test:unit": "pnpm -C ../.. --filter @adobe/alloy run build:lib && pnpm run build:alloy:preinstalled && pnpm exec playwright install chromium && vitest run --project=unit",
36-
"test:unit:watch": "pnpm -C ../.. --filter @adobe/alloy run build:lib && pnpm run build:alloy:preinstalled && pnpm exec playwright install chromium && vitest --project=unit",
37-
"test:integration": "pnpm exec playwright install chromium && vitest run --project=integration",
38-
"test:integration:watch": "pnpm exec playwright install chromium && vitest --project=integration",
39-
"test:integration:debug": "pnpm exec playwright install chromium && vitest --project=integration --browser=chromium --browser.provider=playwright --browser.headless=false",
35+
"test:unit": "pnpm -C ../.. run build:lib && pnpm run build:alloy:preinstalled && pnpm exec playwright install chromium && pnpm -C ../.. run test:unit:extension",
36+
"test:unit:watch": "pnpm -C ../.. run build:lib && pnpm run build:alloy:preinstalled && pnpm exec playwright install chromium && pnpm -C ../.. run test:unit:watch:extension",
37+
"test:integration": "pnpm -C ../.. run test:integration:extension",
38+
"test:integration:watch": "pnpm -C ../.. run test:integration:watch:extension",
39+
"test:integration:debug": "pnpm -C ../.. run test:integration:debug",
4040
"test:integration:debug:file": "pnpm exec playwright install chromium && vitest --browser=chromium --browser.provider=playwright --browser.headless=false --testTimeout=7000",
4141
"test:serve": "serve --cors --no-clipboard --no-port-switching -p \"$WEB_SERVER_PORT\" dist/view",
4242
"test:functional": "pnpm run build && WEB_SERVER_PORT=4000 conc --pad-prefix --kill-others --hide serve --names \"serve,test\" \"pnpm run test:serve\" \"testcafe playwright:chromium --esm test/functional/specs\"",

scripts/runTests.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
Copyright 2025 Adobe. All rights reserved.
5+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License. You may obtain a copy
7+
of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed under
10+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11+
OF ANY KIND, either express or implied. See the License for the specific language
12+
governing permissions and limitations under the License.
13+
*/
14+
15+
/**
16+
* Unified vitest runner. Usage:
17+
* pnpm run test # all unit + integration (core + extension), then test:scripts
18+
* pnpm run test -- --coverage # all with coverage
19+
* pnpm run test -- --watch --mode=unit --package=extension
20+
* pnpm run test -- --debug --mode=integration --package=core
21+
* Flags: --coverage, --watch, --debug, --mode=unit|integration, --package=core|extension|all
22+
* Extra args are passed to vitest (e.g. path to a test file).
23+
*/
24+
25+
import { spawnSync } from "child_process";
26+
27+
const argv = process.argv.slice(2);
28+
29+
const has = (flag) => argv.includes(flag);
30+
const get = (prefix) => {
31+
const arg = argv.find((a) => a.startsWith(`${prefix}=`));
32+
return arg ? arg.slice(prefix.length + 1) : null;
33+
};
34+
35+
const coverage = has("--coverage");
36+
const watch = has("--watch");
37+
const debug = has("--debug");
38+
const mode = get("--mode"); // unit | integration
39+
const pkg = get("--package"); // core | extension | all
40+
41+
// Any remaining args (e.g. file path) pass through to vitest
42+
const passthrough = argv.filter(
43+
(a) =>
44+
!a.startsWith("--mode=") &&
45+
!a.startsWith("--package=") &&
46+
a !== "--coverage" &&
47+
a !== "--watch" &&
48+
a !== "--debug",
49+
);
50+
51+
const PROJECTS = {
52+
unit: ["unit", "reactor-extension/unit"],
53+
integration: ["integration", "reactor-extension/integration"],
54+
};
55+
56+
const getProjects = () => {
57+
if (!mode) {
58+
return [
59+
"unit",
60+
"integration",
61+
"reactor-extension/unit",
62+
"reactor-extension/integration",
63+
];
64+
}
65+
const both = PROJECTS[mode];
66+
if (!both) {
67+
console.error(`Invalid --mode=${mode}; use unit or integration`);
68+
process.exit(1);
69+
}
70+
if (pkg === "core") return [both[0]];
71+
if (pkg === "extension") return [both[1]];
72+
return both;
73+
};
74+
75+
const run = (cmd, args, opts = {}) => {
76+
const result = spawnSync(cmd, args, {
77+
stdio: "inherit",
78+
shell: true,
79+
...opts,
80+
});
81+
if (result.status !== 0) process.exit(result.status ?? 1);
82+
return result;
83+
};
84+
85+
// Playwright install (needed for browser projects)
86+
run("pnpm", ["exec", "playwright", "install", "chromium"]);
87+
88+
if (coverage) {
89+
run("pnpm", ["exec", "rimraf", "coverage"]);
90+
}
91+
92+
const projects = getProjects();
93+
const vitestArgs = [
94+
...(watch ? [] : ["run"]),
95+
"--config",
96+
"./vitest.config.js",
97+
...projects.flatMap((p) => ["--project", p]),
98+
...(coverage ? ["--coverage"] : []),
99+
...(debug
100+
? [
101+
"--no-file-parallelism",
102+
"--browser=chromium",
103+
"--browser.provider=playwright",
104+
"--browser.headless=false",
105+
]
106+
: []),
107+
...passthrough,
108+
];
109+
110+
run("pnpm", ["exec", "vitest", ...vitestArgs]);
111+
112+
// Default (no mode): also run script specs
113+
if (!mode) {
114+
run("pnpm", ["run", "test:scripts"]);
115+
}

0 commit comments

Comments
 (0)