Skip to content

Commit 48f3d05

Browse files
author
Chuck Dumont
authored
Merge pull request #59 from chuckdumont/work2
Add error test cases
2 parents 55ba0e9 + 629df6f commit 48f3d05

File tree

19 files changed

+151
-10
lines changed

19 files changed

+151
-10
lines changed

lib/DojoAMDPlugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,18 @@ Refer to https://github.com/OpenNTF/dojo-webpack-plugin/blob/master/README.md#bu
186186
getDojoLoader(options__, loaderConfig, callback) {
187187
var dojoLoader;
188188
if (this.options.loader) {
189-
dojoLoader = require(this.options.loader);
189+
try {
190+
dojoLoader = require(this.options.loader);
191+
} catch (error) {
192+
callback(error);
193+
}
190194
callback(null, dojoLoader);
191195
} else {
192196
console.log("Dojo loader not specified in options. Building the loader...");
193197
const execFile = require("child_process").execFile;
194198
const tmp = require("tmp");
195199
let dojoPath;
196-
if (!loaderConfig.packages.some((pkg) => {
200+
if (!loaderConfig.packages || !loaderConfig.packages.some((pkg) => {
197201
if (pkg.name === "dojo") return (dojoPath = pkg.location);
198202
})) {
199203
return callback(new Error("dojo package not defined in loader config"));

package-lock.json

Lines changed: 26 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
@@ -33,6 +33,7 @@
3333
"eslint": "^4.7.2",
3434
"eslint-plugin-json": "^1.2.0",
3535
"eslint-plugin-markdown": "^1.0.0-beta.6",
36+
"fs-extra": "^4.0.2",
3637
"istanbul": "^0.4.5",
3738
"mocha": "^3.5.3",
3839
"mocha-lcov-reporter": "^1.3.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
test: function(error) {
3+
return /Dojo loader version does not match the version of Dojo/.test(error.message);
4+
}
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
define([], function() {});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var DojoWebpackPlugin = require("../../../../index");
2+
var path = require("path");
3+
var fs = require("fs-extra");
4+
var loader = fs.readFileSync(path.join(__dirname, "../../../js/dojo/dojo.js"), "utf-8"); // eslint-disable-line
5+
var loaderPath = path.join(__dirname.replace(/[\/\\]test[\/\\]ErrorTestCases[\/\\]/, "/test/js/ErrorTestCases/"), "dojoLoader.js");
6+
loader = loader.replace(/(this\.loaderVersion)\s*=\s*"[^"]+"/, '$1 = "1.0.0"');
7+
fs.ensureDirSync(path.join(loaderPath, ".."));
8+
fs.writeFileSync(loaderPath, loader, "utf-8");
9+
module.exports = {
10+
entry: "test/index",
11+
plugins: [
12+
new DojoWebpackPlugin({
13+
loaderConfig: {
14+
paths:{test: "."}
15+
},
16+
loader: loaderPath
17+
})
18+
]
19+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
test: function(error) {
3+
return /Command failed:/.test(error.message);
4+
}
5+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
define([], function() {});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var DojoWebpackPlugin = require("../../../../index");
2+
module.exports = {
3+
entry: "test/index",
4+
plugins: [
5+
new DojoWebpackPlugin({
6+
loaderConfig: {
7+
paths:{test: "."},
8+
packages:[{name: "dojo", location: "./dojo"}]
9+
}
10+
})
11+
]
12+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
test: function(error) {
3+
return /dojo package not defined in loader config/.test(error.message);
4+
}
5+
};

0 commit comments

Comments
 (0)