Skip to content

Commit e35cfd5

Browse files
scenario: fix flaky time-based distinct filename test, extension consistency
1 parent 8261eee commit e35cfd5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/scenario/test/instance-attachments/binary-output.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ describe('Instance attachments: binary output', () => {
456456

457457
const { scenario, uploads } = await initDistinctFileNamesScenario({
458458
fileNameFactory: ({ nodeId, basename, extension }) => {
459-
return `${basename}-${stripNodeIDPrefix(nodeId)}${extension}`;
459+
return `${basename}-${stripNodeIDPrefix(nodeId)}${extension ?? ''}`;
460460
},
461461
});
462462

@@ -513,18 +513,24 @@ describe('Instance attachments: binary output', () => {
513513
});
514514

515515
it('populates metadata about when the file was written', async () => {
516-
const unixTime = (date: Date): number => date.getSeconds();
516+
const timestampedFileName = (
517+
basename: string,
518+
extension: string | null,
519+
writtenAt: Date
520+
): string => {
521+
return `${basename}-${writtenAt.getTime()}${extension ?? ''}`;
522+
};
517523

518524
const { scenario, uploads } = await initDistinctFileNamesScenario({
519525
fileNameFactory: ({ writtenAt, basename, extension }) => {
520-
return `${basename}-${unixTime(writtenAt)}${extension}`;
526+
return timestampedFileName(basename, extension, writtenAt);
521527
},
522528
});
523529

524530
const expectedFileName = (index: 0 | 1 | 2 | 3): string => {
525531
const { uploadedAt } = uploads[index];
526532

527-
return `${INDISTINGUISHABLE_BASE_NAME}-${unixTime(uploadedAt)}.txt`;
533+
return timestampedFileName(INDISTINGUISHABLE_BASE_NAME, '.txt', uploadedAt);
528534
};
529535

530536
const expectedFileNames = [

0 commit comments

Comments
 (0)