Skip to content

Commit 7c009c2

Browse files
Copilotvobu
andcommitted
test: fix unit tests to run with proper isolation
Co-authored-by: vobu <6573426+vobu@users.noreply.github.com>
1 parent 7e16895 commit 7c009c2

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

tests/unit/config.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,14 @@ describe('Config Module', () => {
187187
mkdirSync(testDir, { recursive: true });
188188
originalEnv = { ...process.env };
189189
process.env.XDG_DATA_HOME = testDir;
190-
// Clear Camunda env vars
190+
// Clear all Camunda env vars to ensure test isolation
191191
delete process.env.CAMUNDA_BASE_URL;
192192
delete process.env.CAMUNDA_CLIENT_ID;
193+
delete process.env.CAMUNDA_CLIENT_SECRET;
194+
delete process.env.CAMUNDA_AUDIENCE;
195+
delete process.env.CAMUNDA_OAUTH_URL;
196+
delete process.env.CAMUNDA_USERNAME;
197+
delete process.env.CAMUNDA_PASSWORD;
193198
delete process.env.CAMUNDA_DEFAULT_TENANT_ID;
194199
});
195200

@@ -238,7 +243,9 @@ describe('Config Module', () => {
238243
test('resolveClusterConfig falls back to localhost', () => {
239244
const config = resolveClusterConfig();
240245

241-
assert.strictEqual(config.baseUrl, 'http://localhost:8080');
246+
assert.strictEqual(config.baseUrl, 'http://localhost:8080/v2');
247+
assert.strictEqual(config.username, 'demo');
248+
assert.strictEqual(config.password, 'demo');
242249
});
243250

244251
test('resolveTenantId uses session tenant first', () => {

tests/unit/deployment-validation.test.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,49 @@
22
* Unit tests for deployment command validation
33
*/
44

5-
import { test, describe } from 'node:test';
5+
import { test, describe, beforeEach, afterEach } from 'node:test';
66
import assert from 'node:assert';
77
import { execSync } from 'node:child_process';
8+
import { join } from 'node:path';
9+
import { mkdirSync, rmSync, existsSync } from 'node:fs';
10+
import { tmpdir } from 'node:os';
811

912
describe('Deployment Validation', () => {
13+
let testDir: string;
14+
let originalEnv: NodeJS.ProcessEnv;
15+
16+
beforeEach(() => {
17+
// Create isolated test directory for session/profile data
18+
testDir = join(tmpdir(), `c8ctl-deploy-test-${Date.now()}`);
19+
mkdirSync(testDir, { recursive: true });
20+
originalEnv = { ...process.env };
21+
process.env.XDG_DATA_HOME = testDir;
22+
// Clear all Camunda env vars to ensure test isolation
23+
delete process.env.CAMUNDA_BASE_URL;
24+
delete process.env.CAMUNDA_CLIENT_ID;
25+
delete process.env.CAMUNDA_CLIENT_SECRET;
26+
delete process.env.CAMUNDA_AUDIENCE;
27+
delete process.env.CAMUNDA_OAUTH_URL;
28+
delete process.env.CAMUNDA_USERNAME;
29+
delete process.env.CAMUNDA_PASSWORD;
30+
delete process.env.CAMUNDA_DEFAULT_TENANT_ID;
31+
});
32+
33+
afterEach(() => {
34+
if (existsSync(testDir)) {
35+
rmSync(testDir, { recursive: true, force: true });
36+
}
37+
process.env = originalEnv;
38+
});
39+
1040
test('detects duplicate process IDs', () => {
1141
// Attempt to deploy directory with duplicate process IDs should fail
1242
try {
13-
execSync('node src/index.ts deploy tests/fixtures/duplicate-ids', {
43+
execSync('npm run cli -- deploy tests/fixtures/duplicate-ids', {
1444
cwd: process.cwd(),
1545
encoding: 'utf-8',
16-
stdio: 'pipe'
46+
stdio: 'pipe',
47+
env: process.env
1748
});
1849
assert.fail('Should have thrown an error for duplicate process IDs');
1950
} catch (error: any) {
@@ -33,11 +64,12 @@ describe('Deployment Validation', () => {
3364
// This test requires a running Camunda instance
3465
// Just verify the command doesn't fail on validation (may fail on connection)
3566
try {
36-
execSync('node src/index.ts deploy tests/fixtures/simple.bpmn', {
67+
execSync('npm run cli -- deploy tests/fixtures/simple.bpmn', {
3768
cwd: process.cwd(),
3869
encoding: 'utf-8',
3970
stdio: 'pipe',
40-
timeout: 5000
71+
timeout: 5000,
72+
env: process.env
4173
});
4274
// If Camunda is running, this should succeed
4375
assert.ok(true);
@@ -52,11 +84,12 @@ describe('Deployment Validation', () => {
5284
test('allows deployment of different process IDs', () => {
5385
// Deploy fixtures that have different process IDs
5486
try {
55-
execSync('node src/index.ts deploy tests/fixtures/sample-project', {
87+
execSync('npm run cli -- deploy tests/fixtures/sample-project', {
5688
cwd: process.cwd(),
5789
encoding: 'utf-8',
5890
stdio: 'pipe',
59-
timeout: 5000
91+
timeout: 5000,
92+
env: process.env
6093
});
6194
// If Camunda is running, this should succeed
6295
assert.ok(true);

0 commit comments

Comments
 (0)