11// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
22
3- import { assert } from "../../../test_util/std/testing/asserts.ts" ;
3+ import { assert , fail } from "../../../test_util/std/testing/asserts.ts" ;
44import { fromFileUrl , relative } from "../../../test_util/std/path/mod.ts" ;
55import { pipeline } from "node:stream/promises" ;
6+ import { Writable } from "node:stream" ;
67import { createReadStream , createWriteStream } from "node:fs" ;
78
89Deno . test ( "stream/promises pipeline" , async ( ) => {
@@ -23,3 +24,37 @@ Deno.test("stream/promises pipeline", async () => {
2324 // pass
2425 }
2526} ) ;
27+
28+ // TODO(kt3k): Remove this test case when the node compat test suite is
29+ // updated to version 18.16.0 or above.
30+ // The last case in parallel/test-stream2-transform.js covers this case.
31+ // See https://github.com/nodejs/node/pull/46818
32+ Deno . test ( "stream.Writable does not change the order of items" , async ( ) => {
33+ async function test ( ) {
34+ const chunks : Uint8Array [ ] = [ ] ;
35+ const writable = new Writable ( {
36+ construct ( cb ) {
37+ setTimeout ( cb , 10 ) ;
38+ } ,
39+ write ( chunk , _ , cb ) {
40+ chunks . push ( chunk ) ;
41+ cb ( ) ;
42+ } ,
43+ } ) ;
44+
45+ for ( const i of Array ( 20 ) . keys ( ) ) {
46+ writable . write ( Uint8Array . from ( [ i ] ) ) ;
47+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
48+ }
49+
50+ if ( chunks [ 0 ] [ 0 ] !== 0 ) {
51+ // The first chunk is swapped with the later chunk.
52+ fail ( "The first chunk is swapped" ) ;
53+ }
54+ }
55+
56+ for ( const _ of Array ( 10 ) ) {
57+ // Run it multiple times to avoid flaky false negative.
58+ await test ( ) ;
59+ }
60+ } ) ;
0 commit comments