Skip to content

Commit

Permalink
Results callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
Silic0nS0ldier committed Feb 20, 2020
1 parent 6f1f558 commit 4b12c7a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
25 changes: 23 additions & 2 deletions src/bundle-orchastrator.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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";
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.
Expand Down Expand Up @@ -70,6 +71,11 @@ interface IBundleBuilderFlags {
* Don't include any script bundles.
*/
noScriptBundles?: boolean;

/**
* Results callback to include.
*/
resultsCallback?: ResultsCallback;
}

/**
Expand Down Expand Up @@ -107,18 +113,31 @@ 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") }),
new Vinyl({ path: resolvePath("./123/foo.css") }),
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(
Expand All @@ -137,6 +156,8 @@ test("Bundles with all dependencies met", async t => {
'history'
)
);

await resultsCallbackCompletion.promise;
});

/**
Expand Down

0 comments on commit 4b12c7a

Please sign in to comment.