Skip to content

Commit b7e36b0

Browse files
committed
fix: update integration tests to use dynamic ES module imports
- Convert require() calls to dynamic import() for ES module compatibility - Add loadModule() helper function to cache module imports - Fix CI workflow test failures by resolving module import issues
1 parent 20e4063 commit b7e36b0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/integration.cjs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#!/usr/bin/env node
2-
const { init } = require('../dist/index.js');
32
const { promises: fs } = require('node:fs');
43
const { join } = require('node:path');
54
const { tmpdir } = require('node:os');
65

6+
let createClaudeModule;
7+
8+
async function loadModule() {
9+
if (!createClaudeModule) {
10+
createClaudeModule = await import('../dist/index.js');
11+
}
12+
return createClaudeModule;
13+
}
14+
715
async function createTempDir() {
816
const tempDir = join(tmpdir(), `create-claude-test-${Date.now()}`);
917
await fs.mkdir(tempDir, { recursive: true });
@@ -22,6 +30,7 @@ async function testBasicInit() {
2230
const testDir = await createTempDir();
2331

2432
try {
33+
const { init } = await loadModule();
2534
const result = await init(testDir);
2635

2736
if (!result.success) {
@@ -117,6 +126,7 @@ async function testDryRun() {
117126
const testDir = await createTempDir();
118127

119128
try {
129+
const { init } = await loadModule();
120130
const result = await init(testDir, { dryRun: true });
121131

122132
if (!result.success) {
@@ -156,6 +166,7 @@ async function testExistingFiles() {
156166
await fs.mkdir(join(testDir, '.claude'), { recursive: true });
157167
await fs.writeFile(join(testDir, '.claude', 'settings.local.json'), existingSettingsContent);
158168

169+
const { init } = await loadModule();
159170
const result = await init(testDir);
160171

161172
if (!result.success) {
@@ -205,6 +216,7 @@ async function testInvalidDirectory() {
205216
console.log('Testing error handling with invalid directory...');
206217

207218
try {
219+
const { init } = await loadModule();
208220
const result = await init('/nonexistent/directory/that/should/not/exist');
209221

210222
if (result.success) {
@@ -239,6 +251,7 @@ async function testAtomicOperations() {
239251
const crypto = require('crypto');
240252
const originalHash = crypto.createHash('sha256').update(originalContent).digest('hex');
241253

254+
const { init } = await loadModule();
242255
const result = await init(testDir);
243256

244257
if (!result.success) {
@@ -283,6 +296,7 @@ async function testConcurrentInit() {
283296
const testDir = await createTempDir();
284297

285298
try {
299+
const { init } = await loadModule();
286300
const results = await Promise.allSettled([
287301
init(testDir),
288302
init(testDir),
@@ -335,6 +349,7 @@ async function testInterruptHandling() {
335349
try {
336350
await fs.writeFile(join(testDir, 'CLAUDE.md'), 'ORIGINAL');
337351

352+
const { init } = await loadModule();
338353
const initPromise = init(testDir);
339354
process.nextTick(() => {
340355
process.emit('SIGINT');
@@ -364,6 +379,7 @@ async function testLargeFiles() {
364379
await fs.writeFile(join(testDir, 'CLAUDE.md'), largeContent);
365380

366381
const memBefore = process.memoryUsage().heapUsed;
382+
const { init } = await loadModule();
367383
const result = await init(testDir);
368384
const memAfter = process.memoryUsage().heapUsed;
369385

@@ -392,6 +408,7 @@ async function testWriteFailure() {
392408
await fs.writeFile(roFile, 'locked');
393409
await fs.chmod(roFile, 0o444);
394410

411+
const { init } = await loadModule();
395412
await init(testDir, { silent: true }).catch(() => {});
396413

397414
await fs.chmod(roFile, 0o644).catch(() => {});
@@ -404,7 +421,7 @@ async function testWriteFailure() {
404421

405422
async function testAtomicFunctions() {
406423
console.log('Testing atomic operations directly...');
407-
const { withRetry, atomicWrite, atomicCopy, TransactionLog } = require('../dist/index.js');
424+
const { withRetry, atomicWrite, atomicCopy, TransactionLog } = await loadModule();
408425
const testDir = await createTempDir();
409426

410427
try {
@@ -461,7 +478,7 @@ async function testAtomicFunctions() {
461478

462479
async function testUtilityFunctions() {
463480
console.log('Testing utility functions directly...');
464-
const { detectPackageManager, detectRuntime, detectFramework, exists } = require('../dist/index.js');
481+
const { detectPackageManager, detectRuntime, detectFramework, exists } = await loadModule();
465482
const testDir = await createTempDir();
466483

467484
try {
@@ -504,7 +521,7 @@ async function testUtilityFunctions() {
504521

505522
async function testTemplateRendering() {
506523
console.log('Testing template rendering functions...');
507-
const { renderTemplate, validateTemplateVariables } = require('../dist/index.js');
524+
const { renderTemplate, validateTemplateVariables } = await loadModule();
508525

509526
try {
510527
const template = 'Project: {{PROJECT_NAME}}, runtime is {{RUNTIME}}!';
@@ -533,7 +550,7 @@ async function testTemplateRendering() {
533550

534551
async function testCommandExecution() {
535552
console.log('Testing command execution functions...');
536-
const { execute, executeQuiet, executeWithRetry } = require('../dist/index.js');
553+
const { execute, executeQuiet, executeWithRetry } = await loadModule();
537554
const testDir = await createTempDir();
538555

539556
try {

0 commit comments

Comments
 (0)