Skip to content

Commit

Permalink
[FEATURE] Allow usage with non-blacklisted karma plugins (#163)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
  • Loading branch information
mlenkeit and CCFenner committed Mar 31, 2020
1 parent 888f1ed commit 1d41181
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
13 changes: 3 additions & 10 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
module.exports = {
ErrorMessage: {
multipleFrameworks: (frameworks) => {
blacklistedFrameworks: (frameworks) => {
let errorMessage = "error 1:\nThe \"karma-ui5\" plugin is not compatible " +
"with other framework plugins when running in \"html\" mode.";
"with certain framework plugins when running in \"html\" mode.";
if (frameworks.includes("qunit")) {
errorMessage += "\nQUnit is supported out of the box.";
}
if (frameworks.includes("sinon")) {
errorMessage += "\nSinon should be loaded from the test.";
}
errorMessage += `
Please make sure to define "ui5" as the only framework in your karma config:
module.exports = function(config) {
config.set({
frameworks: ["ui5"]
});
};
`;
Please make sure not to define "ui5" along with any of the above mentioned plugins your karma config.`;
return errorMessage;
},

Expand Down
6 changes: 4 additions & 2 deletions lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ class Framework {
throw new Error(ErrorMessage.failure());
}

if (this.config.frameworks && this.config.frameworks.length > 1 && this.config.ui5.mode === "html") {
this.logger.log("error", ErrorMessage.multipleFrameworks(this.config.frameworks) );
const blacklistedFrameworks = ["qunit", "sinon"];
const hasBlacklistedFrameworks = (frameworks) => frameworks.some((fwk) => blacklistedFrameworks.includes(fwk));
if (this.config.ui5.mode === "html" && hasBlacklistedFrameworks(this.config.frameworks || [])) {
this.logger.log("error", ErrorMessage.blacklistedFrameworks(this.config.frameworks) );
throw new Error(ErrorMessage.failure());
}

Expand Down
24 changes: 12 additions & 12 deletions test/unit/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,6 @@ describe("Error logging", () => {
expect(framework.logger.message).toBe(ErrorMessage.migrateConfig());
});

it("Should throw if multiple frameworks have been defined", () => {
const config = {
frameworks: ["foo", "ui5"]
};
expect(() => framework.init({config, logger})).toThrow();
expect(framework.logger.message).toBe(ErrorMessage.multipleFrameworks(["foo", "ui5"]));
});

it("Should throw if invalid mode is defined", () => {
const config = {
ui5: {
Expand Down Expand Up @@ -845,20 +837,28 @@ describe("Error logging", () => {
}));
});

it("Should throw if multiple frameworks have been defined (qunit)", () => {
it("Should not throw if a non-backlisted framework has been defined", () => {
const config = {
frameworks: ["foo", "ui5"]
};
expect(() => framework.init({config, logger})).toThrow(); // some unrelated exception
expect(framework.logger.message).not.toBe(ErrorMessage.blacklistedFrameworks(["foo", "ui5"]));
});

it("Should throw if a blacklisted framework has been defined (qunit)", () => {
const config = {
frameworks: ["qunit", "ui5"]
};
expect(() => framework.init({config, logger})).toThrow();
expect(framework.logger.message).toBe(ErrorMessage.multipleFrameworks(["qunit", "ui5"]));
expect(framework.logger.message).toBe(ErrorMessage.blacklistedFrameworks(["qunit", "ui5"]));
});

it("Should throw if multiple frameworks have been defined (qunit + sinon)", () => {
it("Should throw if a blacklisted framework has been defined (qunit + sinon)", () => {
const config = {
frameworks: ["qunit", "sinon", "ui5"]
};
expect(() => framework.init({config, logger})).toThrow();
expect(framework.logger.message).toBe(ErrorMessage.multipleFrameworks(["qunit", "sinon", "ui5"]));
expect(framework.logger.message).toBe(ErrorMessage.blacklistedFrameworks(["qunit", "sinon", "ui5"]));
});

it("Should throw if files have been defined in config", () => {
Expand Down

0 comments on commit 1d41181

Please sign in to comment.