diff --git a/packages/storage/__tests__/providers/s3/apis/list.test.ts b/packages/storage/__tests__/providers/s3/apis/list.test.ts index a13ae54b5a4..e01096a1113 100644 --- a/packages/storage/__tests__/providers/s3/apis/list.test.ts +++ b/packages/storage/__tests__/providers/s3/apis/list.test.ts @@ -506,6 +506,47 @@ describe('list API', () => { }, ); + it.each(pathTestCases)( + 'should list objects with CommonPrefix and nextToken in results with custom path: $path', + async ({ path }) => { + mockListObject.mockImplementationOnce(() => { + return { + CommonPrefixes: [ + { Prefix: 'photos/2023/' }, + { Prefix: 'photos/2024/' }, + { Prefix: 'photos/2025/' }, + { Prefix: 'photos/2026/' }, + { Prefix: 'photos/2027/' }, + { Prefix: 'photos/time-traveling/' }, + ], + NextContinuationToken: 'yup_there_is_more', + }; + }); + const response = await listPaginatedWrapper({ + path: resolvePath(path), + }); + expect(response.excludedSubpaths).toEqual([ + 'photos/2023/', + 'photos/2024/', + 'photos/2025/', + 'photos/2026/', + 'photos/2027/', + 'photos/time-traveling/', + ]); + + expect(response.nextToken).toEqual('yup_there_is_more'); + expect(listObjectsV2).toHaveBeenCalledTimes(1); + await expect(listObjectsV2).toBeLastCalledWithConfigAndInput( + listObjectClientConfig, + { + Bucket: bucket, + MaxKeys: 1000, + Prefix: resolvePath(path), + }, + ); + }, + ); + it.each(pathTestCases)( 'should list all objects having three pages with custom path: $path', async ({ path: inputPath }) => { diff --git a/packages/storage/src/providers/s3/apis/internal/list.ts b/packages/storage/src/providers/s3/apis/internal/list.ts index bbcb342a603..5b41b1f3a23 100644 --- a/packages/storage/src/providers/s3/apis/internal/list.ts +++ b/packages/storage/src/providers/s3/apis/internal/list.ts @@ -238,6 +238,7 @@ const _listWithPath = async ({ if (!contents) { return { items: [], + nextToken: nextContinuationToken, excludedSubpaths, }; }