1
1
import type { S3 , SelectObjectContentEventStream } from "@aws-sdk/client-s3" ;
2
2
import { fromNodeProviderChain } from "@aws-sdk/credential-providers" ;
3
3
import { FetchHttpHandler } from "@smithy/fetch-http-handler" ;
4
- import { afterEach , beforeAll , beforeEach , describe , expect , test as it } from "vitest" ;
4
+ import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , onTestFailed , test as it } from "vitest" ;
5
5
6
6
import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources" ;
7
7
import { getRuntimeConfig } from "../../src/runtimeConfig.browser" ;
8
- import { S3 as S3Impl } from "../browser-build/browser-s3-bundle" ;
8
+ import { S3 as S3Impl , waitUntilObjectExists } from "../browser-build/browser-s3-bundle" ;
9
9
import { createBuffer } from "./helpers" ;
10
10
11
11
describe ( "@aws-sdk/client-s3" , ( ) => {
@@ -14,6 +14,11 @@ describe("@aws-sdk/client-s3", () => {
14
14
let region : string ;
15
15
let mrapArn : string ;
16
16
let Key = `${ Date . now ( ) } ` ;
17
+ const errors = [ ] as any [ ] ;
18
+ let testFailed = false ;
19
+ const setTestFailed = ( ) => {
20
+ testFailed = true ;
21
+ } ;
17
22
18
23
beforeAll ( async ( ) => {
19
24
const integTestResourcesEnv = await getIntegTestResources ( ) ;
@@ -28,10 +33,28 @@ describe("@aws-sdk/client-s3", () => {
28
33
region,
29
34
credentials : fromNodeProviderChain ( ) ,
30
35
requestHandler : new FetchHttpHandler ( ) ,
36
+ logger : {
37
+ trace ( ) { } ,
38
+ debug ( ) { } ,
39
+ info ( ) { } ,
40
+ warn ( ) { } ,
41
+ error ( entry : any ) {
42
+ errors . push ( entry ) ;
43
+ } ,
44
+ } ,
31
45
} )
32
46
) as unknown as S3 ;
33
47
} ) ;
34
48
49
+ afterAll ( ( ) => {
50
+ if ( testFailed ) {
51
+ console . info ( "Test failed, logging errors collecting during test." ) ;
52
+ for ( const error of errors ) {
53
+ console . error ( error ) ;
54
+ }
55
+ }
56
+ } ) ;
57
+
35
58
describe ( "PutObject" , ( ) => {
36
59
beforeEach ( ( ) => {
37
60
Key = `${ Date . now ( ) } ` ;
@@ -47,6 +70,7 @@ describe("@aws-sdk/client-s3", () => {
47
70
// Caused by: RequestContentLengthMismatchError: Request body length does not match content-length header
48
71
// only in vitest + happy-dom.
49
72
it . skip ( "should succeed with blob body" , async ( ) => {
73
+ onTestFailed ( setTestFailed ) ;
50
74
const blob = new Blob ( [ buf ] ) ;
51
75
const result = await client . putObject ( {
52
76
Bucket,
@@ -58,6 +82,7 @@ describe("@aws-sdk/client-s3", () => {
58
82
} ) ;
59
83
60
84
it ( "should succeed with TypedArray body" , async ( ) => {
85
+ onTestFailed ( setTestFailed ) ;
61
86
const result = await client . putObject ( {
62
87
Bucket,
63
88
Key,
@@ -67,6 +92,7 @@ describe("@aws-sdk/client-s3", () => {
67
92
} ) ;
68
93
69
94
it ( "should succeed with ReadableStream body" , async ( ) => {
95
+ onTestFailed ( setTestFailed ) ;
70
96
const length = 10 * 1000 ; // 10KB
71
97
const chunkSize = 10 ;
72
98
const readableStream = new ReadableStream ( {
@@ -102,6 +128,7 @@ describe("@aws-sdk/client-s3", () => {
102
128
} ) ;
103
129
104
130
it ( "should succeed with valid body payload" , async ( ) => {
131
+ onTestFailed ( setTestFailed ) ;
105
132
// prepare the object.
106
133
const body = createBuffer ( "1MB" ) ;
107
134
@@ -133,7 +160,9 @@ describe("@aws-sdk/client-s3", () => {
133
160
afterEach ( async ( ) => {
134
161
await client . deleteObject ( { Bucket, Key } ) ;
135
162
} ) ;
163
+
136
164
it ( "should succeed with valid bucket" , async ( ) => {
165
+ onTestFailed ( setTestFailed ) ;
137
166
const result = await client . listObjects ( {
138
167
Bucket,
139
168
} ) ;
@@ -142,6 +171,7 @@ describe("@aws-sdk/client-s3", () => {
142
171
} ) ;
143
172
144
173
it ( "should throw with invalid bucket" , ( ) => {
174
+ onTestFailed ( setTestFailed ) ;
145
175
expect ( ( ) => client . listObjects ( { Bucket : "invalid-bucket" } ) ) . rejects . toThrow ( ) ;
146
176
} ) ;
147
177
} ) ;
@@ -150,9 +180,11 @@ describe("@aws-sdk/client-s3", () => {
150
180
let UploadId : string ;
151
181
let Etag : string ;
152
182
const multipartObjectKey = `${ Key } -multipart` ;
183
+
153
184
beforeEach ( ( ) => {
154
185
Key = `${ Date . now ( ) } ` ;
155
186
} ) ;
187
+
156
188
afterEach ( async ( ) => {
157
189
if ( UploadId ) {
158
190
await client . abortMultipartUpload ( {
@@ -168,7 +200,9 @@ describe("@aws-sdk/client-s3", () => {
168
200
} ) ;
169
201
170
202
it ( "should successfully create, upload list and complete" , async ( ) => {
171
- //create multipart upload
203
+ onTestFailed ( setTestFailed ) ;
204
+
205
+ // create multipart upload
172
206
const createResult = await client . createMultipartUpload ( {
173
207
Bucket,
174
208
Key : multipartObjectKey ,
@@ -209,15 +243,23 @@ describe("@aws-sdk/client-s3", () => {
209
243
expect ( completeResult . $metadata . httpStatusCode ) . toEqual ( 200 ) ;
210
244
211
245
//validate the object is uploaded
212
- const headResult = await client . headObject ( {
213
- Bucket,
214
- Key : multipartObjectKey ,
215
- } ) ;
216
- expect ( headResult . $metadata . httpStatusCode ) . toEqual ( 200 ) ;
246
+ const waiterState = await waitUntilObjectExists (
247
+ {
248
+ client,
249
+ maxWaitTime : 60 ,
250
+ } ,
251
+ {
252
+ Bucket,
253
+ Key : multipartObjectKey ,
254
+ }
255
+ ) ;
256
+ expect ( waiterState . state ) . toEqual ( "SUCCESS" ) ;
217
257
} ) ;
218
258
219
259
it ( "should successfully create, abort, and list upload" , async ( ) => {
220
- //create multipart upload
260
+ onTestFailed ( setTestFailed ) ;
261
+
262
+ // create multipart upload
221
263
const createResult = await client . createMultipartUpload ( {
222
264
Bucket,
223
265
Key : multipartObjectKey ,
@@ -248,14 +290,18 @@ describe("@aws-sdk/client-s3", () => {
248
290
jsrocks,13
249
291
node4life,22
250
292
esfuture,29` ;
293
+
251
294
beforeEach ( async ( ) => {
252
295
Key = `${ Date . now ( ) } ` ;
253
296
await client . putObject ( { Bucket, Key, Body : csvFile } ) ;
254
297
} ) ;
298
+
255
299
afterEach ( async ( ) => {
256
300
await client . deleteObject ( { Bucket, Key } ) ;
257
301
} ) ;
302
+
258
303
it ( "should succeed" , async ( ) => {
304
+ onTestFailed ( setTestFailed ) ;
259
305
const { Payload } = await client . selectObjectContent ( {
260
306
Bucket,
261
307
Key,
@@ -287,8 +333,9 @@ esfuture,29`;
287
333
beforeEach ( async ( ) => {
288
334
Key = `${ Date . now ( ) } ` ;
289
335
} ) ;
290
- afterEach ( async ( ) => { } ) ;
336
+
291
337
it ( "should throw for aws-crt no available in browser" , async ( ) => {
338
+ onTestFailed ( setTestFailed ) ;
292
339
try {
293
340
await client . listObjects ( {
294
341
Bucket : mrapArn ,
@@ -299,4 +346,4 @@ esfuture,29`;
299
346
}
300
347
} ) ;
301
348
} ) ;
302
- } ) ;
349
+ } , 60_000 ) ;
0 commit comments