mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-11 03:38:07 +00:00
test(zig): absent-grammar case owns GITNEXUS_SKIP_OPTIONAL_GRAMMARS
The loader parses the opt-out variable lazily once per module copy, so under `GITNEXUS_SKIP_OPTIONAL_GRAMMARS=zig` (or `all`) — a supported way to run — the fresh loader took the opt-out branch and the "not the opt-out path" assertion failed before the absent-binding path ran. Clear the variable for the fresh module and restore it in `finally`, instead of returning early: the branch stays exercised in every environment. Verified: fails on the previous code under `=zig`, passes with and without the variable now.
This commit is contained in:
parent
d02f09c53a
commit
5819f73df4
1 changed files with 13 additions and 1 deletions
|
|
@ -745,7 +745,17 @@ describe('Tree-sitter multi-language parsing', () => {
|
|||
// `node:module` with a require that reports the package missing and
|
||||
// delegates everything else. A fresh module copy is needed because the
|
||||
// loader memoizes load results.
|
||||
//
|
||||
// The fresh copy also re-reads `GITNEXUS_SKIP_OPTIONAL_GRAMMARS` (parsed
|
||||
// lazily once per module). Under `=zig` / `=all` — a supported way to
|
||||
// run — the loader would take the opt-out branch and the absent-binding
|
||||
// path below would never run, so the variable is cleared for this test
|
||||
// and restored afterwards. Clearing (not skipping) keeps the branch
|
||||
// exercised in every environment.
|
||||
const ZIG_PKG = '@tree-sitter-grammars/tree-sitter-zig';
|
||||
const SKIP_ENV = 'GITNEXUS_SKIP_OPTIONAL_GRAMMARS';
|
||||
const savedSkip = process.env[SKIP_ENV];
|
||||
delete process.env[SKIP_ENV];
|
||||
vi.doMock('node:module', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('node:module')>();
|
||||
return {
|
||||
|
|
@ -767,7 +777,7 @@ describe('Tree-sitter multi-language parsing', () => {
|
|||
vi.resetModules();
|
||||
try {
|
||||
const fresh = await import('../../src/core/tree-sitter/parser-loader.js');
|
||||
// Not the opt-out path: the env is untouched.
|
||||
// Not the opt-out path: the variable was cleared above.
|
||||
expect(fresh.isGrammarRuntimeSkipped(SupportedLanguages.Zig)).toBe(false);
|
||||
expect(fresh.isLanguageAvailable(SupportedLanguages.Zig)).toBe(false);
|
||||
await expect(fresh.loadLanguage(SupportedLanguages.Zig)).rejects.toThrow(
|
||||
|
|
@ -776,6 +786,8 @@ describe('Tree-sitter multi-language parsing', () => {
|
|||
// Optional-grammar failure is non-fatal: the other grammars still load.
|
||||
expect(fresh.isLanguageAvailable(SupportedLanguages.TypeScript)).toBe(true);
|
||||
} finally {
|
||||
if (savedSkip === undefined) delete process.env[SKIP_ENV];
|
||||
else process.env[SKIP_ENV] = savedSkip;
|
||||
vi.doUnmock('node:module');
|
||||
vi.resetModules();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue