@@ -11,8 +11,7 @@ import { S3, SelectObjectContentEventStream } from "../../src/index";
11
11
import { createBuffer } from "./helpers" ;
12
12
chai . use ( chaiAsPromised ) ;
13
13
const { expect } = chai ;
14
- // There will be default values of defaultRegion, credentials, and isBrowser variable in browser tests.
15
- // Define the values for Node.js tests
14
+
16
15
const region : string | undefined = ( globalThis as any ) . defaultRegion || process ?. env ?. AWS_SMOKE_TEST_REGION ;
17
16
const credentials : Credentials | undefined = ( globalThis as any ) . credentials || undefined ;
18
17
const isBrowser : boolean | undefined = ( globalThis as any ) . isBrowser || false ;
@@ -21,7 +20,7 @@ const mrapArn = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_MRAP_ARN ||
21
20
22
21
let Key = `${ Date . now ( ) } ` ;
23
22
24
- describe ( "@aws-sdk/client-s3" , ( ) => {
23
+ ( isBrowser ? describe : xdescribe ) ( "@aws-sdk/client-s3" , ( ) => {
25
24
const client = new S3 ( {
26
25
region : region ,
27
26
credentials,
@@ -34,81 +33,51 @@ describe("@aws-sdk/client-s3", () => {
34
33
after ( async ( ) => {
35
34
await client . deleteObject ( { Bucket, Key } ) ;
36
35
} ) ;
37
- if ( isBrowser ) {
38
- const buf = createBuffer ( "1KB" ) ;
39
- it ( "should succeed with blob body" , async ( ) => {
40
- const result = await client . putObject ( {
41
- Bucket,
42
- Key,
43
- Body : new Blob ( [ buf ] ) ,
44
- } ) ;
45
- expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
36
+ const buf = createBuffer ( "1KB" ) ;
37
+ it ( "should succeed with blob body" , async ( ) => {
38
+ const result = await client . putObject ( {
39
+ Bucket,
40
+ Key,
41
+ Body : new Blob ( [ buf ] ) ,
46
42
} ) ;
43
+ expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
44
+ } ) ;
47
45
48
- it ( "should succeed with TypedArray body" , async ( ) => {
49
- const result = await client . putObject ( {
50
- Bucket,
51
- Key,
52
- Body : buf ,
53
- } ) ;
54
- expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
46
+ it ( "should succeed with TypedArray body" , async ( ) => {
47
+ const result = await client . putObject ( {
48
+ Bucket,
49
+ Key,
50
+ Body : buf ,
55
51
} ) ;
52
+ expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
53
+ } ) ;
56
54
57
- // todo: fix needed
58
- // todo: TypeError: Failed to construct 'Request': The `duplex` member must
59
- // todo: be specified for a request with a streaming body
60
- it . skip ( "should succeed with ReadableStream body" , async ( ) => {
61
- const length = 10 * 1000 ; // 10KB
62
- const chunkSize = 10 ;
63
- const readableStream = new ReadableStream ( {
64
- start ( controller ) {
65
- let sizeLeft = length ;
66
- while ( sizeLeft > 0 ) {
67
- let chunk = "" ;
68
- for ( let i = 0 ; i < Math . min ( sizeLeft , chunkSize ) ; i ++ ) {
69
- chunk += "x" ;
70
- }
71
- controller . enqueue ( chunk ) ;
72
- sizeLeft -= chunk . length ;
73
- }
74
- } ,
75
- } ) ;
76
- const result = await client . putObject ( {
77
- Bucket,
78
- Key,
79
- Body : readableStream ,
80
- } ) ;
81
- expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
82
- } ) ;
83
- } else {
84
- it ( "should succeed with Node.js readable stream body" , async ( ) => {
85
- const length = 10 * 1000 ; // 10KB
86
- const chunkSize = 10 ;
87
- const { Readable } = require ( "stream" ) ;
88
- let sizeLeft = length ;
89
- const inputStream = new Readable ( {
90
- read ( ) {
91
- if ( sizeLeft <= 0 ) {
92
- this . push ( null ) ; //end stream;
93
- return ;
94
- }
55
+ // todo: fix needed
56
+ // todo: TypeError: Failed to construct 'Request': The `duplex` member must
57
+ // todo: be specified for a request with a streaming body
58
+ it . skip ( "should succeed with ReadableStream body" , async ( ) => {
59
+ const length = 10 * 1000 ; // 10KB
60
+ const chunkSize = 10 ;
61
+ const readableStream = new ReadableStream ( {
62
+ start ( controller ) {
63
+ let sizeLeft = length ;
64
+ while ( sizeLeft > 0 ) {
95
65
let chunk = "" ;
96
66
for ( let i = 0 ; i < Math . min ( sizeLeft , chunkSize ) ; i ++ ) {
97
67
chunk += "x" ;
98
68
}
99
- this . push ( chunk ) ;
69
+ controller . enqueue ( chunk ) ;
100
70
sizeLeft -= chunk . length ;
101
- } ,
102
- } ) ;
103
- inputStream . size = length ; // This is required
104
- const result = await client . putObject ( {
105
- Bucket,
106
- Key,
107
- Body : inputStream ,
108
- } ) ;
109
- expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
71
+ }
72
+ } ,
73
+ } ) ;
74
+ const result = await client . putObject ( {
75
+ Bucket,
76
+ Key,
77
+ Body : readableStream ,
110
78
} ) ;
111
- }
79
+ expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
80
+ } ) ;
112
81
} ) ;
113
82
114
83
describe ( "GetObject" , function ( ) {
@@ -141,12 +110,7 @@ describe("@aws-sdk/client-s3", () => {
141
110
}
142
111
143
112
expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
144
- if ( isBrowser ) {
145
- expect ( result . Body ) . to . be . instanceOf ( ReadableStream ) ;
146
- } else {
147
- const { Readable } = require ( "stream" ) ;
148
- expect ( result . Body ) . to . be . instanceOf ( Readable ) ;
149
- }
113
+ expect ( result . Body ) . to . be . instanceOf ( ReadableStream ) ;
150
114
} ) ;
151
115
} ) ;
152
116
@@ -310,34 +274,17 @@ esfuture,29`;
310
274
describe ( "Multi-region access point" , ( ) => {
311
275
before ( async ( ) => {
312
276
Key = `${ Date . now ( ) } ` ;
313
- if ( ! isBrowser ) {
314
- await client . putObject ( { Bucket : mrapArn , Key, Body : "foo" } ) ;
315
- }
316
277
} ) ;
317
- after ( async ( ) => {
318
- if ( ! isBrowser ) {
319
- await client . deleteObject ( { Bucket : mrapArn , Key } ) ;
320
- }
321
- } ) ;
322
- if ( isBrowser ) {
323
- it ( "should throw for aws-crt no available in browser" , async ( ) => {
324
- try {
325
- await client . listObjects ( {
326
- Bucket : mrapArn ,
327
- } ) ;
328
- expect . fail ( "MRAP call in browser should throw" ) ;
329
- } catch ( e ) {
330
- expect ( e . message ) . include ( "only available in Node.js" ) ;
331
- }
332
- } ) ;
333
- } else {
334
- it ( "should succeed with valid MRAP ARN" , async ( ) => {
335
- const result = await client . listObjects ( {
278
+ after ( async ( ) => { } ) ;
279
+ it ( "should throw for aws-crt no available in browser" , async ( ) => {
280
+ try {
281
+ await client . listObjects ( {
336
282
Bucket : mrapArn ,
337
283
} ) ;
338
- expect ( result . $metadata . httpStatusCode ) . to . equal ( 200 ) ;
339
- expect ( result . Contents ) . to . be . instanceOf ( Array ) ;
340
- } ) ;
341
- }
284
+ expect . fail ( "MRAP call in browser should throw" ) ;
285
+ } catch ( e ) {
286
+ expect ( e . message ) . include ( "only available in Node.js" ) ;
287
+ }
288
+ } ) ;
342
289
} ) ;
343
290
} ) ;
0 commit comments