Skip to content

Commit 4b12c7a

Browse files
Results callback test
1 parent 6f1f558 commit 4b12c7a

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"ava": "^3.3.0",
6666
"changelog-updater": "^1.1.0",
6767
"nyc": "^15.0.0",
68+
"p-defer": "^3.0.0",
6869
"sort-on": "^4.1.0",
6970
"typescript": "^3.7.5"
7071
},

src/bundle-orchastrator.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import test, { ExecutionContext } from "ava";
2-
import { BundleOrchastrator } from "./bundle-orchastrator.js";
2+
import { BundleOrchastrator, ResultsCallback } from "./bundle-orchastrator.js";
33
import intoStream from "into-stream";
44
import getStream from "get-stream";
55
import { Readable, Stream } from "stream";
66
import Vinyl from "vinyl";
77
import { resolve as resolvePath } from "path";
88
import sortOn from "sort-on";
99
import { 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

113122
test("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

Comments
 (0)