11import test , { ExecutionContext } from "ava" ;
2- import { BundleOrchastrator } from "./bundle-orchastrator.js" ;
2+ import { BundleOrchastrator , ResultsCallback } from "./bundle-orchastrator.js" ;
33import intoStream from "into-stream" ;
44import getStream from "get-stream" ;
55import { Readable , Stream } from "stream" ;
66import Vinyl from "vinyl" ;
77import { resolve as resolvePath } from "path" ;
88import sortOn from "sort-on" ;
99import { mapAvaLoggerToStandard } from "./test-util.js" ;
10+ import pDefer from "p-defer" ;
1011
1112/**
1213 * Returns a pretend bundle for testing purposes.
@@ -70,6 +71,11 @@ interface IBundleBuilderFlags {
7071 * Don't include any script bundles.
7172 */
7273 noScriptBundles ?: boolean ;
74+
75+ /**
76+ * Results callback to include.
77+ */
78+ resultsCallback ?: ResultsCallback ;
7379}
7480
7581/**
@@ -107,18 +113,31 @@ function buildBundler(t: ExecutionContext, flags: IBundleBuilderFlags = {}) {
107113 Scripts : bundleFactoryJs ,
108114 Styles : bundleFactoryCss ,
109115 } ,
116+ flags . resultsCallback
117+ ? flags . resultsCallback
118+ : undefined ,
110119 ) ;
111120}
112121
113122test ( "Bundles with all dependencies met" , async t => {
123+ t . plan ( 3 ) ;
124+
125+ const resultsCallbackCompletion = pDefer ( ) ;
126+ const resultsCallback : ResultsCallback = function ( results ) {
127+ // Results data is based on a clone of the actual Vinyl files, length is enough for now
128+ t . is ( results . scripts . size , 1 ) ;
129+ t . is ( results . styles . size , 1 ) ;
130+ resultsCallbackCompletion . resolve ( ) ;
131+ } ;
132+
114133 const result = await getStream . array (
115134 intoStream . object ( [
116135 new Vinyl ( { path : resolvePath ( "./123/bar.js" ) } ) ,
117136 new Vinyl ( { path : resolvePath ( "./123/foo.css" ) } ) ,
118137 new Vinyl ( { path : resolvePath ( "./abc/foo.css" ) } ) ,
119138 new Vinyl ( { path : resolvePath ( "./abc/foo.js" ) } ) ,
120139 ] )
121- . pipe ( buildBundler ( t ) )
140+ . pipe ( buildBundler ( t , { resultsCallback } ) )
122141 ) as Vinyl [ ] ;
123142
124143 t . deepEqual (
@@ -137,6 +156,8 @@ test("Bundles with all dependencies met", async t => {
137156 'history'
138157 )
139158 ) ;
159+
160+ await resultsCallbackCompletion . promise ;
140161} ) ;
141162
142163/**
0 commit comments