1
1
import type { S3 , SelectObjectContentEventStream , waitUntilObjectExists } 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 { Browser } from "happy-dom" ;
4
5
import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , onTestFailed , test as it } from "vitest" ;
5
6
6
7
import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources" ;
@@ -21,18 +22,26 @@ describe("@aws-sdk/client-s3", () => {
21
22
} ;
22
23
23
24
beforeAll ( async ( ) => {
25
+ const browser = new Browser ( ) ;
26
+ browser . settings . fetch . disableSameOriginPolicy = true ;
27
+
24
28
const integTestResourcesEnv = await getIntegTestResources ( ) ;
25
29
Object . assign ( process . env , integTestResourcesEnv ) ;
26
30
27
31
region = process ?. env ?. AWS_SMOKE_TEST_REGION as string ;
28
32
Bucket = process ?. env ?. AWS_SMOKE_TEST_BUCKET as string ;
29
33
mrapArn = ( globalThis as any ) ?. window ?. __env__ ?. AWS_SMOKE_TEST_MRAP_ARN || process ?. env ?. AWS_SMOKE_TEST_MRAP_ARN ;
30
34
35
+ const provider = fromNodeProviderChain ( ) ;
36
+ const credentials = await provider ( ) ;
37
+
31
38
client = new S3Impl (
32
39
getRuntimeConfig ( {
33
40
region,
34
- credentials : fromNodeProviderChain ( ) ,
35
- requestHandler : new FetchHttpHandler ( ) ,
41
+ credentials,
42
+ requestHandler : FetchHttpHandler . create ( {
43
+ credentials : "include" ,
44
+ } ) ,
36
45
logger : {
37
46
trace ( ) { } ,
38
47
debug ( ) { } ,
@@ -44,6 +53,24 @@ describe("@aws-sdk/client-s3", () => {
44
53
} ,
45
54
} )
46
55
) as unknown as S3 ;
56
+
57
+ client . middlewareStack . addRelativeTo (
58
+ ( next : any ) => async ( args : any ) => {
59
+ const result = await next ( args ) ;
60
+ const { response } = result ;
61
+ for ( const [ key , value ] of Object . entries ( response . headers ) ) {
62
+ delete response . headers [ key ] ;
63
+ response . headers [ String ( key ) . toLowerCase ( ) ] = value ;
64
+ }
65
+ return result ;
66
+ } ,
67
+ {
68
+ toMiddleware : "deserializerMiddleware" ,
69
+ name : "header-casing-middleware" ,
70
+ override : true ,
71
+ relation : "after" ,
72
+ }
73
+ ) ;
47
74
} ) ;
48
75
49
76
afterAll ( ( ) => {
@@ -66,10 +93,7 @@ describe("@aws-sdk/client-s3", () => {
66
93
67
94
const buf = createBuffer ( "1KB" ) ;
68
95
69
- // TODO(vitest)
70
- // Caused by: RequestContentLengthMismatchError: Request body length does not match content-length header
71
- // only in vitest + happy-dom.
72
- it . skip ( "should succeed with blob body" , async ( ) => {
96
+ it ( "should succeed with blob body" , async ( ) => {
73
97
onTestFailed ( setTestFailed ) ;
74
98
const blob = new Blob ( [ buf ] ) ;
75
99
const result = await client . putObject ( {
@@ -91,7 +115,10 @@ describe("@aws-sdk/client-s3", () => {
91
115
expect ( result . $metadata . httpStatusCode ) . toEqual ( 200 ) ;
92
116
} ) ;
93
117
94
- it ( "should succeed with ReadableStream body" , async ( ) => {
118
+ // TODO(vitest)
119
+ // Caused by: SignatureDoesNotMatch
120
+ // only in vitest + happy-dom.
121
+ it . skip ( "should succeed with ReadableStream body" , async ( ) => {
95
122
onTestFailed ( setTestFailed ) ;
96
123
const length = 10 * 1000 ; // 10KB
97
124
const chunkSize = 10 ;
@@ -170,9 +197,9 @@ describe("@aws-sdk/client-s3", () => {
170
197
expect ( result . Contents ) . toBeInstanceOf ( Array ) ;
171
198
} ) ;
172
199
173
- it ( "should throw with invalid bucket" , ( ) => {
200
+ it ( "should throw with invalid bucket" , async ( ) => {
174
201
onTestFailed ( setTestFailed ) ;
175
- expect ( ( ) => client . listObjects ( { Bucket : "invalid-bucket" } ) ) . rejects . toThrow ( ) ;
202
+ await expect ( ( ) => client . listObjects ( { Bucket : "invalid-bucket" } ) ) . rejects . toThrow ( ) ;
176
203
} ) ;
177
204
} ) ;
178
205
0 commit comments