Skip to content

Commit 982c814

Browse files
netrajpatelclaude
andcommitted
test(asset-management): fix flaky import assets test (unique temp dir) [DX-9770]
makeSpaceDir() used `am-test-${Date.now()}`, which collided when two tests ran within the same millisecond, so one test's asset index leaked into another's space dir. That intermittently made resolveAssetsChunkedLocation find an index in the 'empty space' test, skipping the empty-space branch and flaking expect(tickStub.callCount).to.equal(1) (seen as 'expected +0 to equal 1'). Use fsReal.mkdtempSync for a guaranteed-unique dir. Verified: 8/8 consecutive runs now 242 passing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NbgqgVDTDmh6c9LwDtMEf9
1 parent 5a96df9 commit 982c814

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/contentstack-asset-management/test/unit/import/assets.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ describe('ImportAssets', () => {
3333
afterEach(() => sinon.restore());
3434

3535
const makeSpaceDir = () => {
36-
const dir = path.join(os.tmpdir(), `am-test-${Date.now()}`);
36+
// mkdtempSync guarantees a unique dir. Using `am-test-${Date.now()}` collided when two
37+
// tests ran within the same millisecond, letting one test's asset index leak into
38+
// another — which intermittently skipped the "empty space" branch and flaked the
39+
// tick-count assertion.
40+
const dir = fsReal.mkdtempSync(path.join(os.tmpdir(), 'am-test-'));
3741
fsReal.mkdirSync(path.join(dir, 'assets'), { recursive: true });
3842
return dir;
3943
};

0 commit comments

Comments
 (0)