@@ -3,7 +3,7 @@ import { join } from "node:path";
33import { suite , test , assert , beforeAll , beforeEach , afterAll , expect } from "vitest" ;
44
55import { setupAsyncTest } from "../helpers.js" ;
6- import { AsyncFunction , LOCAL_TEST_COMPONENTS_DIR } from "../common.js" ;
6+ import { AsyncFunction , LOCAL_TEST_COMPONENTS_DIR , checkStreamValues } from "../common.js" ;
77import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation" ;
88
99suite ( "stream<T> lifts" , ( ) => {
@@ -124,9 +124,9 @@ suite("stream<T> lifts", () => {
124124
125125 let invalidVals = [ - 1 , 256 ] ;
126126 for ( const invalid of invalidVals ) {
127- await expect ( ( ) =>
128- instance [ "jco:test-components/get-stream-async" ] . getStreamU8 ( [ invalid ] ) ,
129- ) . rejects . toThrow ( / i n v a l i d u 8 v a l u e / ) ;
127+ await expect ( ( ) => instance [ "jco:test-components/get-stream-async" ] . getStreamU8 ( [ invalid ] ) ) . rejects . toThrow (
128+ / i n v a l i d u 8 v a l u e / ,
129+ ) ;
130130 }
131131
132132 vals = [ - 11 , - 22 , - 33 , - 128 , 127 ] ;
@@ -135,9 +135,9 @@ suite("stream<T> lifts", () => {
135135
136136 invalidVals = [ - 129 , 128 ] ;
137137 for ( const invalid of invalidVals ) {
138- await expect ( ( ) =>
139- instance [ "jco:test-components/get-stream-async" ] . getStreamS8 ( [ invalid ] ) ,
140- ) . rejects . toThrow ( / i n v a l i d s 8 v a l u e / ) ;
138+ await expect ( ( ) => instance [ "jco:test-components/get-stream-async" ] . getStreamS8 ( [ invalid ] ) ) . rejects . toThrow (
139+ / i n v a l i d s 8 v a l u e / ,
140+ ) ;
141141 }
142142 } ) ;
143143
@@ -291,6 +291,7 @@ suite("stream<T> lifts", () => {
291291 assert . instanceOf ( instance [ "jco:test-components/get-stream-async" ] . getStreamListU8 , AsyncFunction ) ;
292292 let vals = [ [ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 ] , new Uint8Array ( [ 0x05 , 0x04 , 0x03 , 0x02 , 0x01 ] ) , [ ] ] ;
293293 let stream = await instance [ "jco:test-components/get-stream-async" ] . getStreamListU8 ( vals ) ;
294+
294295 await checkStreamValues ( {
295296 stream,
296297 vals,
@@ -305,6 +306,8 @@ suite("stream<T> lifts", () => {
305306 } ) ;
306307 } ) ;
307308
309+ // TODO(fix): add tests for optimized UintXArrays (js_array_ty)
310+
308311 test . concurrent ( "list<string>" , async ( ) => {
309312 assert . instanceOf ( instance [ "jco:test-components/get-stream-async" ] . getStreamListString , AsyncFunction ) ;
310313 let vals = [ [ "first" , "second" , "third" ] , [ ] ] ;
@@ -429,28 +432,3 @@ suite("stream<T> lifts", () => {
429432 assert . isUndefined ( value ) ;
430433 } ) ;
431434} ) ;
432-
433- async function checkStreamValues ( args ) {
434- const { stream, vals, typeName, assertEqFn, partial } = args ?? { } ;
435- const expectedValues = args . expectedValues ?? [ ] ;
436-
437- // Ensure the values produced match expected
438- const eq = assertEqFn ?? assert . equal ;
439- let iteratorRes ;
440- for ( const [ idx , v ] of vals . entries ( ) ) {
441- const expected = expectedValues [ idx ] ?? v ;
442- iteratorRes = await stream . next ( ) ;
443- assert . isFalse ( iteratorRes . done ) ;
444- eq ( iteratorRes . value , expected , `${ typeName } [${ idx } ] read is incorrect` ) ;
445- }
446-
447- // If dealing with a partial list of values from the stream, do not attempt to read the last value
448- if ( partial ) {
449- return ;
450- }
451-
452- // Ensure the next value is undefined (and the iterator is done)
453- iteratorRes = await stream . next ( ) ;
454- assert . isUndefined ( iteratorRes . value ) ;
455- assert . isTrue ( iteratorRes . done ) ;
456- }
0 commit comments