Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Jun 19, 2024
1 parent 08d4d7c commit c1f2fc5
Showing 1 changed file with 82 additions and 7 deletions.
89 changes: 82 additions & 7 deletions test/lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ test.serial("Builder returns single bundle", async (t) => {
const bundleOptions = {
"some": "option"
};
const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "BundleName.js",
Expand Down Expand Up @@ -92,7 +102,7 @@ test.serial("Builder returns single bundle", async (t) => {

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], {
// default bundleOptions
Expand Down Expand Up @@ -132,6 +142,17 @@ test.serial("Builder returns multiple bundles", async (t) => {
"some": "option"
};

const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundles = [
{
name: "BundleName1.js",
Expand Down Expand Up @@ -203,7 +224,7 @@ test.serial("Builder returns multiple bundles", async (t) => {

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], {
// default bundleOptions
Expand Down Expand Up @@ -245,6 +266,16 @@ test.serial("bundleOptions default (no options passed)", async (t) => {
const bundleDefinition = {
"some": "definition"
};
const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "BundleName.js",
Expand Down Expand Up @@ -291,7 +322,7 @@ test.serial("bundleOptions default (no options passed)", async (t) => {

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], {
// default bundleOptions
Expand Down Expand Up @@ -327,6 +358,17 @@ test.serial("bundleOptions default (empty options passed)", async (t) => {
};
const bundleOptions = {};

const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "BundleName.js",
content: "Bundle Content",
Expand Down Expand Up @@ -355,7 +397,7 @@ test.serial("bundleOptions default (empty options passed)", async (t) => {

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], {
// default bundleOptions
Expand Down Expand Up @@ -389,6 +431,17 @@ test.serial("bundleOptions (all options passed)", async (t) => {
ignoreMissingModules: true
};

const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "BundleName.js",
content: "Bundle Content",
Expand Down Expand Up @@ -417,7 +470,7 @@ test.serial("bundleOptions (all options passed)", async (t) => {

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], bundleOptions,
"builder.createBundle should be called with bundleOptions");
Expand Down Expand Up @@ -446,6 +499,16 @@ test.serial("Passes ignoreMissingModules bundleOption to LocatorResourcePool", a

"ignoreMissingModules": "foo"
};
const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "BundleName.js",
Expand Down Expand Up @@ -493,7 +556,7 @@ test.serial("Passes ignoreMissingModules bundleOption to LocatorResourcePool", a

t.is(builder.createBundle.callCount, 1, "builder.createBundle should be called once");
t.is(builder.createBundle.getCall(0).args.length, 2);
t.is(builder.createBundle.getCall(0).args[0], bundleDefinition,
t.deepEqual(builder.createBundle.getCall(0).args[0], effectiveBundleDefinition,
"builder.createBundle should be called with bundleDefinition");
t.deepEqual(builder.createBundle.getCall(0).args[1], effectiveBundleOptions,
"builder.createBundle should be called with bundleOptions");
Expand Down Expand Up @@ -535,6 +598,17 @@ test.serial("Verbose Logging", async (t) => {
"some": "option",
};

const effectiveBundleDefinition = {
// Defaults
"resolve": false,
"resolveConditional": false,
"renderer": false,
"sort": true,
"declareRawModules": false,

"some": "definition"
};

const createdBundle = {
name: "Bundle Name",
content: "Bundle Content",
Expand Down Expand Up @@ -566,6 +640,7 @@ test.serial("Verbose Logging", async (t) => {
t.is(log.verbose.callCount, 3, "log.verbose is called 3 times when verbose level is enabled");

t.deepEqual(log.verbose.getCall(0).args, ["Generating bundle:"]);
t.deepEqual(log.verbose.getCall(1).args, ["bundleDefinition: " + JSON.stringify(bundleDefinition, null, 2)]);
t.deepEqual(log.verbose.getCall(1).args,
["bundleDefinition: " + JSON.stringify(effectiveBundleDefinition, null, 2)]);
t.deepEqual(log.verbose.getCall(2).args, ["bundleOptions: " + JSON.stringify(effectiveBundleOptions, null, 2)]);
});

0 comments on commit c1f2fc5

Please sign in to comment.