Skip to content

Commit 137ba0a

Browse files
authored
Merge pull request #262 from Bijikyu/q/update-aftereach-to-delete-codex
Fix CODEX cleanup across tests
2 parents 9683761 + 594c6a6 commit 137ba0a

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

test/build-repeat.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ beforeEach(() => {
2121
afterEach(() => {
2222
process.chdir(path.resolve(__dirname, '..')); // restore original working directory after test
2323
fs.rmSync(tmpDir, {recursive: true, force: true}); // clean up temporary directory to avoid interference
24+
delete process.env.CODEX; // clear offline flag so later tests use default env
2425
});
2526

2627
describe('build run twice', {concurrency:false}, () => {

test/build.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const os = require('node:os'); // operating system utilities for temporary direc
2525
const {describe, it, beforeEach, afterEach} = require('node:test'); // Node.js native test framework components
2626
let build; // build function reference, assigned after module cache clearing
2727
let tmpDir; // temporary directory path for isolated test execution
28+
let prevCodex; // holds incoming CODEX value so tests can restore it after each run
2829

2930
/*
3031
* TEST SETUP CONFIGURATION
@@ -35,6 +36,7 @@ let tmpDir; // temporary directory path for isolated test execution
3536
* build artifacts. This approach guarantees reproducible test results.
3637
*/
3738
beforeEach(() => {
39+
prevCodex = process.env.CODEX; // snapshot incoming CODEX for restoration after test
3840
process.env.CODEX = 'True'; // forces offline mode to prevent network calls during testing
3941
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'buildtest-')); // creates unique temporary directory for test isolation
4042
fs.writeFileSync(path.join(tmpDir, 'qore.css'), 'body{}'); // minimal CSS input file for build processing
@@ -55,6 +57,7 @@ beforeEach(() => {
5557
afterEach(() => {
5658
process.chdir(path.resolve(__dirname, '..')); // restores original working directory
5759
fs.rmSync(tmpDir, {recursive: true, force: true}); // removes temporary directory and all contents
60+
if(prevCodex !== undefined){ process.env.CODEX = prevCodex; } else { delete process.env.CODEX; } // restore or clear CODEX to avoid cross-test pollution
5861
});
5962

6063
/*

test/integration.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const os = require('node:os'); // operating system utilities for temporary direc
2525
const {describe, it, before, after} = require('node:test'); // Node.js native test framework components
2626
let build, updateHtml; // script function references, assigned after module cache clearing
2727
let tmpDir; // temporary directory path for isolated test execution
28+
let prevCodex; // holds incoming CODEX value for cleanup after tests
2829

2930
/*
3031
* INTEGRATION TEST SETUP
@@ -35,6 +36,7 @@ let tmpDir; // temporary directory path for isolated test execution
3536
* conditions where build and HTML update scripts must coordinate perfectly.
3637
*/
3738
before(() => {
39+
prevCodex = process.env.CODEX; // record incoming CODEX for restoration
3840
process.env.CODEX = 'True'; // forces offline mode to prevent network dependencies
3941
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'integ-')); // creates unique temporary directory for test isolation
4042
fs.writeFileSync(path.join(tmpDir, 'qore.css'), 'body{}'); // minimal CSS input for build processing
@@ -57,6 +59,7 @@ before(() => {
5759
after(() => {
5860
process.chdir(path.resolve(__dirname, '..')); // restores original working directory
5961
fs.rmSync(tmpDir, {recursive: true, force: true}); // removes temporary directory and all contents
62+
if(prevCodex !== undefined){ process.env.CODEX = prevCodex; } else { delete process.env.CODEX; } // restore or clear CODEX after suite
6063
});
6164

6265
/*

0 commit comments

Comments
 (0)