Skip to content

Commit 4fb0d86

Browse files
authored
test(js): isolate frontmatter GitHub API test as integration (#27213)
1 parent c27524b commit 4fb0d86

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ jobs:
377377
if [ -z "$GITHUB_TOKEN" ]; then
378378
echo "⚠️ GITHUB_TOKEN not available - test will be skipped" >> $GITHUB_STEP_SUMMARY
379379
echo "ℹ️ This is expected in forks or when secrets are not available" >> $GITHUB_STEP_SUMMARY
380-
cd actions/setup/js && npm test -- frontmatter_hash_github_api.test.cjs
380+
cd actions/setup/js && npm run test:js-integration-live-api
381381
else
382382
echo "✅ GITHUB_TOKEN available - running live API test" >> $GITHUB_STEP_SUMMARY
383383
echo "" >> $GITHUB_STEP_SUMMARY
384-
cd actions/setup/js && npm test -- frontmatter_hash_github_api.test.cjs
384+
cd actions/setup/js && npm run test:js-integration-live-api
385385
echo "" >> $GITHUB_STEP_SUMMARY
386386
echo "✨ Live API test completed successfully" >> $GITHUB_STEP_SUMMARY
387387
fi

actions/setup/js/TESTING_LIVE_API.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ This directory includes tests for the JavaScript frontmatter hash implementation
44

55
## Running Tests
66

7-
### Standard Test Suite (with mocks)
7+
### Integration Test Suite (not part of default `npm run test:js`)
88
```bash
9-
npm test -- frontmatter_hash_github_api.test.cjs
9+
npm run test:js-integration-live-api
1010
```
1111

12-
This runs all tests including mocked GitHub API calls.
12+
This runs `frontmatter_hash_github_api.test.cjs`, including mocked GitHub API coverage and the optional live API check.
1313

1414
### Live GitHub API Test (no mocks)
1515

1616
The test suite includes a live API test that fetches real data from the GitHub repository. To run it, you need a GitHub token:
1717

18-
#### Option 1: Run via npm test
18+
#### Option 1: Run via npm integration script
1919
```bash
20-
GITHUB_TOKEN=ghp_your_token_here npm test -- frontmatter_hash_github_api.test.cjs
20+
GITHUB_TOKEN=ghp_your_token_here npm run test:js-integration-live-api
2121
```
2222

2323
#### Option 2: Run standalone script
@@ -56,7 +56,7 @@ This validates that the JavaScript hash implementation works correctly with real
5656
stdout | frontmatter_hash_github_api.test.cjs > live GitHub API integration > should compute hash using real GitHub API (no mocks)
5757
Skipping live API test - no GITHUB_TOKEN or GH_TOKEN available
5858
To run this test, set GITHUB_TOKEN or GH_TOKEN environment variable
59-
Example: GITHUB_TOKEN=ghp_xxx npm test -- frontmatter_hash_github_api.test.cjs
59+
Example: GITHUB_TOKEN=ghp_xxx npm run test:js-integration-live-api
6060
6161
✓ frontmatter_hash_github_api.test.cjs (10 tests) 16ms
6262
```

actions/setup/js/frontmatter_hash_github_api.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe("frontmatter_hash with GitHub API", () => {
378378
if (!token) {
379379
console.log("Skipping live API test - no GITHUB_TOKEN or GH_TOKEN available");
380380
console.log("To run this test, set GITHUB_TOKEN or GH_TOKEN environment variable");
381-
console.log("Example: GITHUB_TOKEN=ghp_xxx npm test -- frontmatter_hash_github_api.test.cjs");
381+
console.log("Example: GITHUB_TOKEN=ghp_xxx npm run test:js-integration-live-api");
382382
return;
383383
}
384384

actions/setup/js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"typecheck": "tsc --noEmit",
2424
"test": "npm run typecheck && vitest run --no-file-parallelism",
2525
"test:js": "vitest run",
26+
"test:js-integration-live-api": "vitest run --config vitest.integration.config.mjs --no-file-parallelism",
2627
"test:js-watch": "vitest",
2728
"test:js-coverage": "vitest run --coverage",
2829
"format:cjs": "npx prettier --write '**/*.cjs' '**/*.ts' '**/*.json' --ignore-path ../../../.prettierignore",

actions/setup/js/vitest.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { defineConfig } from "vitest/config";
1+
import { configDefaults, defineConfig } from "vitest/config";
22

33
export default defineConfig({
44
test: {
55
environment: "node",
66
globals: true,
77
include: ["**/*.test.{js,cjs}"],
8+
exclude: ["**/frontmatter_hash_github_api.test.cjs", ...configDefaults.exclude],
89
testTimeout: 10000,
910
hookTimeout: 10000,
1011
coverage: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
environment: "node",
6+
globals: true,
7+
include: ["frontmatter_hash_github_api.test.cjs"],
8+
testTimeout: 30000,
9+
hookTimeout: 10000,
10+
},
11+
});

0 commit comments

Comments
 (0)