Skip to content

Commit

Permalink
[FIX] Error handling for missing scoping files
Browse files Browse the repository at this point in the history
Fixes: #66
  • Loading branch information
matz3 committed Jun 26, 2020
1 parent 3ae5c40 commit c7513a1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,18 @@ Builder.prototype.build = function(options) {
function compileWithScope(scopeOptions) {
// 1. Compile base + embedded files (both default + RTL variants)
return Promise.all([
that.fileUtils.readFile(scopeOptions.embeddedCompareFilePath, options.rootPaths).then(compile),
that.fileUtils.readFile(scopeOptions.embeddedFilePath, options.rootPaths).then(compile)
that.fileUtils.readFile(scopeOptions.embeddedCompareFilePath, options.rootPaths).then(function(config) {
if (!config) {
throw new Error("Could not find embeddedCompareFile at path '" + scopeOptions.embeddedCompareFilePath + "'");
}
return compile(config);
}),
that.fileUtils.readFile(scopeOptions.embeddedFilePath, options.rootPaths).then(function(config) {
if (!config) {
throw new Error("Could not find embeddedFile at path '" + scopeOptions.embeddedFilePath + "'");
}
return compile(config);
})
]).then(function(results) {
return {
embeddedCompare: results[0],
Expand Down
41 changes: 41 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,4 +1330,45 @@ describe("CSS Scoping (via option) of", function() {
});
});
});

describe("Error handling", function() {
it("should throw error when embeddedFile is missing", function() {
return new Builder().build({
scope: {
selector: "fooContrast",
embeddedFilePath: "comments/themes/bar/library.source.less",
embeddedCompareFilePath: "comments/themes/foo/library.source.less",
baseFilePath: "comments/themes/foo/library.source.less"
},
lessInputPath: "comments/themes/foo/library.source.less",
rootPaths: [
"test/fixtures/libraries/scopes/comments/lib1"
]
}).then(function() {
assert.fail("Build should not succeed");
}, function(err) {
assert.ok(err instanceof Error, "err should be instance of Error");
assert.equal(err.message, "Could not find embeddedFile at path 'comments/themes/bar/library.source.less'");
});
});
it("should throw error when embeddedCompareFile is missing", function() {
return new Builder().build({
scope: {
selector: "fooContrast",
embeddedFilePath: "comments/themes/bar/library.source.less",
embeddedCompareFilePath: "comments/themes/foo/library.source.less",
baseFilePath: "comments/themes/foo/library.source.less"
},
lessInputPath: "comments/themes/bar/library.source.less",
rootPaths: [
"test/fixtures/libraries/scopes/comments/lib2"
]
}).then(function() {
assert.fail("Build should not succeed");
}, function(err) {
assert.ok(err instanceof Error, "err should be instance of Error");
assert.equal(err.message, "Could not find embeddedCompareFile at path 'comments/themes/foo/library.source.less'");
});
});
});
});

0 comments on commit c7513a1

Please sign in to comment.