Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage with non-blacklisted karma plugins #163

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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