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' ;
66import assert from 'node:assert' ;
77import { 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
912describe ( '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