diff --git a/package-lock.json b/package-lock.json index fe13b575..7420c0a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2484,6 +2484,12 @@ "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", "dev": true }, + "p-defer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-3.0.0.tgz", + "integrity": "sha512-ugZxsxmtTln604yeYd29EGrNhazN2lywetzpKhfmQjW/VJmhpDmWbiX+h0zL8V91R0UXkhb3KtPmyq9PZw3aYw==", + "dev": true + }, "p-is-promise": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-3.0.0.tgz", diff --git a/package.json b/package.json index bb0a9505..afb71981 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "ava": "^3.3.0", "changelog-updater": "^1.1.0", "nyc": "^15.0.0", + "p-defer": "^3.0.0", "sort-on": "^4.1.0", "typescript": "^3.7.5" }, diff --git a/src/bundle-orchastrator.test.ts b/src/bundle-orchastrator.test.ts index daa8fac0..317de758 100644 --- a/src/bundle-orchastrator.test.ts +++ b/src/bundle-orchastrator.test.ts @@ -1,5 +1,5 @@ import test, { ExecutionContext } from "ava"; -import { BundleOrchastrator } from "./bundle-orchastrator.js"; +import { BundleOrchastrator, ResultsCallback } from "./bundle-orchastrator.js"; import intoStream from "into-stream"; import getStream from "get-stream"; import { Readable, Stream } from "stream"; @@ -7,6 +7,7 @@ import Vinyl from "vinyl"; import { resolve as resolvePath } from "path"; import sortOn from "sort-on"; import { mapAvaLoggerToStandard } from "./test-util.js"; +import pDefer from "p-defer"; /** * Returns a pretend bundle for testing purposes. @@ -70,6 +71,11 @@ interface IBundleBuilderFlags { * Don't include any script bundles. */ noScriptBundles?: boolean; + + /** + * Results callback to include. + */ + resultsCallback?: ResultsCallback; } /** @@ -107,10 +113,23 @@ function buildBundler(t: ExecutionContext, flags: IBundleBuilderFlags = {}) { Scripts: bundleFactoryJs, Styles: bundleFactoryCss, }, + flags.resultsCallback + ? flags.resultsCallback + : undefined, ); } test("Bundles with all dependencies met", async t => { + t.plan(3); + + const resultsCallbackCompletion = pDefer(); + const resultsCallback: ResultsCallback = function (results) { + // Results data is based on a clone of the actual Vinyl files, length is enough for now + t.is(results.scripts.size, 1); + t.is(results.styles.size, 1); + resultsCallbackCompletion.resolve(); + }; + const result = await getStream.array( intoStream.object([ new Vinyl({ path: resolvePath("./123/bar.js") }), @@ -118,7 +137,7 @@ test("Bundles with all dependencies met", async t => { new Vinyl({ path: resolvePath("./abc/foo.css") }), new Vinyl({ path: resolvePath("./abc/foo.js") }), ]) - .pipe(buildBundler(t)) + .pipe(buildBundler(t, { resultsCallback })) ) as Vinyl[]; t.deepEqual( @@ -137,6 +156,8 @@ test("Bundles with all dependencies met", async t => { 'history' ) ); + + await resultsCallbackCompletion.promise; }); /**