11import { Ok , SourceProcessor , SymbolUploader , ZipArchive } from '@backtrace/sourcemap-tools' ;
22import assert from 'assert' ;
33import crypto from 'crypto' ;
4- import fs from 'fs' ;
54import path from 'path' ;
5+ import { Readable } from 'stream' ;
66import webpack from 'webpack' ;
77import { asyncWebpack , expectSuccess , getFiles , removeDir , webpackModeTest } from './helpers' ;
88
@@ -19,9 +19,7 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
1919 }
2020
2121 function mockProcessor ( ) {
22- return jest
23- . spyOn ( SourceProcessor . prototype , 'processSourceAndSourceMapFiles' )
24- . mockImplementation ( async ( _ , __ , debugId ) => Ok ( { debugId : debugId ?? 'debugId' } as never ) ) ;
22+ return jest . spyOn ( SourceProcessor . prototype , 'processSourceAndSourceMapFiles' ) ;
2523 }
2624
2725 function mockZipArchiveAppend ( ) {
@@ -34,7 +32,7 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
3432 let zipArchiveAppendSpy : ReturnType < typeof mockZipArchiveAppend > ;
3533
3634 beforeAll ( async ( ) => {
37- jest . resetAllMocks ( ) ;
35+ jest . restoreAllMocks ( ) ;
3836
3937 uploadSpy = mockUploader ( ) ;
4038 processSpy = mockProcessor ( ) ;
@@ -50,44 +48,35 @@ export function createE2ETest(configBuilder: (mode: webpack.Configuration['mode'
5048 result = webpackResult ;
5149 } , 120000 ) ;
5250
53- it ( 'should call SourceProcessor for every emitted source file and sourcemap pair ' , async ( ) => {
51+ it ( 'should call SourceProcessor for every emitted source file' , async ( ) => {
5452 const outputDir = result . compilation . outputOptions . path ;
5553 assert ( outputDir ) ;
5654
5755 const jsFiles = await getFiles ( outputDir , / .j s $ / ) ;
5856 expect ( jsFiles . length ) . toBeGreaterThan ( 0 ) ;
5957
60- const processedPairs = processSpy . mock . calls . map (
61- ( [ p1 , p2 ] ) => [ path . resolve ( p1 ) , p2 ? path . resolve ( p2 ) : undefined ] as const ,
62- ) ;
63- for ( const file of jsFiles ) {
64- const content = await fs . promises . readFile ( file , 'utf8' ) ;
65- const matches = [ ...content . matchAll ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = ( .+ ) $ / gm) ] ;
66- expect ( matches . length ) . toEqual ( 1 ) ;
67- const [ , sourceMapPath ] = matches [ 0 ] ;
68-
69- expect ( processedPairs ) . toContainEqual ( [
70- path . resolve ( file ) ,
71- path . resolve ( path . dirname ( file ) , sourceMapPath ) ,
72- ] ) ;
73- }
58+ const processedFiles = processSpy . mock . calls
59+ . map ( ( [ sourcePath ] ) => path . resolve ( sourcePath ) )
60+ . sort ( ( a , b ) => a . localeCompare ( b ) ) ;
61+
62+ expect ( processedFiles ) . toEqual ( jsFiles . sort ( ( a , b ) => a . localeCompare ( b ) ) ) ;
7463 } ) ;
7564
7665 it ( 'should append every emitted sourcemap to archive' , async ( ) => {
7766 const outputDir = result . compilation . outputOptions . path ;
7867 assert ( outputDir ) ;
7968
80- const mapFiles = await getFiles ( outputDir , / .j s .m a p $ / ) ;
69+ const mapFiles = ( await getFiles ( outputDir , / .j s .m a p $ / ) ) . map ( ( f ) => path . basename ( f ) ) ;
8170 expect ( mapFiles . length ) . toBeGreaterThan ( 0 ) ;
8271
83- const uploadedFiles = zipArchiveAppendSpy . mock . calls . map ( ( c ) => path . resolve ( c [ 1 ] as string ) ) ;
72+ const uploadedFiles = zipArchiveAppendSpy . mock . calls . map ( ( [ name ] ) => name ) ;
8473 for ( const file of mapFiles ) {
85- expect ( uploadedFiles ) . toContain ( path . resolve ( file ) ) ;
74+ expect ( uploadedFiles ) . toContainEqual ( expect . stringContaining ( file ) ) ;
8675 }
8776 } ) ;
8877
8978 it ( 'should upload archive' , async ( ) => {
90- expect ( uploadSpy ) . toBeCalledWith ( expect . any ( ZipArchive ) ) ;
79+ expect ( uploadSpy ) . toHaveBeenCalledWith ( expect . any ( Readable ) ) ;
9180 } ) ;
9281 } ) ;
9382}
0 commit comments