@@ -2,11 +2,18 @@ import * as fs from "node:fs";
22import { describe , expect , it } from "vitest" ;
33import {
44 createGzipDecoder ,
5+ createTarDecoder ,
56 type ParsedTarEntryWithData ,
67 unpackTar ,
78} from "../../src/web" ;
89import { streamToBuffer } from "../../src/web/stream-utils" ;
9- import { ELECTRON_TGZ , LODASH_TGZ , NEXT_SWC_TGZ , SHARP_TGZ } from "./fixtures" ;
10+ import {
11+ ELECTRON_TGZ ,
12+ LODASH_TGZ ,
13+ NEXT_SWC_TGZ ,
14+ NODE_V25_DARWIN_ARM64_TAR_GZ ,
15+ SHARP_TGZ ,
16+ } from "./fixtures" ;
1017
1118async function extractTgz ( filePath : string ) : Promise < ParsedTarEntryWithData [ ] > {
1219 // @ts -expect-error ReadableStream.from is supported in Node tests
@@ -32,7 +39,7 @@ describe("real world examples", () => {
3239 ( e ) => e . header . name === "package/README.md" ,
3340 ) ;
3441 expect ( readmeEntry ) . toBeDefined ( ) ;
35- expect ( readmeEntry ?. data . length ) . toBeGreaterThan ( 1000 ) ;
42+ expect ( readmeEntry ?. data ? .length ) . toBe ( 1107 ) ;
3643 } ) ;
3744
3845 it (
@@ -51,7 +58,7 @@ describe("real world examples", () => {
5158 ( e ) => e . header . name === "package/next-swc.linux-x64-gnu.node" ,
5259 ) ;
5360 expect ( binaryEntry ) . toBeDefined ( ) ;
54- expect ( binaryEntry ?. data . length ) . toBeGreaterThan ( 30 * 1024 * 1024 ) ; // > 30MB
61+ expect ( binaryEntry ?. data ? .length ) . toBe ( 131406240 ) ;
5562
5663 // Verify package.json exists
5764 expect (
@@ -72,14 +79,14 @@ describe("real world examples", () => {
7279 const cppFiles = entries . filter (
7380 ( e ) => e . header . name . endsWith ( ".cc" ) || e . header . name . endsWith ( ".h" ) ,
7481 ) ;
75- expect ( cppFiles . length ) . toBeGreaterThan ( 5 ) ;
82+ expect ( cppFiles . length ) . toBe ( 13 ) ;
7683
7784 // Verify a specific C++ file has substantial content
7885 const sharpCcEntry = entries . find (
7986 ( e ) => e . header . name === "package/src/sharp.cc" ,
8087 ) ;
8188 expect ( sharpCcEntry ) . toBeDefined ( ) ;
82- expect ( sharpCcEntry ?. data . length ) . toBeGreaterThan ( 1000 ) ;
89+ expect ( sharpCcEntry ?. data ? .length ) . toBe ( 1465 ) ;
8390 } ) ;
8491
8592 it ( "extracts a package with installation scripts (electron)" , async ( ) => {
@@ -104,6 +111,58 @@ describe("real world examples", () => {
104111 ( e ) => e . header . name === "package/electron.d.ts" ,
105112 ) ;
106113 expect ( electronDtsEntry ) . toBeDefined ( ) ;
107- expect ( electronDtsEntry ?. data . length ) . toBeGreaterThan ( 1000 ) ;
114+ expect ( electronDtsEntry ?. data ?. length ) . toBe ( 987499 ) ;
115+ } ) ;
116+
117+ it ( "extracts a Node.js release tarball" , async ( ) => {
118+ // @ts -expect-error ReadableStream.from is supported in Node tests
119+ const fileStream = ReadableStream . from (
120+ fs . createReadStream ( NODE_V25_DARWIN_ARM64_TAR_GZ ) ,
121+ ) ;
122+
123+ const entryStream = fileStream
124+ . pipeThrough ( createGzipDecoder ( ) )
125+ . pipeThrough ( createTarDecoder ( ) ) ;
126+
127+ let count = 0 ;
128+ let lastEntry = "" ;
129+ let totalBytes = 0 ;
130+ for await ( const entry of entryStream ) {
131+ count ++ ;
132+ lastEntry = entry . header . name ;
133+
134+ const reader = entry . body . getReader ( ) ;
135+ while ( true ) {
136+ const { done, value } = await reader . read ( ) ;
137+ if ( done ) break ;
138+ if ( value ) totalBytes += value . length ;
139+ }
140+ }
141+
142+ expect ( count ) . toBe ( 5986 ) ;
143+ expect ( lastEntry ) . toBe ( "node-v25.2.0-darwin-arm64/bin/npm" ) ;
144+ expect ( totalBytes ) . toBe ( 200544142 ) ;
145+ } ) ;
146+
147+ it ( "streams entries from the Node.js release tarball" , async ( ) => {
148+ // @ts -expect-error ReadableStream.from is supported in Node tests
149+ const fileStream = ReadableStream . from (
150+ fs . createReadStream ( NODE_V25_DARWIN_ARM64_TAR_GZ ) ,
151+ ) ;
152+
153+ const entryStream = fileStream
154+ . pipeThrough ( createGzipDecoder ( ) )
155+ . pipeThrough ( createTarDecoder ( ) ) ;
156+
157+ let count = 0 ;
158+ let lastEntry = "" ;
159+ for await ( const entry of entryStream ) {
160+ count ++ ;
161+ lastEntry = entry . header . name ;
162+ await entry . body . cancel ( ) ;
163+ }
164+
165+ expect ( count ) . toBe ( 5986 ) ;
166+ expect ( lastEntry ) . toBe ( "node-v25.2.0-darwin-arm64/bin/npm" ) ;
108167 } ) ;
109168} ) ;
0 commit comments