Files
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

109 lines
3.3 KiB
JavaScript

/**
* Tests for scripts/hooks/check-hook-enabled.js
*
* Tests the CLI wrapper around isHookEnabled.
*
* Run with: node tests/hooks/check-hook-enabled.test.js
*/
const assert = require('assert');
const path = require('path');
const { spawnSync } = require('child_process');
const script = path.join(__dirname, '..', '..', 'scripts', 'hooks', 'check-hook-enabled.js');
function test(name, fn) {
try {
fn();
console.log(` \u2713 ${name}`);
return true;
} catch (err) {
console.log(` \u2717 ${name}`);
console.log(` Error: ${err.message}`);
return false;
}
}
function runScript(args = [], envOverrides = {}) {
const env = { ...process.env, ...envOverrides };
// Remove potentially interfering env vars unless explicitly set
if (!envOverrides.ECC_HOOK_PROFILE) delete env.ECC_HOOK_PROFILE;
if (!envOverrides.ECC_DISABLED_HOOKS) delete env.ECC_DISABLED_HOOKS;
const result = spawnSync('node', [script, ...args], {
encoding: 'utf8',
timeout: 10000,
env,
});
return {
code: result.status || 0,
stdout: result.stdout || '',
stderr: result.stderr || '',
};
}
function runTests() {
console.log('\n=== Testing check-hook-enabled.js ===\n');
let passed = 0;
let failed = 0;
console.log('No arguments:');
if (test('returns yes when no hookId provided', () => {
const result = runScript([]);
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
console.log('\nDefault profile (standard):');
if (test('returns yes for hook with default profiles', () => {
const result = runScript(['my-hook']);
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
if (test('returns yes for hook with standard,strict profiles', () => {
const result = runScript(['my-hook', 'standard,strict']);
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
if (test('returns no for hook with only strict profile', () => {
const result = runScript(['my-hook', 'strict']);
assert.strictEqual(result.stdout, 'no');
})) passed++; else failed++;
if (test('returns no for hook with only minimal profile', () => {
const result = runScript(['my-hook', 'minimal']);
assert.strictEqual(result.stdout, 'no');
})) passed++; else failed++;
console.log('\nDisabled hooks:');
if (test('returns no when hook is disabled via env', () => {
const result = runScript(['my-hook'], { ECC_DISABLED_HOOKS: 'my-hook' });
assert.strictEqual(result.stdout, 'no');
})) passed++; else failed++;
if (test('returns yes when different hook is disabled', () => {
const result = runScript(['my-hook'], { ECC_DISABLED_HOOKS: 'other-hook' });
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
console.log('\nProfile overrides:');
if (test('returns yes for strict profile with strict-only hook', () => {
const result = runScript(['my-hook', 'strict'], { ECC_HOOK_PROFILE: 'strict' });
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
if (test('returns yes for minimal profile with minimal-only hook', () => {
const result = runScript(['my-hook', 'minimal'], { ECC_HOOK_PROFILE: 'minimal' });
assert.strictEqual(result.stdout, 'yes');
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}
runTests();