@@ -50,11 +50,33 @@ function bundleFactoryCss(_: Readable, name: string): Stream {
5050 return newSrc ;
5151}
5252
53- function buildBundler ( t : ExecutionContext ) {
53+ interface IBundleBuilderFlags {
54+ /**
55+ * Explicitly set cwd.
56+ */
57+ explicitCwd ?: boolean ;
58+
59+ /**
60+ * Don't include any bundle specs.
61+ */
62+ noBundles ?: boolean ;
63+ }
64+
65+ /**
66+ * Tool to help build bundler for tests.
67+ * @param t Execution context from test.
68+ * @param flags Flags used to modify returned bundler.
69+ */
70+ function buildBundler ( t : ExecutionContext , flags : IBundleBuilderFlags = { } ) {
5471 return new BundleOrchastrator (
5572 {
73+ cwd : flags . explicitCwd
74+ ? process . cwd ( )
75+ : undefined ,
5676 Logger : mapAvaLoggerToStandard ( t ) ,
57- bundle : {
77+ bundle : flags . noBundles
78+ ? undefined
79+ : {
5880 bund1 : {
5981 scripts : [
6082 "./123/bar.js" ,
@@ -103,6 +125,65 @@ test("Bundles with all dependencies met", async t => {
103125 ) ;
104126} ) ;
105127
128+ /**
129+ * @todo This should be improved to account for _different_ `cwd`s. Currently UserFrosting covers
130+ * this via its usage of this library.
131+ */
132+ test ( "Bundles with all dependencies met and custom cwd" , async t => {
133+ const result = await getStream . array (
134+ intoStream . object ( [
135+ new Vinyl ( { path : resolvePath ( "./123/bar.js" ) } ) ,
136+ new Vinyl ( { path : resolvePath ( "./123/foo.css" ) } ) ,
137+ new Vinyl ( { path : resolvePath ( "./abc/foo.css" ) } ) ,
138+ new Vinyl ( { path : resolvePath ( "./abc/foo.js" ) } ) ,
139+ ] )
140+ . pipe ( buildBundler ( t , { explicitCwd : true } ) )
141+ ) as Vinyl [ ] ;
142+
143+ t . deepEqual (
144+ sortOn ( result , 'history' ) ,
145+ sortOn (
146+ [
147+ // Original inputs
148+ new Vinyl ( { path : resolvePath ( "./123/bar.js" ) } ) ,
149+ new Vinyl ( { path : resolvePath ( "./123/foo.css" ) } ) ,
150+ new Vinyl ( { path : resolvePath ( "./abc/foo.css" ) } ) ,
151+ new Vinyl ( { path : resolvePath ( "./abc/foo.js" ) } ) ,
152+ // Bundles
153+ new Vinyl ( { path : resolvePath ( "./bund1.js" ) } ) ,
154+ new Vinyl ( { path : resolvePath ( "./bund1.css" ) } ) ,
155+ ] ,
156+ 'history'
157+ )
158+ ) ;
159+ } ) ;
160+
161+ test ( "No bundles to build" , async t => {
162+ const result = await getStream . array (
163+ intoStream . object ( [
164+ new Vinyl ( { path : resolvePath ( "./123/bar.js" ) } ) ,
165+ new Vinyl ( { path : resolvePath ( "./123/foo.css" ) } ) ,
166+ new Vinyl ( { path : resolvePath ( "./abc/foo.css" ) } ) ,
167+ new Vinyl ( { path : resolvePath ( "./abc/foo.js" ) } ) ,
168+ ] )
169+ . pipe ( buildBundler ( t , { noBundles : true } ) )
170+ ) as Vinyl [ ] ;
171+
172+ t . deepEqual (
173+ sortOn ( result , 'history' ) ,
174+ sortOn (
175+ [
176+ // Original inputs
177+ new Vinyl ( { path : resolvePath ( "./123/bar.js" ) } ) ,
178+ new Vinyl ( { path : resolvePath ( "./123/foo.css" ) } ) ,
179+ new Vinyl ( { path : resolvePath ( "./abc/foo.css" ) } ) ,
180+ new Vinyl ( { path : resolvePath ( "./abc/foo.js" ) } ) ,
181+ ] ,
182+ 'history'
183+ )
184+ ) ;
185+ } ) ;
186+
106187test ( "Non-vinyl chunk pushed out when feed in" , async t => {
107188 try {
108189 const result = await getStream . array (
0 commit comments