Skip to content

Commit

Permalink
[FEATURE] Introduce "html" / "script" mode
Browse files Browse the repository at this point in the history
The "htmlrunner" flag has been removed in favor of a "mode" which
currently supports "html" and "script".
  • Loading branch information
romaniam authored and matz3 committed Apr 2, 2019
1 parent ec1d060 commit bc0aa54
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 24 deletions.
10 changes: 10 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ module.exports = function(config) {
};
`,
migrateConfig: () => "error 12: Please migrate your configuration https://github.com/SAP/karma-ui5",
invalidMode: (mode) => `error 13:
The mode defined in your config is invalid. Mode must be "script" or "html" (default).
module.exports = function(config) {
config.set({
ui5: {
mode: "${mode}"\t<-- Invalid. Must be "script" or "html"
}
});
};`,
failure: () => "ui5.framework failed. See error message above"

}
Expand Down
46 changes: 34 additions & 12 deletions lib/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Framework {
}
}

initWithoutHTMLRunner(config) {
initScriptMode(config) {
config.client.ui5.config = config.ui5.config;
config.client.ui5.tests = config.ui5.tests;
if (config.ui5.tests) {
Expand All @@ -93,6 +93,16 @@ class Framework {
config.files.unshift(this.createPluginFilesPattern(`${__dirname}/client/sap-ui-config.js`));
}

/**
* Checks if give filename contains pattern
*
* @param {string} fileName
* @returns {boolean}
*/
fileContainsPattern(fileName) {
return /\*+/.test(fileName);
}

init({config, logger}) {
this.config = config;
this.logger = logger.create("ui5.framework");
Expand All @@ -110,23 +120,38 @@ class Framework {
this.config.client.ui5.useIframe = true;
}

this.checkLegacy(config);

if (this.config.ui5.htmlrunner === false) {
this.initWithoutHTMLRunner(config);
return this;
if (!this.config.ui5.mode) {
this.config.ui5.mode = "html";
}

if (config.frameworks && config.frameworks.length > 1) {
this.logger.log("error", ErrorMessage.multipleFrameworks(config.frameworks) );
if (this.config.ui5.mode && ["script", "html"].indexOf(this.config.ui5.mode) === -1) {
this.logger.log("error", ErrorMessage.invalidMode(this.config.ui5.mode));
throw new Error(ErrorMessage.failure());
}

if (Object.keys(config.files).length !== 0) {
this.checkLegacy(config);

const bContainsFilesDefinition = this.config.files.filter(
(option) => this.fileContainsPattern(option.pattern)
).length > 0;

if (Object.keys(config.files).length !== 0 && bContainsFilesDefinition) {
this.logger.log("error", ErrorMessage.containsFilesDefinition() );
throw new Error(ErrorMessage.failure());
}

if (this.config.ui5.mode === "script") {
this.initScriptMode(config);
} else {
// Add browser bundle including third-party dependencies
this.config.files.unshift(this.createPluginFilesPattern(__dirname + "/../dist/browser-bundle.js"));
}

if (config.frameworks && config.frameworks.length > 1 && this.config.ui5.mode === "html") {
this.logger.log("error", ErrorMessage.multipleFrameworks(config.frameworks) );
throw new Error(ErrorMessage.failure());
}

if (this.config.ui5.paths && !this.config.ui5.type) {
this.logger.log("error", ErrorMessage.customPathWithoutType() );
throw new Error(ErrorMessage.failure());
Expand All @@ -150,9 +175,6 @@ class Framework {
this.config.client.ui5.testpage = this.config.ui5Testpage || this.config.ui5.testpage;
}

// Add browser bundle including third-party dependencies
this.config.files.unshift(this.createPluginFilesPattern(__dirname + "/../dist/browser-bundle.js"));

if (this.config.ui5.type === "application") {
const webappFolder = this.config.ui5.paths.webapp;
if (!this.exists(path.join(this.config.basePath, webappFolder))) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"test": "npm run lint && npm run utest-coverage && npm run itest",
"utest": "jest",
"utest-coverage": "jest --coverage",
"itest": "npm run itest:app-proxy && npm run itest:app-proxy-coverage && npm run itest:app-ui5-tooling && npm run itest:library-proxy && npm run itest:library-ui5-tooling && npm run itest:library-custompath && npm run itest:app-no-htmlrunner",
"itest": "npm run itest:app-proxy && npm run itest:app-proxy-coverage && npm run itest:app-ui5-tooling && npm run itest:library-proxy && npm run itest:library-ui5-tooling && npm run itest:library-custompath && npm run itest:app-script-mode",
"itest:app-proxy": "karma start test/integration/application-proxy/karma.conf.js",
"itest:app-proxy-coverage": "karma start test/integration/application-proxy/karma-coverage.conf.js",
"itest:app-ui5-tooling": "karma start test/integration/application-ui5-tooling/karma.conf.js",
"itest:app-no-htmlrunner": "karma start test/integration/application-no-htmlrunner/karma.conf.js",
"itest:app-script-mode": "karma start test/integration/application-script-mode/karma.conf.js",
"itest:library-proxy": "karma start test/integration/library-proxy/karma.conf.js",
"itest:library-ui5-tooling": "karma start test/integration/library-ui5-tooling/karma.conf.js",
"itest:library-ui5-tooling-multiple-testsuites": "karma start test/integration/library-ui5-tooling-multiple-testsuites/karma.conf.js",
Expand Down
12 changes: 7 additions & 5 deletions test/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe("UI5 Middleware / Proxy configuration", () => {
framework.init({config, logger});

expect(setupProxySpy).toHaveBeenCalledWith({
mode: "html",
url: "http://localhost",
type: "application",
paths: {
Expand All @@ -187,6 +188,7 @@ describe("UI5 Middleware / Proxy configuration", () => {
framework.init({config, logger});

expect(setupProxySpy).toHaveBeenCalledWith({
mode: "html",
type: "application",
url: "http://other.host",
paths: {
Expand Down Expand Up @@ -479,7 +481,7 @@ describe("Without QUnit HTML Runner", () => {
it("Should include sap-ui-config.js and sap-ui-core.js", () => {
const config = {
ui5: {
htmlrunner: false,
mode: "script",
url: "https://example.com"
}
};
Expand All @@ -493,7 +495,7 @@ describe("Without QUnit HTML Runner", () => {
it("Should include also include autorun.js if tests are configured", () => {
const config = {
ui5: {
htmlrunner: false,
mode: "script",
url: "https://example.com",
tests: ["some/test"]
}
Expand Down Expand Up @@ -572,9 +574,9 @@ describe("Error logging", () => {

it("Should throw if files have been defined in config", () => {
const config = {
files: {
a: ""
}
files: [
{pattern: "**", included: false, served: true, watched: true}
]
};
expect(() => framework.init({config, logger})).toThrow();
expect(framework.logger.message).toBe(ErrorMessage.containsFilesDefinition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(config) {
frameworks: ["qunit", "ui5"],

ui5: {
htmlrunner: false,
mode: "script",
url: "https://openui5nightly.hana.ondemand.com",
config: {
theme: "sap_belize",
Expand All @@ -26,10 +26,6 @@ module.exports = function(config) {
}
},

files: [
{pattern: "**", included: false, served: true, watched: true}
],

plugins: [
require("../../../lib"),
require("karma-chrome-launcher"),
Expand Down

0 comments on commit bc0aa54

Please sign in to comment.