Skip to content

Commit bf58ebc

Browse files
authored
fix(storage): nextToken is not surfaced when list result contain only CommonPrefix (#13933)
1 parent 971bec4 commit bf58ebc

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/storage/__tests__/providers/s3/apis/list.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,47 @@ describe('list API', () => {
506506
},
507507
);
508508

509+
it.each(pathTestCases)(
510+
'should list objects with CommonPrefix and nextToken in results with custom path: $path',
511+
async ({ path }) => {
512+
mockListObject.mockImplementationOnce(() => {
513+
return {
514+
CommonPrefixes: [
515+
{ Prefix: 'photos/2023/' },
516+
{ Prefix: 'photos/2024/' },
517+
{ Prefix: 'photos/2025/' },
518+
{ Prefix: 'photos/2026/' },
519+
{ Prefix: 'photos/2027/' },
520+
{ Prefix: 'photos/time-traveling/' },
521+
],
522+
NextContinuationToken: 'yup_there_is_more',
523+
};
524+
});
525+
const response = await listPaginatedWrapper({
526+
path: resolvePath(path),
527+
});
528+
expect(response.excludedSubpaths).toEqual([
529+
'photos/2023/',
530+
'photos/2024/',
531+
'photos/2025/',
532+
'photos/2026/',
533+
'photos/2027/',
534+
'photos/time-traveling/',
535+
]);
536+
537+
expect(response.nextToken).toEqual('yup_there_is_more');
538+
expect(listObjectsV2).toHaveBeenCalledTimes(1);
539+
await expect(listObjectsV2).toBeLastCalledWithConfigAndInput(
540+
listObjectClientConfig,
541+
{
542+
Bucket: bucket,
543+
MaxKeys: 1000,
544+
Prefix: resolvePath(path),
545+
},
546+
);
547+
},
548+
);
549+
509550
it.each(pathTestCases)(
510551
'should list all objects having three pages with custom path: $path',
511552
async ({ path: inputPath }) => {

packages/storage/src/providers/s3/apis/internal/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const _listWithPath = async ({
238238
if (!contents) {
239239
return {
240240
items: [],
241+
nextToken: nextContinuationToken,
241242
excludedSubpaths,
242243
};
243244
}

0 commit comments

Comments
 (0)