From a7bf9371566f973d7b2c474ae52781fc0ccbe5cf Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Wed, 25 Mar 2020 01:15:58 +0800 Subject: [PATCH 01/23] Update browser.js push assertion result to karma --- lib/client/browser.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/client/browser.js b/lib/client/browser.js index 002d0e43..f92396bd 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -219,6 +219,14 @@ require("./discovery.js"); }); QUnit.log(function(details) { + const result = { + description: details.message, + suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], + success: details.result, + log: testResult.errors || [], + time: new Date().getTime() - timer + }; + karma.result(result); if (!details.result) { let msg = ""; From 2e56125d08558c3e05f930fb4cdbbb40c89e573c Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Thu, 26 Mar 2020 02:25:15 +0800 Subject: [PATCH 02/23] Update browser.js --- lib/client/browser.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/client/browser.js b/lib/client/browser.js index f92396bd..93a2d8a2 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -219,14 +219,16 @@ require("./discovery.js"); }); QUnit.log(function(details) { - const result = { - description: details.message, - suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], - success: details.result, - log: testResult.errors || [], - time: new Date().getTime() - timer - }; - karma.result(result); + if (config.logAllAssersions) { + const result = { + description: details.message, + suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], + success: details.result, + log: testResult.errors || [], + time: new Date().getTime() - timer + }; + karma.result(result); + } if (!details.result) { let msg = ""; From b9605f35fbf02e65c2e5cf9fb400a541404c49d9 Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Wed, 8 Apr 2020 15:42:59 +0800 Subject: [PATCH 03/23] Update browser.js --- lib/client/browser.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/client/browser.js b/lib/client/browser.js index 93a2d8a2..940448df 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -219,16 +219,6 @@ require("./discovery.js"); }); QUnit.log(function(details) { - if (config.logAllAssersions) { - const result = { - description: details.message, - suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], - success: details.result, - log: testResult.errors || [], - time: new Date().getTime() - timer - }; - karma.result(result); - } if (!details.result) { let msg = ""; @@ -248,6 +238,16 @@ require("./discovery.js"); testResult.success = false; testResult.errors.push(msg); } + if (config.logAssertions) { + const result = { + description: details.message, + suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], + success: details.result, + log: testResult.errors || [], + time: new Date().getTime() - timer + }; + karma.result(result); + } }); QUnit.testDone(function(test) { From 377d7ff73e71ccf21b43b61663892e1aebc9786f Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Thu, 23 Apr 2020 14:23:53 +0800 Subject: [PATCH 04/23] add integration tests(unfinished) --- .../karma-reporter/formatter.js | 44 +++++++++++++ .../karma-reporter/index.js | 53 ++++++++++++++++ .../karma-reporter/writer.js | 16 +++++ .../application-log-assersion/karma.conf.js | 61 +++++++++++++++++++ .../application-log-assersion/webapp/foo.js | 3 + .../webapp/manifest.json | 5 ++ .../webapp/test/test.qunit.html | 15 +++++ .../webapp/test/test.qunit.js | 15 +++++ .../webapp/test/testsuite.qunit.html | 10 +++ .../webapp/test/testsuite.qunit.js | 10 +++ 10 files changed, 232 insertions(+) create mode 100644 test/integration/application-log-assersion/karma-reporter/formatter.js create mode 100644 test/integration/application-log-assersion/karma-reporter/index.js create mode 100644 test/integration/application-log-assersion/karma-reporter/writer.js create mode 100644 test/integration/application-log-assersion/karma.conf.js create mode 100644 test/integration/application-log-assersion/webapp/foo.js create mode 100644 test/integration/application-log-assersion/webapp/manifest.json create mode 100644 test/integration/application-log-assersion/webapp/test/test.qunit.html create mode 100644 test/integration/application-log-assersion/webapp/test/test.qunit.js create mode 100644 test/integration/application-log-assersion/webapp/test/testsuite.qunit.html create mode 100644 test/integration/application-log-assersion/webapp/test/testsuite.qunit.js diff --git a/test/integration/application-log-assersion/karma-reporter/formatter.js b/test/integration/application-log-assersion/karma-reporter/formatter.js new file mode 100644 index 00000000..4759d4d3 --- /dev/null +++ b/test/integration/application-log-assersion/karma-reporter/formatter.js @@ -0,0 +1,44 @@ +"use strict"; + +var _ = require("lodash"); + +module.exports = function (history) { + var cucumberJson = []; + + _.forEach(history, function (feature, featureName) { + var elements = []; + var identifier = _.split(featureName, " "); + var tag = identifier[0]; + var name = identifier.slice(1).join(" "); + + _.forEach(feature, function (scenario, scenarioName) { + elements.push({ + name: scenarioName, + type: "scenario", + keyword: "Scenario", + steps: _.map(scenario, function (step) { + return { + keyword: "", + name: step.description, + result: { + duration: step.time * 1000000, + status: step.success ? "passed" : "failed" + } + }; + }) + }); + }); + + cucumberJson.push({ + keyword: "Feature", + name: name, + uri: _.camelCase(name), + tags: [{ + name: tag + }], + elements: elements + }); + }); + + return cucumberJson; +}; diff --git a/test/integration/application-log-assersion/karma-reporter/index.js b/test/integration/application-log-assersion/karma-reporter/index.js new file mode 100644 index 00000000..1d642b4f --- /dev/null +++ b/test/integration/application-log-assersion/karma-reporter/index.js @@ -0,0 +1,53 @@ +"use strict"; + +var _ = require("lodash"); + +var formatter = require("./formatter"); +var writer = require("./writer"); + +var CucumberReporter = function (baseReporterDecorator, config, logger, helper) { + var log = logger.create("reporter.cucumber"); + var reporterConfig = config.cucumberReporter || {}; + var out = reporterConfig.out || "stdout"; + var history = {}; + + baseReporterDecorator(this); + + this.adapters = [function (msg) { + process.stdout.write.bind(process.stdout)(msg); + }]; + + this.onSpecComplete = function (browser, result) { + console.log("--------------------------------- debug ---------------------------------"); + console.log(JSON.stringify(result)); + var suite = result.suite[1]; + var scenario = result.suite[2]; + var step = result.suite[3]; + + if (!reporterConfig.prefix || reporterConfig.prefix && _.startsWith(suite, reporterConfig.prefix)) { + history[suite] = history[suite] || {}; + history[suite][scenario] = history[suite][scenario] || []; + if (step) { + history[suite][scenario].push(result); + } + } + console.log("--------------------------------- debug ---------------------------------"); + }; + + this.onRunComplete = function () { + var cucumberJson = formatter(history); + var jsonResult = JSON.stringify(cucumberJson, null, 2) + "\n"; + + if (out === "stdout") { + process.stdout.write(jsonResult); + } else { + writer(helper, out, log, jsonResult); + } + }; +}; + +CucumberReporter.$inject = ["baseReporterDecorator", "config", "logger", "helper", "formatError"]; + +module.exports = { + "reporter:cucumber": ["type", CucumberReporter] +}; diff --git a/test/integration/application-log-assersion/karma-reporter/writer.js b/test/integration/application-log-assersion/karma-reporter/writer.js new file mode 100644 index 00000000..d7380b83 --- /dev/null +++ b/test/integration/application-log-assersion/karma-reporter/writer.js @@ -0,0 +1,16 @@ +"use strict"; + +var path = require("path"); +var fs = require("fs"); + +module.exports = function (helper, out, log, jsonResult) { + helper.mkdirIfNotExists(path.dirname(out), function () { + fs.writeFile(out, jsonResult, function (err) { + if (err) { + log.error("Cannot write JSON\n\t" + err.message); + } else { + log.info("JSON written to %s", out); + } + }); + }); +}; diff --git a/test/integration/application-log-assersion/karma.conf.js b/test/integration/application-log-assersion/karma.conf.js new file mode 100644 index 00000000..b258888f --- /dev/null +++ b/test/integration/application-log-assersion/karma.conf.js @@ -0,0 +1,61 @@ +const customCucumberReporter = require("./karma-reporter/index"); +const customKarmaUI5 = require("../../../lib/index"); + +module.exports = function(config) { + "use strict"; + + require("../karma-base.conf")(config); + config.set({ + plugins: [ + "karma-chrome-launcher", + "karma-coverage", + customKarmaUI5, + customCucumberReporter + ], + + ui5: { + type: "application", + mode: "html", + testpage: "webapp/test/test.qunit.html", + url: "http://localhost:" + config.localUI5ServerPort + }, + + frameworks: ["ui5"], + + preprocessors: { + "{webapp,webapp/!(test)}/*.js": ["coverage"] + }, + cucumberReporter: { + out: "cucumber.json", + prefix: "Feature" + }, + + coverageReporter: { + includeAllSources: true, + reporters: [ + { + type: "json", + dir: "coverage", + subdir: "json" + } + ], + check: { + each: { + statements: 100, + branches: 100, + functions: 100, + lines: 100 + } + } + }, + + reporters: ["progress", "coverage"] + + }); +}; + +module.exports.assertions = function({expect, log}) { + const coverage = require("./coverage/json/coverage-final.json"); + const files = Object.keys(coverage); + expect(files).toHaveLength(1); +}; diff --git a/test/integration/application-log-assersion/webapp/foo.js b/test/integration/application-log-assersion/webapp/foo.js new file mode 100644 index 00000000..5aaa0e64 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/foo.js @@ -0,0 +1,3 @@ +sap.ui.define(function() { + return "foo"; +}); diff --git a/test/integration/application-log-assersion/webapp/manifest.json b/test/integration/application-log-assersion/webapp/manifest.json new file mode 100644 index 00000000..36e269f7 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/manifest.json @@ -0,0 +1,5 @@ +{ + "sap.app": { + "id": "sap.karma.ui5.test" + } +} diff --git a/test/integration/application-log-assersion/webapp/test/test.qunit.html b/test/integration/application-log-assersion/webapp/test/test.qunit.html new file mode 100644 index 00000000..81aeffeb --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/test.qunit.html @@ -0,0 +1,15 @@ + + + + + QUnit Test + + + + + + + +
+ + diff --git a/test/integration/application-log-assersion/webapp/test/test.qunit.js b/test/integration/application-log-assersion/webapp/test/test.qunit.js new file mode 100644 index 00000000..64b61da5 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/test.qunit.js @@ -0,0 +1,15 @@ +/* global QUnit */ + +QUnit.config.autostart = false; + +sap.ui.getCore().attachInit(function() { + "use strict"; + + sap.ui.require(["test/app/foo"], function() { + QUnit.test("Karma", function(assert) { + assert.ok(parent.__karma__.files["/base/webapp/.dotfile"], "Karma files should contain dotfiles"); + }); + + QUnit.start(); + }); +}); diff --git a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html new file mode 100644 index 00000000..3153df14 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html @@ -0,0 +1,10 @@ + + + + Testsuite + + + + + + diff --git a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js new file mode 100644 index 00000000..ae283fc8 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js @@ -0,0 +1,10 @@ +window.suite = function() { + "use strict"; + + // eslint-disable-next-line new-cap + const oSuite = new parent.jsUnitTestSuite(); + const sContextPath = location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1); + oSuite.addTestPage(sContextPath + "test.qunit.html"); + + return oSuite; +}; From 62ca5dbdb70444415e50442e6407ce0ab35bb5a3 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Wed, 6 May 2020 14:55:40 +0800 Subject: [PATCH 05/23] add integration tests and add config initialization --- .gitignore | 2 + lib/framework.js | 1 + .../karma-reporter/index.js | 5 +- .../application-log-assersion/karma.conf.js | 22 ++-- .../application-log-assersion/webapp/foo.js | 3 - .../webapp/manifest.json | 5 - .../webapp/test/GherkinTestRunner.html | 24 +++++ .../webapp/test/GherkinTestRunner.js | 21 ++++ .../webapp/test/Requirements1.feature | 23 ++++ .../webapp/test/Steps.js | 100 ++++++++++++++++++ .../webapp/test/Website.html | 15 +++ .../webapp/test/WebsiteCode.js | 44 ++++++++ .../webapp/test/manifest.json | 26 +++++ .../webapp/test/test.qunit.html | 15 --- .../webapp/test/test.qunit.js | 15 --- .../webapp/test/testsuite.qunit.html | 10 -- .../webapp/test/testsuite.qunit.js | 10 -- .../application-proxy/karma.conf.js | 5 +- .../application-script-mode/karma.conf.js | 6 +- .../karma.conf.js | 6 +- .../application-ui5-tooling/karma.conf.js | 6 +- test/integration/integration.test.js | 2 +- .../library-custompath/karma.conf.js | 6 +- test/integration/library-proxy/karma.conf.js | 6 +- .../library-script-mode/karma.conf.js | 6 +- .../library-tooling-script-mode/karma.conf.js | 6 +- .../karma.conf.js | 6 +- .../library-ui5-tooling/karma.conf.js | 7 +- 28 files changed, 322 insertions(+), 81 deletions(-) delete mode 100644 test/integration/application-log-assersion/webapp/foo.js delete mode 100644 test/integration/application-log-assersion/webapp/manifest.json create mode 100644 test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html create mode 100644 test/integration/application-log-assersion/webapp/test/GherkinTestRunner.js create mode 100644 test/integration/application-log-assersion/webapp/test/Requirements1.feature create mode 100644 test/integration/application-log-assersion/webapp/test/Steps.js create mode 100644 test/integration/application-log-assersion/webapp/test/Website.html create mode 100644 test/integration/application-log-assersion/webapp/test/WebsiteCode.js create mode 100644 test/integration/application-log-assersion/webapp/test/manifest.json delete mode 100644 test/integration/application-log-assersion/webapp/test/test.qunit.html delete mode 100644 test/integration/application-log-assersion/webapp/test/test.qunit.js delete mode 100644 test/integration/application-log-assersion/webapp/test/testsuite.qunit.html delete mode 100644 test/integration/application-log-assersion/webapp/test/testsuite.qunit.js diff --git a/.gitignore b/.gitignore index c760ecae..4004deb6 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ deploy_key # Custom directories dist/ + +cucumber.js \ No newline at end of file diff --git a/lib/framework.js b/lib/framework.js index 4f90d3cf..8a49af53 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -116,6 +116,7 @@ class Framework { // Relevant options (e.g. testpage, config, tests) will be written to the client section. this.config.client.ui5 = {}; this.config.client.ui5.useIframe = true; // for now only allow using iframes in HTML mode + this.config.client.ui5.logAssertions = config.ui5 && config.ui5.logAssertions || false; this.config.ui5 = config.ui5 || {}; this.config.proxies = config.proxies || {}; this.config.middleware = config.middleware || []; diff --git a/test/integration/application-log-assersion/karma-reporter/index.js b/test/integration/application-log-assersion/karma-reporter/index.js index 1d642b4f..47c5ff83 100644 --- a/test/integration/application-log-assersion/karma-reporter/index.js +++ b/test/integration/application-log-assersion/karma-reporter/index.js @@ -18,10 +18,8 @@ var CucumberReporter = function (baseReporterDecorator, config, logger, helper) }]; this.onSpecComplete = function (browser, result) { - console.log("--------------------------------- debug ---------------------------------"); - console.log(JSON.stringify(result)); var suite = result.suite[1]; - var scenario = result.suite[2]; + var scenario = result.description; var step = result.suite[3]; if (!reporterConfig.prefix || reporterConfig.prefix && _.startsWith(suite, reporterConfig.prefix)) { @@ -31,7 +29,6 @@ var CucumberReporter = function (baseReporterDecorator, config, logger, helper) history[suite][scenario].push(result); } } - console.log("--------------------------------- debug ---------------------------------"); }; this.onRunComplete = function () { diff --git a/test/integration/application-log-assersion/karma.conf.js b/test/integration/application-log-assersion/karma.conf.js index b258888f..8d81a14e 100644 --- a/test/integration/application-log-assersion/karma.conf.js +++ b/test/integration/application-log-assersion/karma.conf.js @@ -16,8 +16,9 @@ module.exports = function(config) { ui5: { type: "application", mode: "html", - testpage: "webapp/test/test.qunit.html", - url: "http://localhost:" + config.localUI5ServerPort + testpage: "webapp/test/GherkinTestRunner.html", + url: "http://localhost:" + config.localUI5ServerPort, + logAssertions: true }, frameworks: ["ui5"], @@ -26,8 +27,8 @@ module.exports = function(config) { "{webapp,webapp/!(test)}/*.js": ["coverage"] }, cucumberReporter: { - out: "cucumber.json", - prefix: "Feature" + out: "application-log-assersion/cucumber.json", + prefix: "" }, coverageReporter: { @@ -48,14 +49,19 @@ module.exports = function(config) { } } }, + autoWatch: false, + singleRun: true, - reporters: ["progress", "coverage"] + reporters: ["progress", "coverage", "cucumber"] }); }; module.exports.assertions = function({expect, log}) { - const coverage = require("./coverage/json/coverage-final.json"); - const files = Object.keys(coverage); - expect(files).toHaveLength(1); + const features = require("./cucumber.json"); + const scenarios = features[0].elements; + const steps = scenarios[0].steps; + expect(features).toHaveLength(1); + expect(scenarios).toHaveLength(12); + expect(steps).toHaveLength(2); }; diff --git a/test/integration/application-log-assersion/webapp/foo.js b/test/integration/application-log-assersion/webapp/foo.js deleted file mode 100644 index 5aaa0e64..00000000 --- a/test/integration/application-log-assersion/webapp/foo.js +++ /dev/null @@ -1,3 +0,0 @@ -sap.ui.define(function() { - return "foo"; -}); diff --git a/test/integration/application-log-assersion/webapp/manifest.json b/test/integration/application-log-assersion/webapp/manifest.json deleted file mode 100644 index 36e269f7..00000000 --- a/test/integration/application-log-assersion/webapp/manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sap.app": { - "id": "sap.karma.ui5.test" - } -} diff --git a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html new file mode 100644 index 00000000..4e12672e --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html @@ -0,0 +1,24 @@ + + + + + Using Gherkin with OPA5 + + + + + + + +
+
+ + + + + diff --git a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.js b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.js new file mode 100644 index 00000000..ae04cf07 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.js @@ -0,0 +1,21 @@ +/* global QUnit */ +window.QUnit = { + config: { + autostart: false + } +}; + +sap.ui.require([ + "sap/ui/test/gherkin/opa5TestHarness", + // Code coverage will be calculated for all modules loaded after the harness + "GherkinWithOPA5/Steps" +], function(opa5TestHarness, Steps) { + "use strict"; + + opa5TestHarness.test({ + featurePath: "GherkinWithOPA5.Requirements1", + steps: Steps + }); + + QUnit.start(); +}); diff --git a/test/integration/application-log-assersion/webapp/test/Requirements1.feature b/test/integration/application-log-assersion/webapp/test/Requirements1.feature new file mode 100644 index 00000000..71211cee --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/Requirements1.feature @@ -0,0 +1,23 @@ +Feature: Clicking Buttons Is a Life Saving Activity + Clicking buttons saves lemmings' lives. For the mere cost of a cheap home PC you + can save thousands of lemmings daily by clicking buttons all day long. + + Background: + Given I have started the app + And I can see the life saving button + + Scenario: Click a button, save a life! + Given I check how many lemmings have been saved already + When I click on the life saving button + Then I save a lemming's life + + Scenario: The saved lemming has a name + When I click on the life saving button + Then I see Alice at the end of the list of named lemmings + + @wip + Scenario: Lemmings don't really throw themselves off cliffs + Given there was a documentary of lemmings throwing themselves off a cliff + Given this film greatly affected people's perception of lemmings + Given this part of the film was faked + Then we expect the myth of suicide lemmings to persist despite its falsity diff --git a/test/integration/application-log-assersion/webapp/test/Steps.js b/test/integration/application-log-assersion/webapp/test/Steps.js new file mode 100644 index 00000000..8b3854d9 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/Steps.js @@ -0,0 +1,100 @@ +sap.ui.define([ + "sap/base/Log", + "sap/ui/test/gherkin/StepDefinitions", + "sap/ui/test/Opa5", + "sap/ui/test/actions/Press" +], function(Log, StepDefinitions, Opa5, Press) { + "use strict"; + + var oOpa5 = new Opa5(); + + /** + * @param {function} fnCallback - executed once the number of lemmings saved is determined. + * Receives one parameter: "iNumberOfLemmingsSaved" + */ + function getNumberOfLemmingsSaved(fnCallback) { + oOpa5.waitFor({ + id: "num-lemmings-saved", + success: function(oLabel) { + var sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; + var iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); + fnCallback(iNumberOfLemmingsSaved); + } + }); + } + + var Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { + init: function() { + + this.register(/^I have started the app$/i, function() { + oOpa5.iStartMyAppInAFrame(sap.ui.require.toUrl("GherkinWithOPA5/Website.html")); + }); + + this.register(/^I can see the life saving button$/i, function() { + oOpa5.waitFor({ + id: "life-saving-button", + success: function(oButton) { + Opa5.assert.strictEqual(oButton.getText(), "Save a Lemming", + "Verified that we can see the life saving button"); + } + }); + }); + + this.register(/^I check how many lemmings have been saved already$/i, function() { + getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { + this.iNumLemmings = iNumberOfLemmingsSaved; + }.bind(this)); + }); + + this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, + function(sNumTimes) { + var iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; + for (var i = 0; i < iNumTimes; ++i) { + oOpa5.waitFor({ + id: "life-saving-button", + actions: new Press() + }); + } + }); + + this.register(/^I save a lemming's life$/i, function() { + getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { + var iExpectedSavedLemmings = this.iNumLemmings + 1; + Opa5.assert.strictEqual(iNumberOfLemmingsSaved, iExpectedSavedLemmings, + "Verified correct number of lemmings saved"); + }.bind(this)); + }); + + this.register(/^I can see the following named lemmings:$/i, function(aDataTable) { + aDataTable.forEach(function(sLemmingName, iLemmingId) { + oOpa5.waitFor({ + id: "lemming-name-" + (iLemmingId + 1), + success: function(oLabel) { + Opa5.assert.strictEqual(oLabel.getText(), sLemmingName, + "Verified lemming: " + sLemmingName); + } + }); + }); + }); + + this.register(/^I see (\w+) at the end of the list of named lemmings$/i, function(sName) { + oOpa5.waitFor({ + id: "layout", + success: function(oLayout) { + var aContent = oLayout.getContent(); + var oLastContentItem = aContent[aContent.length - 1]; + Opa5.assert.strictEqual(oLastContentItem.getText(), sName, + "Verified lemming: " + sName); + } + }); + }); + }, + + closeApplication: function() { + Log.info("Closing application"); + } + }); + + return Steps; + +}); \ No newline at end of file diff --git a/test/integration/application-log-assersion/webapp/test/Website.html b/test/integration/application-log-assersion/webapp/test/Website.html new file mode 100644 index 00000000..ef9e0e4c --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/Website.html @@ -0,0 +1,15 @@ + + + Using Gherkin with OPA5 Website + + + + +
+ + \ No newline at end of file diff --git a/test/integration/application-log-assersion/webapp/test/WebsiteCode.js b/test/integration/application-log-assersion/webapp/test/WebsiteCode.js new file mode 100644 index 00000000..63c416ec --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/WebsiteCode.js @@ -0,0 +1,44 @@ +sap.ui.getCore().attachInit(function() { + "use strict"; + + var sText = "Number of lemmings saved: "; + var iNumSavedLemmings = 0; + + var oTitle = sap.m.Label({ + id: "lemming-website-title", + text: "Lemming Life Saving Machine" + }); + + var oLabel = new sap.m.Label({ + id: "num-lemmings-saved", + text: sText + iNumSavedLemmings + }); + + var aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", + "Georgia", "Holly", "Idris", "Julien", "Kevin", "Lucia", "Michael", "Nancy", + "Oscar", "Peter", "Qubert", "Rascal", "Susan", "Terry", "Ursula", "Vicky", + "Walter", "Xavier", "Yolanda", "Zelda"]; + + var oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); + + var oButton = new sap.m.Button({ + id: "life-saving-button", + text: "Save a Lemming", + press: function() { + iNumSavedLemmings += 1; + oLabel.setText(sText + iNumSavedLemmings); + + var oNewLabel = new sap.m.Label({ + id: "lemming-name-" + iNumSavedLemmings, + text: aLemmingNames[(iNumSavedLemmings - 1) % aLemmingNames.length] + }); + oLayout.addContent(oNewLabel); + } + }); + + oLayout.addContent(oTitle); + oLayout.addContent(oButton); + oLayout.addContent(oLabel); + oLayout.placeAt("uiArea"); + +}); \ No newline at end of file diff --git a/test/integration/application-log-assersion/webapp/test/manifest.json b/test/integration/application-log-assersion/webapp/test/manifest.json new file mode 100644 index 00000000..85cf4bb2 --- /dev/null +++ b/test/integration/application-log-assersion/webapp/test/manifest.json @@ -0,0 +1,26 @@ +{ + "sap.app": { + "id": "sap.ui.core.sample.gherkin.GherkinWithOPA5", + "applicationVersion": { + "version": "1.0.0" + } + }, + "sap.ui5": { + "config": { + "sample": { + "iframe": "GherkinTestRunner.html", + "stretch": true, + "files": [ + "GherkinTestRunner.html", + "GherkinTestRunner.js", + "Requirements1.feature", + "Requirements2.feature", + "Steps.js", + "Website.html", + "WebsiteCode.js", + "manifest.json" + ] + } + } + } +} \ No newline at end of file diff --git a/test/integration/application-log-assersion/webapp/test/test.qunit.html b/test/integration/application-log-assersion/webapp/test/test.qunit.html deleted file mode 100644 index 81aeffeb..00000000 --- a/test/integration/application-log-assersion/webapp/test/test.qunit.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - QUnit Test - - - - - - - -
- - diff --git a/test/integration/application-log-assersion/webapp/test/test.qunit.js b/test/integration/application-log-assersion/webapp/test/test.qunit.js deleted file mode 100644 index 64b61da5..00000000 --- a/test/integration/application-log-assersion/webapp/test/test.qunit.js +++ /dev/null @@ -1,15 +0,0 @@ -/* global QUnit */ - -QUnit.config.autostart = false; - -sap.ui.getCore().attachInit(function() { - "use strict"; - - sap.ui.require(["test/app/foo"], function() { - QUnit.test("Karma", function(assert) { - assert.ok(parent.__karma__.files["/base/webapp/.dotfile"], "Karma files should contain dotfiles"); - }); - - QUnit.start(); - }); -}); diff --git a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html deleted file mode 100644 index 3153df14..00000000 --- a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - Testsuite - - - - - - diff --git a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js b/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js deleted file mode 100644 index ae283fc8..00000000 --- a/test/integration/application-log-assersion/webapp/test/testsuite.qunit.js +++ /dev/null @@ -1,10 +0,0 @@ -window.suite = function() { - "use strict"; - - // eslint-disable-next-line new-cap - const oSuite = new parent.jsUnitTestSuite(); - const sContextPath = location.pathname.substring(0, location.pathname.lastIndexOf("/") + 1); - oSuite.addTestPage(sContextPath + "test.qunit.html"); - - return oSuite; -}; diff --git a/test/integration/application-proxy/karma.conf.js b/test/integration/application-proxy/karma.conf.js index e1b24963..53beb020 100644 --- a/test/integration/application-proxy/karma.conf.js +++ b/test/integration/application-proxy/karma.conf.js @@ -43,5 +43,8 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("application-proxy/webapp/foo.js"); + const sWindowsExpect = "application-proxy\\webapp\\foo.js"; + const sLinuxExpect = "application-proxy/webapp/foo.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/application-script-mode/karma.conf.js b/test/integration/application-script-mode/karma.conf.js index db2cc404..f94418d8 100644 --- a/test/integration/application-script-mode/karma.conf.js +++ b/test/integration/application-script-mode/karma.conf.js @@ -58,5 +58,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("application-script-mode/webapp/foo.js"); + + const sWindowsExpect = "application-script-mode\\webapp\\foo.js"; + const sLinuxExpect = "application-script-mode/webapp/foo.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/application-tooling-script-mode/karma.conf.js b/test/integration/application-tooling-script-mode/karma.conf.js index 2446b535..7bca7bd7 100644 --- a/test/integration/application-tooling-script-mode/karma.conf.js +++ b/test/integration/application-tooling-script-mode/karma.conf.js @@ -57,5 +57,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("application-tooling-script-mode/webapp/foo.js"); + + const sWindowsExpect = "application-tooling-script-mode\\webapp\\foo.js"; + const sLinuxExpect = "application-tooling-script-mode/webapp/foo.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/application-ui5-tooling/karma.conf.js b/test/integration/application-ui5-tooling/karma.conf.js index 378dd3d2..d315788e 100644 --- a/test/integration/application-ui5-tooling/karma.conf.js +++ b/test/integration/application-ui5-tooling/karma.conf.js @@ -38,5 +38,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("application-ui5-tooling/webapp/foo.js"); + + const sWindowsExpect = "application-ui5-tooling\\webapp\\foo.js"; + const sLinuxExpect = "application-ui5-tooling/webapp/foo.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/integration.test.js b/test/integration/integration.test.js index d0832766..17ef2f7d 100644 --- a/test/integration/integration.test.js +++ b/test/integration/integration.test.js @@ -54,7 +54,7 @@ const registerIntegrationTest = async (configPath) => { }; // Increase test timeout to 10s (default 5s) -jest.setTimeout(10000); +jest.setTimeout(100000); beforeAll(async (done) => { try { diff --git a/test/integration/library-custompath/karma.conf.js b/test/integration/library-custompath/karma.conf.js index 86c2d791..af526e30 100644 --- a/test/integration/library-custompath/karma.conf.js +++ b/test/integration/library-custompath/karma.conf.js @@ -47,5 +47,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-custompath/src/main/js/sap/test/lib/library.js"); + + const sWindowsExpect = "library-custompath\\src\\main\\js\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-custompath/src/main/js/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/library-proxy/karma.conf.js b/test/integration/library-proxy/karma.conf.js index ae98974d..aeba3f84 100644 --- a/test/integration/library-proxy/karma.conf.js +++ b/test/integration/library-proxy/karma.conf.js @@ -43,5 +43,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-proxy/src/sap/test/lib/library.js"); + + const sWindowsExpect = "library-proxy\\src\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-proxy/src/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/library-script-mode/karma.conf.js b/test/integration/library-script-mode/karma.conf.js index d244a929..f738a258 100644 --- a/test/integration/library-script-mode/karma.conf.js +++ b/test/integration/library-script-mode/karma.conf.js @@ -53,5 +53,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-script-mode/src/sap/test/lib/library.js"); + + const sWindowsExpect = "library-script-mode\\src\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-script-mode/src/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/library-tooling-script-mode/karma.conf.js b/test/integration/library-tooling-script-mode/karma.conf.js index d2e331a0..a70171ba 100644 --- a/test/integration/library-tooling-script-mode/karma.conf.js +++ b/test/integration/library-tooling-script-mode/karma.conf.js @@ -51,5 +51,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-tooling-script-mode/src/sap/test/lib/library.js"); + + const sWindowsExpect = "library-tooling-script-mode\\src\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-tooling-script-mode/src/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/library-ui5-tooling-multiple-testsuites/karma.conf.js b/test/integration/library-ui5-tooling-multiple-testsuites/karma.conf.js index 7bf25b79..6737c2ee 100644 --- a/test/integration/library-ui5-tooling-multiple-testsuites/karma.conf.js +++ b/test/integration/library-ui5-tooling-multiple-testsuites/karma.conf.js @@ -42,5 +42,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-ui5-tooling-multiple-testsuites/src/sap/test/lib/library.js"); + + const sWindowsExpect = "library-ui5-tooling-multiple-testsuites\\src\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-ui5-tooling-multiple-testsuites/src/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; diff --git a/test/integration/library-ui5-tooling/karma.conf.js b/test/integration/library-ui5-tooling/karma.conf.js index 341fa451..82aa2033 100644 --- a/test/integration/library-ui5-tooling/karma.conf.js +++ b/test/integration/library-ui5-tooling/karma.conf.js @@ -1,3 +1,4 @@ + module.exports = function(config) { "use strict"; @@ -38,5 +39,9 @@ module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("library-ui5-tooling/src/sap/test/lib/library.js"); + + const sWindowsExpect = "library-ui5-tooling\\src\\sap\\test\\lib\\library.js"; + const sLinuxExpect = "library-ui5-tooling/src/sap/test/lib/library.js"; + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); }; From 54001094973c909ea35ab6974afb9037aead6f4f Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Wed, 6 May 2020 15:24:58 +0800 Subject: [PATCH 06/23] fix eslint --- .../karma-reporter/formatter.js | 72 ++++++++-------- .../karma-reporter/index.js | 84 +++++++++---------- .../karma-reporter/writer.js | 24 +++--- .../webapp/test/Steps.js | 31 +++---- .../webapp/test/WebsiteCode.js | 19 ++--- 5 files changed, 115 insertions(+), 115 deletions(-) diff --git a/test/integration/application-log-assersion/karma-reporter/formatter.js b/test/integration/application-log-assersion/karma-reporter/formatter.js index 4759d4d3..4fb7be8f 100644 --- a/test/integration/application-log-assersion/karma-reporter/formatter.js +++ b/test/integration/application-log-assersion/karma-reporter/formatter.js @@ -1,44 +1,44 @@ "use strict"; -var _ = require("lodash"); +const _ = require("lodash"); -module.exports = function (history) { - var cucumberJson = []; +module.exports = function(history) { + const cucumberJson = []; - _.forEach(history, function (feature, featureName) { - var elements = []; - var identifier = _.split(featureName, " "); - var tag = identifier[0]; - var name = identifier.slice(1).join(" "); + _.forEach(history, function(feature, featureName) { + const elements = []; + const identifier = _.split(featureName, " "); + const tag = identifier[0]; + const name = identifier.slice(1).join(" "); - _.forEach(feature, function (scenario, scenarioName) { - elements.push({ - name: scenarioName, - type: "scenario", - keyword: "Scenario", - steps: _.map(scenario, function (step) { - return { - keyword: "", - name: step.description, - result: { - duration: step.time * 1000000, - status: step.success ? "passed" : "failed" - } - }; - }) - }); - }); + _.forEach(feature, function(scenario, scenarioName) { + elements.push({ + name: scenarioName, + type: "scenario", + keyword: "Scenario", + steps: _.map(scenario, function(step) { + return { + keyword: "", + name: step.description, + result: { + duration: step.time * 1000000, + status: step.success ? "passed" : "failed" + } + }; + }) + }); + }); - cucumberJson.push({ - keyword: "Feature", - name: name, - uri: _.camelCase(name), - tags: [{ - name: tag - }], - elements: elements - }); - }); + cucumberJson.push({ + keyword: "Feature", + name: name, + uri: _.camelCase(name), + tags: [{ + name: tag + }], + elements: elements + }); + }); - return cucumberJson; + return cucumberJson; }; diff --git a/test/integration/application-log-assersion/karma-reporter/index.js b/test/integration/application-log-assersion/karma-reporter/index.js index 47c5ff83..412853ab 100644 --- a/test/integration/application-log-assersion/karma-reporter/index.js +++ b/test/integration/application-log-assersion/karma-reporter/index.js @@ -1,50 +1,50 @@ "use strict"; -var _ = require("lodash"); - -var formatter = require("./formatter"); -var writer = require("./writer"); - -var CucumberReporter = function (baseReporterDecorator, config, logger, helper) { - var log = logger.create("reporter.cucumber"); - var reporterConfig = config.cucumberReporter || {}; - var out = reporterConfig.out || "stdout"; - var history = {}; - - baseReporterDecorator(this); - - this.adapters = [function (msg) { - process.stdout.write.bind(process.stdout)(msg); - }]; - - this.onSpecComplete = function (browser, result) { - var suite = result.suite[1]; - var scenario = result.description; - var step = result.suite[3]; - - if (!reporterConfig.prefix || reporterConfig.prefix && _.startsWith(suite, reporterConfig.prefix)) { - history[suite] = history[suite] || {}; - history[suite][scenario] = history[suite][scenario] || []; - if (step) { - history[suite][scenario].push(result); - } - } - }; - - this.onRunComplete = function () { - var cucumberJson = formatter(history); - var jsonResult = JSON.stringify(cucumberJson, null, 2) + "\n"; - - if (out === "stdout") { - process.stdout.write(jsonResult); - } else { - writer(helper, out, log, jsonResult); - } - }; +const _ = require("lodash"); + +const formatter = require("./formatter"); +const writer = require("./writer"); + +const CucumberReporter = function(baseReporterDecorator, config, logger, helper) { + const log = logger.create("reporter.cucumber"); + const reporterConfig = config.cucumberReporter || {}; + const out = reporterConfig.out || "stdout"; + const history = {}; + + baseReporterDecorator(this); + + this.adapters = [function(msg) { + process.stdout.write.bind(process.stdout)(msg); + }]; + + this.onSpecComplete = function(browser, result) { + const suite = result.suite[1]; + const scenario = result.description; + const step = result.suite[3]; + + if (!reporterConfig.prefix || reporterConfig.prefix && _.startsWith(suite, reporterConfig.prefix)) { + history[suite] = history[suite] || {}; + history[suite][scenario] = history[suite][scenario] || []; + if (step) { + history[suite][scenario].push(result); + } + } + }; + + this.onRunComplete = function() { + const cucumberJson = formatter(history); + const jsonResult = JSON.stringify(cucumberJson, null, 2) + "\n"; + + if (out === "stdout") { + process.stdout.write(jsonResult); + } else { + writer(helper, out, log, jsonResult); + } + }; }; CucumberReporter.$inject = ["baseReporterDecorator", "config", "logger", "helper", "formatError"]; module.exports = { - "reporter:cucumber": ["type", CucumberReporter] + "reporter:cucumber": ["type", CucumberReporter] }; diff --git a/test/integration/application-log-assersion/karma-reporter/writer.js b/test/integration/application-log-assersion/karma-reporter/writer.js index d7380b83..dfe91d8c 100644 --- a/test/integration/application-log-assersion/karma-reporter/writer.js +++ b/test/integration/application-log-assersion/karma-reporter/writer.js @@ -1,16 +1,16 @@ "use strict"; -var path = require("path"); -var fs = require("fs"); +const path = require("path"); +const fs = require("fs"); -module.exports = function (helper, out, log, jsonResult) { - helper.mkdirIfNotExists(path.dirname(out), function () { - fs.writeFile(out, jsonResult, function (err) { - if (err) { - log.error("Cannot write JSON\n\t" + err.message); - } else { - log.info("JSON written to %s", out); - } - }); - }); +module.exports = function(helper, out, log, jsonResult) { + helper.mkdirIfNotExists(path.dirname(out), function() { + fs.writeFile(out, jsonResult, function(err) { + if (err) { + log.error("Cannot write JSON\n\t" + err.message); + } else { + log.info("JSON written to %s", out); + } + }); + }); }; diff --git a/test/integration/application-log-assersion/webapp/test/Steps.js b/test/integration/application-log-assersion/webapp/test/Steps.js index 8b3854d9..2f941c01 100644 --- a/test/integration/application-log-assersion/webapp/test/Steps.js +++ b/test/integration/application-log-assersion/webapp/test/Steps.js @@ -6,26 +6,25 @@ sap.ui.define([ ], function(Log, StepDefinitions, Opa5, Press) { "use strict"; - var oOpa5 = new Opa5(); + const oOpa5 = new Opa5(); /** - * @param {function} fnCallback - executed once the number of lemmings saved is determined. + * @param {Function} fnCallback - executed once the number of lemmings saved is determined. * Receives one parameter: "iNumberOfLemmingsSaved" */ function getNumberOfLemmingsSaved(fnCallback) { oOpa5.waitFor({ id: "num-lemmings-saved", success: function(oLabel) { - var sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; - var iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); + const sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; + const iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); fnCallback(iNumberOfLemmingsSaved); } }); } - var Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { + const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { init: function() { - this.register(/^I have started the app$/i, function() { oOpa5.iStartMyAppInAFrame(sap.ui.require.toUrl("GherkinWithOPA5/Website.html")); }); @@ -43,13 +42,14 @@ sap.ui.define([ this.register(/^I check how many lemmings have been saved already$/i, function() { getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { this.iNumLemmings = iNumberOfLemmingsSaved; + /* eslint-disable */ }.bind(this)); + /* eslint-enable */ }); - this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, - function(sNumTimes) { - var iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; - for (var i = 0; i < iNumTimes; ++i) { + this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, function(sNumTimes) { + const iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; + for (let i = 0; i < iNumTimes; ++i) { oOpa5.waitFor({ id: "life-saving-button", actions: new Press() @@ -59,10 +59,12 @@ sap.ui.define([ this.register(/^I save a lemming's life$/i, function() { getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { - var iExpectedSavedLemmings = this.iNumLemmings + 1; + const iExpectedSavedLemmings = this.iNumLemmings + 1; Opa5.assert.strictEqual(iNumberOfLemmingsSaved, iExpectedSavedLemmings, "Verified correct number of lemmings saved"); + /* eslint-disable */ }.bind(this)); + /* eslint-enable */ }); this.register(/^I can see the following named lemmings:$/i, function(aDataTable) { @@ -81,8 +83,8 @@ sap.ui.define([ oOpa5.waitFor({ id: "layout", success: function(oLayout) { - var aContent = oLayout.getContent(); - var oLastContentItem = aContent[aContent.length - 1]; + const aContent = oLayout.getContent(); + const oLastContentItem = aContent[aContent.length - 1]; Opa5.assert.strictEqual(oLastContentItem.getText(), sName, "Verified lemming: " + sName); } @@ -96,5 +98,4 @@ sap.ui.define([ }); return Steps; - -}); \ No newline at end of file +}); diff --git a/test/integration/application-log-assersion/webapp/test/WebsiteCode.js b/test/integration/application-log-assersion/webapp/test/WebsiteCode.js index 63c416ec..ba22b42e 100644 --- a/test/integration/application-log-assersion/webapp/test/WebsiteCode.js +++ b/test/integration/application-log-assersion/webapp/test/WebsiteCode.js @@ -1,34 +1,34 @@ sap.ui.getCore().attachInit(function() { "use strict"; - var sText = "Number of lemmings saved: "; - var iNumSavedLemmings = 0; + const sText = "Number of lemmings saved: "; + let iNumSavedLemmings = 0; - var oTitle = sap.m.Label({ + const oTitle = new sap.m.Label({ id: "lemming-website-title", text: "Lemming Life Saving Machine" }); - var oLabel = new sap.m.Label({ + const oLabel = new sap.m.Label({ id: "num-lemmings-saved", text: sText + iNumSavedLemmings }); - var aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", + const aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", "Georgia", "Holly", "Idris", "Julien", "Kevin", "Lucia", "Michael", "Nancy", "Oscar", "Peter", "Qubert", "Rascal", "Susan", "Terry", "Ursula", "Vicky", "Walter", "Xavier", "Yolanda", "Zelda"]; - var oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); + const oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); - var oButton = new sap.m.Button({ + const oButton = new sap.m.Button({ id: "life-saving-button", text: "Save a Lemming", press: function() { iNumSavedLemmings += 1; oLabel.setText(sText + iNumSavedLemmings); - var oNewLabel = new sap.m.Label({ + const oNewLabel = new sap.m.Label({ id: "lemming-name-" + iNumSavedLemmings, text: aLemmingNames[(iNumSavedLemmings - 1) % aLemmingNames.length] }); @@ -40,5 +40,4 @@ sap.ui.getCore().attachInit(function() { oLayout.addContent(oButton); oLayout.addContent(oLabel); oLayout.placeAt("uiArea"); - -}); \ No newline at end of file +}); From 51c331b1d4a9a0446707736e9daa2b19f5308c3e Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Thu, 28 May 2020 14:50:12 +0800 Subject: [PATCH 07/23] Update test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Oßwald <1410947+matz3@users.noreply.github.com> --- .../webapp/test/GherkinTestRunner.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html index 4e12672e..93674544 100644 --- a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html +++ b/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html @@ -5,7 +5,7 @@ Using Gherkin with OPA5 @@ -12,4 +12,4 @@
- \ No newline at end of file + From d0d11d86a8ffa365bdf0dabe20be96fde14100b9 Mon Sep 17 00:00:00 2001 From: EdStrickland <2499128545@qq.com> Date: Thu, 28 May 2020 14:51:06 +0800 Subject: [PATCH 09/23] Update test/integration/application-log-assersion/karma.conf.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Oßwald <1410947+matz3@users.noreply.github.com> --- test/integration/application-log-assersion/karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/application-log-assersion/karma.conf.js b/test/integration/application-log-assersion/karma.conf.js index 8d81a14e..5b36f6b9 100644 --- a/test/integration/application-log-assersion/karma.conf.js +++ b/test/integration/application-log-assersion/karma.conf.js @@ -27,7 +27,7 @@ module.exports = function(config) { "{webapp,webapp/!(test)}/*.js": ["coverage"] }, cucumberReporter: { - out: "application-log-assersion/cucumber.json", + out: "application-log-assertion/cucumber.json", prefix: "" }, From 98f551abf6b4a1cc5cc2360e9454e976388ffb74 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 2 Jun 2020 16:41:04 +0800 Subject: [PATCH 10/23] enhance config and integration tests 1) add new config logHTMLFilePath 2) add new case for the config --- .gitignore | 2 +- lib/client/browser.js | 13 +- lib/framework.js | 1 + .../karma-reporter/formatter.js | 44 ---- .../karma-reporter/index.js | 50 ----- .../karma-reporter/index.js | 31 +++ .../karma-reporter/writer.js | 0 .../karma.conf.js | 16 +- .../webapp/test/GherkinTestRunner.html | 2 +- .../webapp/test/GherkinTestRunner.js | 0 .../webapp/test/Requirements1.feature | 0 .../webapp/test/Steps.js | 0 .../webapp/test/Website.html | 2 +- .../webapp/test/WebsiteCode.js | 0 .../webapp/test/manifest.json | 0 .../karma-reporter/index.js | 31 +++ .../karma-reporter/writer.js | 16 ++ .../application-log-assertion/karma.conf.js | 61 ++++++ .../reports/test_report.json | 188 ++++++++++++++++++ .../webapp/test/GherkinTestRunner.html | 23 +++ .../webapp/test/GherkinTestRunner.js | 21 ++ .../webapp/test/Requirements1.feature | 23 +++ .../webapp/test/Steps.js | 101 ++++++++++ .../webapp/test/Website.html | 15 ++ .../webapp/test/WebsiteCode.js | 43 ++++ .../webapp/test/manifest.json | 26 +++ 26 files changed, 598 insertions(+), 111 deletions(-) delete mode 100644 test/integration/application-log-assersion/karma-reporter/formatter.js delete mode 100644 test/integration/application-log-assersion/karma-reporter/index.js create mode 100644 test/integration/application-log-assertion-with-cucumber-report/karma-reporter/index.js rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/karma-reporter/writer.js (100%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/karma.conf.js (73%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/GherkinTestRunner.html (81%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/GherkinTestRunner.js (100%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/Requirements1.feature (100%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/Steps.js (100%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/Website.html (82%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/WebsiteCode.js (100%) rename test/integration/{application-log-assersion => application-log-assertion-with-cucumber-report}/webapp/test/manifest.json (100%) create mode 100644 test/integration/application-log-assertion/karma-reporter/index.js create mode 100644 test/integration/application-log-assertion/karma-reporter/writer.js create mode 100644 test/integration/application-log-assertion/karma.conf.js create mode 100644 test/integration/application-log-assertion/reports/test_report.json create mode 100644 test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html create mode 100644 test/integration/application-log-assertion/webapp/test/GherkinTestRunner.js create mode 100644 test/integration/application-log-assertion/webapp/test/Requirements1.feature create mode 100644 test/integration/application-log-assertion/webapp/test/Steps.js create mode 100644 test/integration/application-log-assertion/webapp/test/Website.html create mode 100644 test/integration/application-log-assertion/webapp/test/WebsiteCode.js create mode 100644 test/integration/application-log-assertion/webapp/test/manifest.json diff --git a/.gitignore b/.gitignore index 4004deb6..f992a59a 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,4 @@ deploy_key # Custom directories dist/ -cucumber.js \ No newline at end of file +**/reports/cucumber_report.json \ No newline at end of file diff --git a/lib/client/browser.js b/lib/client/browser.js index 940448df..32d2601e 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -219,9 +219,8 @@ require("./discovery.js"); }); QUnit.log(function(details) { + let msg = ""; if (!details.result) { - let msg = ""; - if (details.message) { msg += details.message + "\n"; } @@ -239,11 +238,13 @@ require("./discovery.js"); testResult.errors.push(msg); } if (config.logAssertions) { + const testSuite = [details.module, details.name, details.message]; + const testSuiteWithHTMLFilePath = testSuite.unshift(qunitHtmlFile) && testSuite; const result = { description: details.message, - suite: details.module && [qunitHtmlFile, details.module, details.name, details.message] || [], + suite: details.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], success: details.result, - log: testResult.errors || [], + log: msg, time: new Date().getTime() - timer }; karma.result(result); @@ -251,9 +252,11 @@ require("./discovery.js"); }); QUnit.testDone(function(test) { + const testSuite = [test.module]; + const testSuiteWithHTMLFilePath = testSuite.unshift(qunitHtmlFile) && testSuite; const result = { description: test.name, - suite: test.module && [qunitHtmlFile, test.module] || [], + suite: test.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], success: testResult.success, log: testResult.errors || [], time: new Date().getTime() - timer diff --git a/lib/framework.js b/lib/framework.js index 8a49af53..189ca71c 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -117,6 +117,7 @@ class Framework { this.config.client.ui5 = {}; this.config.client.ui5.useIframe = true; // for now only allow using iframes in HTML mode this.config.client.ui5.logAssertions = config.ui5 && config.ui5.logAssertions || false; + this.config.client.ui5.logHTMLFilePath = config.ui5 && config.ui5.logHTMLFilePath || true; this.config.ui5 = config.ui5 || {}; this.config.proxies = config.proxies || {}; this.config.middleware = config.middleware || []; diff --git a/test/integration/application-log-assersion/karma-reporter/formatter.js b/test/integration/application-log-assersion/karma-reporter/formatter.js deleted file mode 100644 index 4fb7be8f..00000000 --- a/test/integration/application-log-assersion/karma-reporter/formatter.js +++ /dev/null @@ -1,44 +0,0 @@ -"use strict"; - -const _ = require("lodash"); - -module.exports = function(history) { - const cucumberJson = []; - - _.forEach(history, function(feature, featureName) { - const elements = []; - const identifier = _.split(featureName, " "); - const tag = identifier[0]; - const name = identifier.slice(1).join(" "); - - _.forEach(feature, function(scenario, scenarioName) { - elements.push({ - name: scenarioName, - type: "scenario", - keyword: "Scenario", - steps: _.map(scenario, function(step) { - return { - keyword: "", - name: step.description, - result: { - duration: step.time * 1000000, - status: step.success ? "passed" : "failed" - } - }; - }) - }); - }); - - cucumberJson.push({ - keyword: "Feature", - name: name, - uri: _.camelCase(name), - tags: [{ - name: tag - }], - elements: elements - }); - }); - - return cucumberJson; -}; diff --git a/test/integration/application-log-assersion/karma-reporter/index.js b/test/integration/application-log-assersion/karma-reporter/index.js deleted file mode 100644 index 412853ab..00000000 --- a/test/integration/application-log-assersion/karma-reporter/index.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; - -const _ = require("lodash"); - -const formatter = require("./formatter"); -const writer = require("./writer"); - -const CucumberReporter = function(baseReporterDecorator, config, logger, helper) { - const log = logger.create("reporter.cucumber"); - const reporterConfig = config.cucumberReporter || {}; - const out = reporterConfig.out || "stdout"; - const history = {}; - - baseReporterDecorator(this); - - this.adapters = [function(msg) { - process.stdout.write.bind(process.stdout)(msg); - }]; - - this.onSpecComplete = function(browser, result) { - const suite = result.suite[1]; - const scenario = result.description; - const step = result.suite[3]; - - if (!reporterConfig.prefix || reporterConfig.prefix && _.startsWith(suite, reporterConfig.prefix)) { - history[suite] = history[suite] || {}; - history[suite][scenario] = history[suite][scenario] || []; - if (step) { - history[suite][scenario].push(result); - } - } - }; - - this.onRunComplete = function() { - const cucumberJson = formatter(history); - const jsonResult = JSON.stringify(cucumberJson, null, 2) + "\n"; - - if (out === "stdout") { - process.stdout.write(jsonResult); - } else { - writer(helper, out, log, jsonResult); - } - }; -}; - -CucumberReporter.$inject = ["baseReporterDecorator", "config", "logger", "helper", "formatError"]; - -module.exports = { - "reporter:cucumber": ["type", CucumberReporter] -}; diff --git a/test/integration/application-log-assertion-with-cucumber-report/karma-reporter/index.js b/test/integration/application-log-assertion-with-cucumber-report/karma-reporter/index.js new file mode 100644 index 00000000..265fc59d --- /dev/null +++ b/test/integration/application-log-assertion-with-cucumber-report/karma-reporter/index.js @@ -0,0 +1,31 @@ +"use strict"; + +const writer = require("./writer"); + +const CucumberReporter = function(baseReporterDecorator, config, logger, helper) { + const log = logger.create("reporter.testReporter"); + const reporterConfig = config.testReporter || {}; + const out = reporterConfig.out; + const specs = []; + + baseReporterDecorator(this); + + this.adapters = [function(msg) { + process.stdout.write.bind(process.stdout)(msg); + }]; + + this.onSpecComplete = function(browser, result) { + specs.push(result); + }; + + this.onRunComplete = function() { + const jsonResult = JSON.stringify(specs, null, 2) + "\n"; + writer(helper, out, log, jsonResult); + }; +}; + +CucumberReporter.$inject = ["baseReporterDecorator", "config", "logger", "helper"]; + +module.exports = { + "reporter:testReporter": ["type", CucumberReporter] +}; diff --git a/test/integration/application-log-assersion/karma-reporter/writer.js b/test/integration/application-log-assertion-with-cucumber-report/karma-reporter/writer.js similarity index 100% rename from test/integration/application-log-assersion/karma-reporter/writer.js rename to test/integration/application-log-assertion-with-cucumber-report/karma-reporter/writer.js diff --git a/test/integration/application-log-assersion/karma.conf.js b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js similarity index 73% rename from test/integration/application-log-assersion/karma.conf.js rename to test/integration/application-log-assertion-with-cucumber-report/karma.conf.js index 5b36f6b9..9b03a719 100644 --- a/test/integration/application-log-assersion/karma.conf.js +++ b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js @@ -18,7 +18,8 @@ module.exports = function(config) { mode: "html", testpage: "webapp/test/GherkinTestRunner.html", url: "http://localhost:" + config.localUI5ServerPort, - logAssertions: true + logAssertions: true, + logHTMLFilePath: false }, frameworks: ["ui5"], @@ -27,7 +28,7 @@ module.exports = function(config) { "{webapp,webapp/!(test)}/*.js": ["coverage"] }, cucumberReporter: { - out: "application-log-assertion/cucumber.json", + out: "application-log-assertion-with-cucumber-report/reports/test_report.json", prefix: "" }, @@ -52,16 +53,13 @@ module.exports = function(config) { autoWatch: false, singleRun: true, - reporters: ["progress", "coverage", "cucumber"] + reporters: ["progress", "coverage", "testReporter"] }); }; module.exports.assertions = function({expect, log}) { - const features = require("./cucumber.json"); - const scenarios = features[0].elements; - const steps = scenarios[0].steps; - expect(features).toHaveLength(1); - expect(scenarios).toHaveLength(12); - expect(steps).toHaveLength(2); + const features = require("./reports/test_report.json"); + const featureName = features[0].suite[0]; + expect(featureName).toBe("Feature: Clicking Buttons Is a Life Saving Activity"); }; diff --git a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html similarity index 81% rename from test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html rename to test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html index 93674544..266a0e66 100644 --- a/test/integration/application-log-assersion/webapp/test/GherkinTestRunner.html +++ b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html @@ -5,7 +5,7 @@ Using Gherkin with OPA5 diff --git a/test/integration/application-log-assersion/webapp/test/WebsiteCode.js b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js similarity index 100% rename from test/integration/application-log-assersion/webapp/test/WebsiteCode.js rename to test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js diff --git a/test/integration/application-log-assersion/webapp/test/manifest.json b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/manifest.json similarity index 100% rename from test/integration/application-log-assersion/webapp/test/manifest.json rename to test/integration/application-log-assertion-with-cucumber-report/webapp/test/manifest.json diff --git a/test/integration/application-log-assertion/karma-reporter/index.js b/test/integration/application-log-assertion/karma-reporter/index.js new file mode 100644 index 00000000..265fc59d --- /dev/null +++ b/test/integration/application-log-assertion/karma-reporter/index.js @@ -0,0 +1,31 @@ +"use strict"; + +const writer = require("./writer"); + +const CucumberReporter = function(baseReporterDecorator, config, logger, helper) { + const log = logger.create("reporter.testReporter"); + const reporterConfig = config.testReporter || {}; + const out = reporterConfig.out; + const specs = []; + + baseReporterDecorator(this); + + this.adapters = [function(msg) { + process.stdout.write.bind(process.stdout)(msg); + }]; + + this.onSpecComplete = function(browser, result) { + specs.push(result); + }; + + this.onRunComplete = function() { + const jsonResult = JSON.stringify(specs, null, 2) + "\n"; + writer(helper, out, log, jsonResult); + }; +}; + +CucumberReporter.$inject = ["baseReporterDecorator", "config", "logger", "helper"]; + +module.exports = { + "reporter:testReporter": ["type", CucumberReporter] +}; diff --git a/test/integration/application-log-assertion/karma-reporter/writer.js b/test/integration/application-log-assertion/karma-reporter/writer.js new file mode 100644 index 00000000..dfe91d8c --- /dev/null +++ b/test/integration/application-log-assertion/karma-reporter/writer.js @@ -0,0 +1,16 @@ +"use strict"; + +const path = require("path"); +const fs = require("fs"); + +module.exports = function(helper, out, log, jsonResult) { + helper.mkdirIfNotExists(path.dirname(out), function() { + fs.writeFile(out, jsonResult, function(err) { + if (err) { + log.error("Cannot write JSON\n\t" + err.message); + } else { + log.info("JSON written to %s", out); + } + }); + }); +}; diff --git a/test/integration/application-log-assertion/karma.conf.js b/test/integration/application-log-assertion/karma.conf.js new file mode 100644 index 00000000..ba2a33ef --- /dev/null +++ b/test/integration/application-log-assertion/karma.conf.js @@ -0,0 +1,61 @@ +const customCucumberReporter = require("./karma-reporter/index"); +const customKarmaUI5 = require("../../../lib/index"); +module.exports = function(config) { + "use strict"; + + require("../karma-base.conf")(config); + config.set({ + plugins: [ + "karma-chrome-launcher", + "karma-coverage", + customKarmaUI5, + customCucumberReporter + ], + + ui5: { + type: "application", + mode: "html", + testpage: "webapp/test/GherkinTestRunner.html", + url: "http://localhost:" + config.localUI5ServerPort, + logAssertions: true + }, + + frameworks: ["ui5"], + + preprocessors: { + "{webapp,webapp/!(test)}/*.js": ["coverage"] + }, + testReporter: { + out: "application-log-assertion/reports/test_report.json" + }, + + coverageReporter: { + includeAllSources: true, + reporters: [ + { + type: "json", + dir: "coverage", + subdir: "json" + } + ], + check: { + each: { + statements: 100, + branches: 100, + functions: 100, + lines: 100 + } + } + }, + autoWatch: false, + singleRun: true, + + reporters: ["progress", "coverage", "testReporter"] + + }); +}; + +module.exports.assertions = function({expect, log}) { + const features = require("./reports/test_report.json"); + expect(features).toHaveLength(16); +}; diff --git a/test/integration/application-log-assertion/reports/test_report.json b/test/integration/application-log-assertion/reports/test_report.json new file mode 100644 index 00000000..0bf8b5cc --- /dev/null +++ b/test/integration/application-log-assertion/reports/test_report.json @@ -0,0 +1,188 @@ +[ + { + "description": "I have started the app", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "I have started the app" + ], + "success": true, + "log": "", + "time": 382 + }, + { + "description": "I can see the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "I can see the life saving button" + ], + "success": true, + "log": "", + "time": 2749 + }, + { + "description": "Verified that we can see the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "Verified that we can see the life saving button" + ], + "success": true, + "log": "", + "time": 2854 + }, + { + "description": "I check how many lemmings have been saved already", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "I check how many lemmings have been saved already" + ], + "success": true, + "log": "", + "time": 2878 + }, + { + "description": "I click on the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "I click on the life saving button" + ], + "success": true, + "log": "", + "time": 2899 + }, + { + "description": "I save a lemming's life", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "I save a lemming's life" + ], + "success": true, + "log": "", + "time": 3063 + }, + { + "description": "Verified correct number of lemmings saved", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: Click a button, save a life!", + "Verified correct number of lemmings saved" + ], + "success": true, + "log": "", + "time": 3112 + }, + { + "description": "Scenario: Click a button, save a life!", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity" + ], + "success": true, + "log": [], + "time": 3133 + }, + { + "description": "I have started the app", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "I have started the app" + ], + "success": true, + "log": "", + "time": 122 + }, + { + "description": "I can see the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "I can see the life saving button" + ], + "success": true, + "log": "", + "time": 1040 + }, + { + "description": "Verified that we can see the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "Verified that we can see the life saving button" + ], + "success": true, + "log": "", + "time": 1071 + }, + { + "description": "I click on the life saving button", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "I click on the life saving button" + ], + "success": true, + "log": "", + "time": 1087 + }, + { + "description": "I see Alice at the end of the list of named lemmings", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "I see Alice at the end of the list of named lemmings" + ], + "success": true, + "log": "", + "time": 1179 + }, + { + "description": "Verified lemming: Alice", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity", + "Scenario: The saved lemming has a name", + "Verified lemming: Alice" + ], + "success": true, + "log": "", + "time": 1195 + }, + { + "description": "Scenario: The saved lemming has a name", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity" + ], + "success": true, + "log": [], + "time": 1213 + }, + { + "description": "(WIP) Scenario: Lemmings don't really throw themselves off cliffs", + "suite": [ + "/base/webapp/test/GherkinTestRunner.html", + "Feature: Clicking Buttons Is a Life Saving Activity" + ], + "success": true, + "log": [], + "time": 1 + } +] diff --git a/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html new file mode 100644 index 00000000..266a0e66 --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html @@ -0,0 +1,23 @@ + + + + + Using Gherkin with OPA5 + + + + + + + +
+
+ + + + diff --git a/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.js b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.js new file mode 100644 index 00000000..ae04cf07 --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.js @@ -0,0 +1,21 @@ +/* global QUnit */ +window.QUnit = { + config: { + autostart: false + } +}; + +sap.ui.require([ + "sap/ui/test/gherkin/opa5TestHarness", + // Code coverage will be calculated for all modules loaded after the harness + "GherkinWithOPA5/Steps" +], function(opa5TestHarness, Steps) { + "use strict"; + + opa5TestHarness.test({ + featurePath: "GherkinWithOPA5.Requirements1", + steps: Steps + }); + + QUnit.start(); +}); diff --git a/test/integration/application-log-assertion/webapp/test/Requirements1.feature b/test/integration/application-log-assertion/webapp/test/Requirements1.feature new file mode 100644 index 00000000..71211cee --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/Requirements1.feature @@ -0,0 +1,23 @@ +Feature: Clicking Buttons Is a Life Saving Activity + Clicking buttons saves lemmings' lives. For the mere cost of a cheap home PC you + can save thousands of lemmings daily by clicking buttons all day long. + + Background: + Given I have started the app + And I can see the life saving button + + Scenario: Click a button, save a life! + Given I check how many lemmings have been saved already + When I click on the life saving button + Then I save a lemming's life + + Scenario: The saved lemming has a name + When I click on the life saving button + Then I see Alice at the end of the list of named lemmings + + @wip + Scenario: Lemmings don't really throw themselves off cliffs + Given there was a documentary of lemmings throwing themselves off a cliff + Given this film greatly affected people's perception of lemmings + Given this part of the film was faked + Then we expect the myth of suicide lemmings to persist despite its falsity diff --git a/test/integration/application-log-assertion/webapp/test/Steps.js b/test/integration/application-log-assertion/webapp/test/Steps.js new file mode 100644 index 00000000..2f941c01 --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/Steps.js @@ -0,0 +1,101 @@ +sap.ui.define([ + "sap/base/Log", + "sap/ui/test/gherkin/StepDefinitions", + "sap/ui/test/Opa5", + "sap/ui/test/actions/Press" +], function(Log, StepDefinitions, Opa5, Press) { + "use strict"; + + const oOpa5 = new Opa5(); + + /** + * @param {Function} fnCallback - executed once the number of lemmings saved is determined. + * Receives one parameter: "iNumberOfLemmingsSaved" + */ + function getNumberOfLemmingsSaved(fnCallback) { + oOpa5.waitFor({ + id: "num-lemmings-saved", + success: function(oLabel) { + const sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; + const iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); + fnCallback(iNumberOfLemmingsSaved); + } + }); + } + + const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { + init: function() { + this.register(/^I have started the app$/i, function() { + oOpa5.iStartMyAppInAFrame(sap.ui.require.toUrl("GherkinWithOPA5/Website.html")); + }); + + this.register(/^I can see the life saving button$/i, function() { + oOpa5.waitFor({ + id: "life-saving-button", + success: function(oButton) { + Opa5.assert.strictEqual(oButton.getText(), "Save a Lemming", + "Verified that we can see the life saving button"); + } + }); + }); + + this.register(/^I check how many lemmings have been saved already$/i, function() { + getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { + this.iNumLemmings = iNumberOfLemmingsSaved; + /* eslint-disable */ + }.bind(this)); + /* eslint-enable */ + }); + + this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, function(sNumTimes) { + const iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; + for (let i = 0; i < iNumTimes; ++i) { + oOpa5.waitFor({ + id: "life-saving-button", + actions: new Press() + }); + } + }); + + this.register(/^I save a lemming's life$/i, function() { + getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { + const iExpectedSavedLemmings = this.iNumLemmings + 1; + Opa5.assert.strictEqual(iNumberOfLemmingsSaved, iExpectedSavedLemmings, + "Verified correct number of lemmings saved"); + /* eslint-disable */ + }.bind(this)); + /* eslint-enable */ + }); + + this.register(/^I can see the following named lemmings:$/i, function(aDataTable) { + aDataTable.forEach(function(sLemmingName, iLemmingId) { + oOpa5.waitFor({ + id: "lemming-name-" + (iLemmingId + 1), + success: function(oLabel) { + Opa5.assert.strictEqual(oLabel.getText(), sLemmingName, + "Verified lemming: " + sLemmingName); + } + }); + }); + }); + + this.register(/^I see (\w+) at the end of the list of named lemmings$/i, function(sName) { + oOpa5.waitFor({ + id: "layout", + success: function(oLayout) { + const aContent = oLayout.getContent(); + const oLastContentItem = aContent[aContent.length - 1]; + Opa5.assert.strictEqual(oLastContentItem.getText(), sName, + "Verified lemming: " + sName); + } + }); + }); + }, + + closeApplication: function() { + Log.info("Closing application"); + } + }); + + return Steps; +}); diff --git a/test/integration/application-log-assertion/webapp/test/Website.html b/test/integration/application-log-assertion/webapp/test/Website.html new file mode 100644 index 00000000..536010ce --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/Website.html @@ -0,0 +1,15 @@ + + + Using Gherkin with OPA5 Website + + + + +
+ + diff --git a/test/integration/application-log-assertion/webapp/test/WebsiteCode.js b/test/integration/application-log-assertion/webapp/test/WebsiteCode.js new file mode 100644 index 00000000..ba22b42e --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/WebsiteCode.js @@ -0,0 +1,43 @@ +sap.ui.getCore().attachInit(function() { + "use strict"; + + const sText = "Number of lemmings saved: "; + let iNumSavedLemmings = 0; + + const oTitle = new sap.m.Label({ + id: "lemming-website-title", + text: "Lemming Life Saving Machine" + }); + + const oLabel = new sap.m.Label({ + id: "num-lemmings-saved", + text: sText + iNumSavedLemmings + }); + + const aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", + "Georgia", "Holly", "Idris", "Julien", "Kevin", "Lucia", "Michael", "Nancy", + "Oscar", "Peter", "Qubert", "Rascal", "Susan", "Terry", "Ursula", "Vicky", + "Walter", "Xavier", "Yolanda", "Zelda"]; + + const oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); + + const oButton = new sap.m.Button({ + id: "life-saving-button", + text: "Save a Lemming", + press: function() { + iNumSavedLemmings += 1; + oLabel.setText(sText + iNumSavedLemmings); + + const oNewLabel = new sap.m.Label({ + id: "lemming-name-" + iNumSavedLemmings, + text: aLemmingNames[(iNumSavedLemmings - 1) % aLemmingNames.length] + }); + oLayout.addContent(oNewLabel); + } + }); + + oLayout.addContent(oTitle); + oLayout.addContent(oButton); + oLayout.addContent(oLabel); + oLayout.placeAt("uiArea"); +}); diff --git a/test/integration/application-log-assertion/webapp/test/manifest.json b/test/integration/application-log-assertion/webapp/test/manifest.json new file mode 100644 index 00000000..85cf4bb2 --- /dev/null +++ b/test/integration/application-log-assertion/webapp/test/manifest.json @@ -0,0 +1,26 @@ +{ + "sap.app": { + "id": "sap.ui.core.sample.gherkin.GherkinWithOPA5", + "applicationVersion": { + "version": "1.0.0" + } + }, + "sap.ui5": { + "config": { + "sample": { + "iframe": "GherkinTestRunner.html", + "stretch": true, + "files": [ + "GherkinTestRunner.html", + "GherkinTestRunner.js", + "Requirements1.feature", + "Requirements2.feature", + "Steps.js", + "Website.html", + "WebsiteCode.js", + "manifest.json" + ] + } + } + } +} \ No newline at end of file From 9d37b93b5611a8a8468445f7a6e7cc29998e12d6 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 2 Jun 2020 18:39:39 +0800 Subject: [PATCH 11/23] fix bug` --- lib/client/browser.js | 8 +- lib/framework.js | 2 +- .../karma.conf.js | 9 +- .../application-log-assertion/karma.conf.js | 1 + .../reports/test_report.json | 188 ------------------ 5 files changed, 10 insertions(+), 198 deletions(-) delete mode 100644 test/integration/application-log-assertion/reports/test_report.json diff --git a/lib/client/browser.js b/lib/client/browser.js index 32d2601e..d8e07556 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -238,8 +238,8 @@ require("./discovery.js"); testResult.errors.push(msg); } if (config.logAssertions) { - const testSuite = [details.module, details.name, details.message]; - const testSuiteWithHTMLFilePath = testSuite.unshift(qunitHtmlFile) && testSuite; + const testSuiteWithHTMLFilePath = [qunitHtmlFile, details.module, details.name, details.message]; + const testSuite = testSuiteWithHTMLFilePath.slice(1); const result = { description: details.message, suite: details.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], @@ -252,8 +252,8 @@ require("./discovery.js"); }); QUnit.testDone(function(test) { - const testSuite = [test.module]; - const testSuiteWithHTMLFilePath = testSuite.unshift(qunitHtmlFile) && testSuite; + const testSuiteWithHTMLFilePath = [qunitHtmlFile, test]; + const testSuite = testSuiteWithHTMLFilePath.slice(1); const result = { description: test.name, suite: test.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], diff --git a/lib/framework.js b/lib/framework.js index 189ca71c..5cc2af0f 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -117,7 +117,7 @@ class Framework { this.config.client.ui5 = {}; this.config.client.ui5.useIframe = true; // for now only allow using iframes in HTML mode this.config.client.ui5.logAssertions = config.ui5 && config.ui5.logAssertions || false; - this.config.client.ui5.logHTMLFilePath = config.ui5 && config.ui5.logHTMLFilePath || true; + this.config.client.ui5.logHTMLFilePath = config.ui5 && config.ui5.logHTMLFilePath || config.ui5.logHTMLFilePath === undefined && true; this.config.ui5 = config.ui5 || {}; this.config.proxies = config.proxies || {}; this.config.middleware = config.middleware || []; diff --git a/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js index 9b03a719..7f78b4dc 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js +++ b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js @@ -27,9 +27,8 @@ module.exports = function(config) { preprocessors: { "{webapp,webapp/!(test)}/*.js": ["coverage"] }, - cucumberReporter: { - out: "application-log-assertion-with-cucumber-report/reports/test_report.json", - prefix: "" + testReporter: { + out: "application-log-assertion-with-cucumber-report/reports/test_report.json" }, coverageReporter: { @@ -60,6 +59,6 @@ module.exports = function(config) { module.exports.assertions = function({expect, log}) { const features = require("./reports/test_report.json"); - const featureName = features[0].suite[0]; - expect(featureName).toBe("Feature: Clicking Buttons Is a Life Saving Activity"); + expect(features).toHaveLength(16); + expect(features[0].suite[0]).toBe("Feature: Clicking Buttons Is a Life Saving Activity"); }; diff --git a/test/integration/application-log-assertion/karma.conf.js b/test/integration/application-log-assertion/karma.conf.js index ba2a33ef..73824774 100644 --- a/test/integration/application-log-assertion/karma.conf.js +++ b/test/integration/application-log-assertion/karma.conf.js @@ -1,5 +1,6 @@ const customCucumberReporter = require("./karma-reporter/index"); const customKarmaUI5 = require("../../../lib/index"); + module.exports = function(config) { "use strict"; diff --git a/test/integration/application-log-assertion/reports/test_report.json b/test/integration/application-log-assertion/reports/test_report.json deleted file mode 100644 index 0bf8b5cc..00000000 --- a/test/integration/application-log-assertion/reports/test_report.json +++ /dev/null @@ -1,188 +0,0 @@ -[ - { - "description": "I have started the app", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "I have started the app" - ], - "success": true, - "log": "", - "time": 382 - }, - { - "description": "I can see the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "I can see the life saving button" - ], - "success": true, - "log": "", - "time": 2749 - }, - { - "description": "Verified that we can see the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "Verified that we can see the life saving button" - ], - "success": true, - "log": "", - "time": 2854 - }, - { - "description": "I check how many lemmings have been saved already", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "I check how many lemmings have been saved already" - ], - "success": true, - "log": "", - "time": 2878 - }, - { - "description": "I click on the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "I click on the life saving button" - ], - "success": true, - "log": "", - "time": 2899 - }, - { - "description": "I save a lemming's life", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "I save a lemming's life" - ], - "success": true, - "log": "", - "time": 3063 - }, - { - "description": "Verified correct number of lemmings saved", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: Click a button, save a life!", - "Verified correct number of lemmings saved" - ], - "success": true, - "log": "", - "time": 3112 - }, - { - "description": "Scenario: Click a button, save a life!", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity" - ], - "success": true, - "log": [], - "time": 3133 - }, - { - "description": "I have started the app", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "I have started the app" - ], - "success": true, - "log": "", - "time": 122 - }, - { - "description": "I can see the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "I can see the life saving button" - ], - "success": true, - "log": "", - "time": 1040 - }, - { - "description": "Verified that we can see the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "Verified that we can see the life saving button" - ], - "success": true, - "log": "", - "time": 1071 - }, - { - "description": "I click on the life saving button", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "I click on the life saving button" - ], - "success": true, - "log": "", - "time": 1087 - }, - { - "description": "I see Alice at the end of the list of named lemmings", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "I see Alice at the end of the list of named lemmings" - ], - "success": true, - "log": "", - "time": 1179 - }, - { - "description": "Verified lemming: Alice", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity", - "Scenario: The saved lemming has a name", - "Verified lemming: Alice" - ], - "success": true, - "log": "", - "time": 1195 - }, - { - "description": "Scenario: The saved lemming has a name", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity" - ], - "success": true, - "log": [], - "time": 1213 - }, - { - "description": "(WIP) Scenario: Lemmings don't really throw themselves off cliffs", - "suite": [ - "/base/webapp/test/GherkinTestRunner.html", - "Feature: Clicking Buttons Is a Life Saving Activity" - ], - "success": true, - "log": [], - "time": 1 - } -] From 58b2d1cc536cd3cb4c959cc13305a89f8e380dca Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 2 Jun 2020 18:41:25 +0800 Subject: [PATCH 12/23] fix gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f992a59a..72548411 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,4 @@ deploy_key # Custom directories dist/ -**/reports/cucumber_report.json \ No newline at end of file +**/reports/test_report.json \ No newline at end of file From 7bbaa7a71c5be721e808f49881aa5ca5ab2772fd Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Wed, 3 Jun 2020 17:10:16 +0800 Subject: [PATCH 13/23] bug fix --- lib/framework.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/framework.js b/lib/framework.js index 5cc2af0f..99311ff0 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -117,7 +117,7 @@ class Framework { this.config.client.ui5 = {}; this.config.client.ui5.useIframe = true; // for now only allow using iframes in HTML mode this.config.client.ui5.logAssertions = config.ui5 && config.ui5.logAssertions || false; - this.config.client.ui5.logHTMLFilePath = config.ui5 && config.ui5.logHTMLFilePath || config.ui5.logHTMLFilePath === undefined && true; + this.config.client.ui5.logHTMLFilePath = ! config.ui5 || config.ui5.logHTMLFilePath || config.ui5.logHTMLFilePath === undefined && true; this.config.ui5 = config.ui5 || {}; this.config.proxies = config.proxies || {}; this.config.middleware = config.middleware || []; From dadbdec2f5e17c7b78b7367fb8e414b561953885 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Wed, 3 Jun 2020 17:17:55 +0800 Subject: [PATCH 14/23] change ui5 resource to relative path --- .../webapp/test/GherkinTestRunner.html | 2 +- .../webapp/test/Website.html | 2 +- .../webapp/test/GherkinTestRunner.html | 2 +- .../application-log-assertion/webapp/test/Website.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html index 266a0e66..93674544 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html +++ b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/GherkinTestRunner.html @@ -5,7 +5,7 @@ Using Gherkin with OPA5 diff --git a/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html index 266a0e66..93674544 100644 --- a/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html +++ b/test/integration/application-log-assertion/webapp/test/GherkinTestRunner.html @@ -5,7 +5,7 @@ Using Gherkin with OPA5 From cc6117bd942fedecff467d1135491c6319aa93a3 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 9 Jun 2020 18:10:03 +0800 Subject: [PATCH 15/23] simplify mock OPA tests --- .../webapp/test/Steps.js | 69 +++---------------- .../webapp/test/Website.html | 1 - .../webapp/test/WebsiteCode.js | 43 ------------ .../webapp/test/Steps.js | 69 +++---------------- .../webapp/test/Website.html | 1 - .../webapp/test/WebsiteCode.js | 43 ------------ 6 files changed, 18 insertions(+), 208 deletions(-) delete mode 100644 test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js delete mode 100644 test/integration/application-log-assertion/webapp/test/WebsiteCode.js diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js index 2f941c01..5fb76d01 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js +++ b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js @@ -1,28 +1,12 @@ sap.ui.define([ "sap/base/Log", "sap/ui/test/gherkin/StepDefinitions", - "sap/ui/test/Opa5", - "sap/ui/test/actions/Press" -], function(Log, StepDefinitions, Opa5, Press) { + "sap/ui/test/Opa5" +], function(Log, StepDefinitions, Opa5) { "use strict"; const oOpa5 = new Opa5(); - /** - * @param {Function} fnCallback - executed once the number of lemmings saved is determined. - * Receives one parameter: "iNumberOfLemmingsSaved" - */ - function getNumberOfLemmingsSaved(fnCallback) { - oOpa5.waitFor({ - id: "num-lemmings-saved", - success: function(oLabel) { - const sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; - const iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); - fnCallback(iNumberOfLemmingsSaved); - } - }); - } - const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { init: function() { this.register(/^I have started the app$/i, function() { @@ -30,65 +14,30 @@ sap.ui.define([ }); this.register(/^I can see the life saving button$/i, function() { - oOpa5.waitFor({ - id: "life-saving-button", - success: function(oButton) { - Opa5.assert.strictEqual(oButton.getText(), "Save a Lemming", - "Verified that we can see the life saving button"); - } - }); + Opa5.assert.strictEqual("Save a Lemming", "Save a Lemming", + "Verified that we can see the life saving button"); }); this.register(/^I check how many lemmings have been saved already$/i, function() { - getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { - this.iNumLemmings = iNumberOfLemmingsSaved; - /* eslint-disable */ - }.bind(this)); - /* eslint-enable */ + Opa5.assert.strictEqual(true, true); }); this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, function(sNumTimes) { - const iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; - for (let i = 0; i < iNumTimes; ++i) { - oOpa5.waitFor({ - id: "life-saving-button", - actions: new Press() - }); - } + Opa5.assert.strictEqual(true, true); }); this.register(/^I save a lemming's life$/i, function() { - getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { - const iExpectedSavedLemmings = this.iNumLemmings + 1; - Opa5.assert.strictEqual(iNumberOfLemmingsSaved, iExpectedSavedLemmings, - "Verified correct number of lemmings saved"); - /* eslint-disable */ - }.bind(this)); - /* eslint-enable */ + Opa5.assert.strictEqual(1, 1, "Verified correct number of lemmings saved"); }); this.register(/^I can see the following named lemmings:$/i, function(aDataTable) { aDataTable.forEach(function(sLemmingName, iLemmingId) { - oOpa5.waitFor({ - id: "lemming-name-" + (iLemmingId + 1), - success: function(oLabel) { - Opa5.assert.strictEqual(oLabel.getText(), sLemmingName, - "Verified lemming: " + sLemmingName); - } - }); + Opa5.assert.strictEqual(sLemmingName, sLemmingName, "Verified lemming: " + sLemmingName); }); }); this.register(/^I see (\w+) at the end of the list of named lemmings$/i, function(sName) { - oOpa5.waitFor({ - id: "layout", - success: function(oLayout) { - const aContent = oLayout.getContent(); - const oLastContentItem = aContent[aContent.length - 1]; - Opa5.assert.strictEqual(oLastContentItem.getText(), sName, - "Verified lemming: " + sName); - } - }); + Opa5.assert.strictEqual(sName, sName, "Verified lemming: " + sName); }); }, diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html index c6d9c42f..a23ed288 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html +++ b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html @@ -7,7 +7,6 @@ data-sap-ui-async="true" data-sap-ui-libs="sap.m,sap.ui.layout" > -
diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js deleted file mode 100644 index ba22b42e..00000000 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/WebsiteCode.js +++ /dev/null @@ -1,43 +0,0 @@ -sap.ui.getCore().attachInit(function() { - "use strict"; - - const sText = "Number of lemmings saved: "; - let iNumSavedLemmings = 0; - - const oTitle = new sap.m.Label({ - id: "lemming-website-title", - text: "Lemming Life Saving Machine" - }); - - const oLabel = new sap.m.Label({ - id: "num-lemmings-saved", - text: sText + iNumSavedLemmings - }); - - const aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", - "Georgia", "Holly", "Idris", "Julien", "Kevin", "Lucia", "Michael", "Nancy", - "Oscar", "Peter", "Qubert", "Rascal", "Susan", "Terry", "Ursula", "Vicky", - "Walter", "Xavier", "Yolanda", "Zelda"]; - - const oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); - - const oButton = new sap.m.Button({ - id: "life-saving-button", - text: "Save a Lemming", - press: function() { - iNumSavedLemmings += 1; - oLabel.setText(sText + iNumSavedLemmings); - - const oNewLabel = new sap.m.Label({ - id: "lemming-name-" + iNumSavedLemmings, - text: aLemmingNames[(iNumSavedLemmings - 1) % aLemmingNames.length] - }); - oLayout.addContent(oNewLabel); - } - }); - - oLayout.addContent(oTitle); - oLayout.addContent(oButton); - oLayout.addContent(oLabel); - oLayout.placeAt("uiArea"); -}); diff --git a/test/integration/application-log-assertion/webapp/test/Steps.js b/test/integration/application-log-assertion/webapp/test/Steps.js index 2f941c01..5fb76d01 100644 --- a/test/integration/application-log-assertion/webapp/test/Steps.js +++ b/test/integration/application-log-assertion/webapp/test/Steps.js @@ -1,28 +1,12 @@ sap.ui.define([ "sap/base/Log", "sap/ui/test/gherkin/StepDefinitions", - "sap/ui/test/Opa5", - "sap/ui/test/actions/Press" -], function(Log, StepDefinitions, Opa5, Press) { + "sap/ui/test/Opa5" +], function(Log, StepDefinitions, Opa5) { "use strict"; const oOpa5 = new Opa5(); - /** - * @param {Function} fnCallback - executed once the number of lemmings saved is determined. - * Receives one parameter: "iNumberOfLemmingsSaved" - */ - function getNumberOfLemmingsSaved(fnCallback) { - oOpa5.waitFor({ - id: "num-lemmings-saved", - success: function(oLabel) { - const sNumberOfLemmingsSaved = oLabel.getText().match(/Number of lemmings saved: (\d+)/)[1]; - const iNumberOfLemmingsSaved = parseInt(sNumberOfLemmingsSaved); - fnCallback(iNumberOfLemmingsSaved); - } - }); - } - const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { init: function() { this.register(/^I have started the app$/i, function() { @@ -30,65 +14,30 @@ sap.ui.define([ }); this.register(/^I can see the life saving button$/i, function() { - oOpa5.waitFor({ - id: "life-saving-button", - success: function(oButton) { - Opa5.assert.strictEqual(oButton.getText(), "Save a Lemming", - "Verified that we can see the life saving button"); - } - }); + Opa5.assert.strictEqual("Save a Lemming", "Save a Lemming", + "Verified that we can see the life saving button"); }); this.register(/^I check how many lemmings have been saved already$/i, function() { - getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { - this.iNumLemmings = iNumberOfLemmingsSaved; - /* eslint-disable */ - }.bind(this)); - /* eslint-enable */ + Opa5.assert.strictEqual(true, true); }); this.register(/^I click on the life saving button\s*(\d*)?(?:\s*times)?$/i, function(sNumTimes) { - const iNumTimes = (sNumTimes) ? parseInt(sNumTimes) : 1; - for (let i = 0; i < iNumTimes; ++i) { - oOpa5.waitFor({ - id: "life-saving-button", - actions: new Press() - }); - } + Opa5.assert.strictEqual(true, true); }); this.register(/^I save a lemming's life$/i, function() { - getNumberOfLemmingsSaved(function(iNumberOfLemmingsSaved) { - const iExpectedSavedLemmings = this.iNumLemmings + 1; - Opa5.assert.strictEqual(iNumberOfLemmingsSaved, iExpectedSavedLemmings, - "Verified correct number of lemmings saved"); - /* eslint-disable */ - }.bind(this)); - /* eslint-enable */ + Opa5.assert.strictEqual(1, 1, "Verified correct number of lemmings saved"); }); this.register(/^I can see the following named lemmings:$/i, function(aDataTable) { aDataTable.forEach(function(sLemmingName, iLemmingId) { - oOpa5.waitFor({ - id: "lemming-name-" + (iLemmingId + 1), - success: function(oLabel) { - Opa5.assert.strictEqual(oLabel.getText(), sLemmingName, - "Verified lemming: " + sLemmingName); - } - }); + Opa5.assert.strictEqual(sLemmingName, sLemmingName, "Verified lemming: " + sLemmingName); }); }); this.register(/^I see (\w+) at the end of the list of named lemmings$/i, function(sName) { - oOpa5.waitFor({ - id: "layout", - success: function(oLayout) { - const aContent = oLayout.getContent(); - const oLastContentItem = aContent[aContent.length - 1]; - Opa5.assert.strictEqual(oLastContentItem.getText(), sName, - "Verified lemming: " + sName); - } - }); + Opa5.assert.strictEqual(sName, sName, "Verified lemming: " + sName); }); }, diff --git a/test/integration/application-log-assertion/webapp/test/Website.html b/test/integration/application-log-assertion/webapp/test/Website.html index c6d9c42f..a23ed288 100644 --- a/test/integration/application-log-assertion/webapp/test/Website.html +++ b/test/integration/application-log-assertion/webapp/test/Website.html @@ -7,7 +7,6 @@ data-sap-ui-async="true" data-sap-ui-libs="sap.m,sap.ui.layout" > -
diff --git a/test/integration/application-log-assertion/webapp/test/WebsiteCode.js b/test/integration/application-log-assertion/webapp/test/WebsiteCode.js deleted file mode 100644 index ba22b42e..00000000 --- a/test/integration/application-log-assertion/webapp/test/WebsiteCode.js +++ /dev/null @@ -1,43 +0,0 @@ -sap.ui.getCore().attachInit(function() { - "use strict"; - - const sText = "Number of lemmings saved: "; - let iNumSavedLemmings = 0; - - const oTitle = new sap.m.Label({ - id: "lemming-website-title", - text: "Lemming Life Saving Machine" - }); - - const oLabel = new sap.m.Label({ - id: "num-lemmings-saved", - text: sText + iNumSavedLemmings - }); - - const aLemmingNames = ["Alice", "Bob", "Charlie", "David", "Elektra", "Felicia", - "Georgia", "Holly", "Idris", "Julien", "Kevin", "Lucia", "Michael", "Nancy", - "Oscar", "Peter", "Qubert", "Rascal", "Susan", "Terry", "Ursula", "Vicky", - "Walter", "Xavier", "Yolanda", "Zelda"]; - - const oLayout = new sap.ui.layout.VerticalLayout({id: "layout"}); - - const oButton = new sap.m.Button({ - id: "life-saving-button", - text: "Save a Lemming", - press: function() { - iNumSavedLemmings += 1; - oLabel.setText(sText + iNumSavedLemmings); - - const oNewLabel = new sap.m.Label({ - id: "lemming-name-" + iNumSavedLemmings, - text: aLemmingNames[(iNumSavedLemmings - 1) % aLemmingNames.length] - }); - oLayout.addContent(oNewLabel); - } - }); - - oLayout.addContent(oTitle); - oLayout.addContent(oButton); - oLayout.addContent(oLabel); - oLayout.placeAt("uiArea"); -}); From d9973f5e11a46d4472227e77a8135aaf34df86c3 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 9 Jun 2020 18:32:25 +0800 Subject: [PATCH 16/23] simplify mock OPA tests --- .../webapp/test/Steps.js | 3 +-- .../webapp/test/Website.html | 14 -------------- .../application-log-assertion/webapp/test/Steps.js | 4 +--- .../webapp/test/Website.html | 14 -------------- 4 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html delete mode 100644 test/integration/application-log-assertion/webapp/test/Website.html diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js index 5fb76d01..218eaf24 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js +++ b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Steps.js @@ -5,12 +5,11 @@ sap.ui.define([ ], function(Log, StepDefinitions, Opa5) { "use strict"; - const oOpa5 = new Opa5(); const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { init: function() { this.register(/^I have started the app$/i, function() { - oOpa5.iStartMyAppInAFrame(sap.ui.require.toUrl("GherkinWithOPA5/Website.html")); + Opa5.assert.strictEqual(true, true); }); this.register(/^I can see the life saving button$/i, function() { diff --git a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html b/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html deleted file mode 100644 index a23ed288..00000000 --- a/test/integration/application-log-assertion-with-cucumber-report/webapp/test/Website.html +++ /dev/null @@ -1,14 +0,0 @@ - - - Using Gherkin with OPA5 Website - - - -
- - diff --git a/test/integration/application-log-assertion/webapp/test/Steps.js b/test/integration/application-log-assertion/webapp/test/Steps.js index 5fb76d01..2617eb3e 100644 --- a/test/integration/application-log-assertion/webapp/test/Steps.js +++ b/test/integration/application-log-assertion/webapp/test/Steps.js @@ -5,12 +5,10 @@ sap.ui.define([ ], function(Log, StepDefinitions, Opa5) { "use strict"; - const oOpa5 = new Opa5(); - const Steps = StepDefinitions.extend("GherkinWithOPA5.Steps", { init: function() { this.register(/^I have started the app$/i, function() { - oOpa5.iStartMyAppInAFrame(sap.ui.require.toUrl("GherkinWithOPA5/Website.html")); + Opa5.assert.strictEqual(true, true); }); this.register(/^I can see the life saving button$/i, function() { diff --git a/test/integration/application-log-assertion/webapp/test/Website.html b/test/integration/application-log-assertion/webapp/test/Website.html deleted file mode 100644 index a23ed288..00000000 --- a/test/integration/application-log-assertion/webapp/test/Website.html +++ /dev/null @@ -1,14 +0,0 @@ - - - Using Gherkin with OPA5 Website - - - -
- - From 72ceeefb74358e2ab6bcf17cbe1d591c82d24540 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 9 Jun 2020 18:46:10 +0800 Subject: [PATCH 17/23] fix check --- .../karma.conf.js | 2 +- test/integration/application-log-assertion/karma.conf.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js index 7f78b4dc..b19c0b4d 100644 --- a/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js +++ b/test/integration/application-log-assertion-with-cucumber-report/karma.conf.js @@ -59,6 +59,6 @@ module.exports = function(config) { module.exports.assertions = function({expect, log}) { const features = require("./reports/test_report.json"); - expect(features).toHaveLength(16); + expect(features).toHaveLength(21); expect(features[0].suite[0]).toBe("Feature: Clicking Buttons Is a Life Saving Activity"); }; diff --git a/test/integration/application-log-assertion/karma.conf.js b/test/integration/application-log-assertion/karma.conf.js index 73824774..ec286318 100644 --- a/test/integration/application-log-assertion/karma.conf.js +++ b/test/integration/application-log-assertion/karma.conf.js @@ -58,5 +58,5 @@ module.exports = function(config) { module.exports.assertions = function({expect, log}) { const features = require("./reports/test_report.json"); - expect(features).toHaveLength(16); + expect(features).toHaveLength(21); }; From e9f0660efff9e6ac70a1aad04bb4526b50bdd2d7 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 9 Jun 2020 19:45:33 +0800 Subject: [PATCH 18/23] add the flags in readme --- README.md | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a6e4f6a8..73639b9d 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,21 @@ - [Installation](#installation) - [Configuration](#configuration) - [Execution](#execution) -- [Karma configuration requirements](#karma-configuration-requirements) +- [Karma Configuration Requirements](#karma-configuration-requirements) - [Options](#options) - [url](#url) - [type](#type) - [paths](#paths) - - [configPath](#configPath) + - [configPath](#configpath) - [mode](#mode) - [html](#html) - [script](#script) - [testpage](#testpage) - - [urlParameters](#urlParameters) + - [urlParameters](#urlparameters) - [config](#config) - [tests](#tests) + - [logAssertions](#logassertions) + - [logHTMLFilePath](#loghtmlfilepath) - [License](#license) @@ -323,6 +325,32 @@ ui5: { } ``` +### logAssertions +Type: `Boolean` +Default: `false` + +If set to `true`, the framework would report the result of the assertions. + +Example: +```js +ui5: { + logAssertions: true +} +``` + +### logHTMLFilePath +Type: `Boolean` +Default: `true` + +If set to `false`, the `log.suite[0]` of the test log would be the feature name. Otherwise it would be the path of the testsuite. + +Example: +```js +ui5: { + logHTMLFilePath: false +} +``` + ## License (c) Copyright 2019 SAP SE or an SAP affiliate company From d53933b6b93b028399403e8c7f798e901189cf8b Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 20 Oct 2020 16:41:35 +0800 Subject: [PATCH 19/23] fix eslint --- lib/client/browser.js | 13 +++++++++++-- lib/framework.js | 8 ++++++-- test/unit/framework.test.js | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/client/browser.js b/lib/client/browser.js index b9e8a659..7e488faf 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -286,11 +286,20 @@ require("./discovery.js"); testResult.errors.push(msg); } if (config.logAssertions) { - const testSuiteWithHTMLFilePath = [qunitHtmlFile, details.module, details.name, details.message]; + const testSuiteWithHTMLFilePath = [ + qunitHtmlFile, + details.module, + details.name, + details.message + ]; const testSuite = testSuiteWithHTMLFilePath.slice(1); const result = { description: details.message, - suite: details.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], + suite: details.module && + config.logHTMLFilePath ? + testSuiteWithHTMLFilePath : + testSuite || + [], success: details.result, log: msg, time: new Date().getTime() - timer diff --git a/lib/framework.js b/lib/framework.js index 8a8e5873..6544e426 100644 --- a/lib/framework.js +++ b/lib/framework.js @@ -119,7 +119,9 @@ class Framework { this.config.client.ui5 = {}; this.config.client.ui5.useIframe = true; // for now only allow using iframes in HTML mode this.config.client.ui5.logAssertions = config.ui5 && config.ui5.logAssertions || false; - this.config.client.ui5.logHTMLFilePath = ! config.ui5 || config.ui5.logHTMLFilePath || config.ui5.logHTMLFilePath === undefined && true; + this.config.client.ui5.logHTMLFilePath = ! config.ui5 || + config.ui5.logHTMLFilePath || + config.ui5.logHTMLFilePath === undefined && true; this.config.ui5 = config.ui5 || {}; this.config.middleware = config.middleware || []; this.config.files = config.files || []; @@ -141,7 +143,9 @@ class Framework { } const incompatibleFrameworks = ["qunit", "sinon"]; - const hasIncompatibleFrameworks = (frameworks) => frameworks.some((fwk) => incompatibleFrameworks.includes(fwk)); + const hasIncompatibleFrameworks = (frameworks) => frameworks.some((fwk) => + incompatibleFrameworks.includes(fwk) + ); if (this.config.ui5.mode === "html" && hasIncompatibleFrameworks(this.config.frameworks || [])) { this.logger.log("error", ErrorMessage.incompatibleFrameworks(this.config.frameworks) ); throw new Error(ErrorMessage.failure()); diff --git a/test/unit/framework.test.js b/test/unit/framework.test.js index 24bd4035..81650952 100644 --- a/test/unit/framework.test.js +++ b/test/unit/framework.test.js @@ -1035,7 +1035,8 @@ describe("Error logging", () => { const config = { frameworks: ["foo", "ui5"] }; - await expect(framework.init({config, logger})).rejects.toThrow(ErrorMessage.failure()); // some unrelated exception + await expect(framework.init({config, logger})).rejects. + toThrow(ErrorMessage.failure()); // some unrelated exception expect(framework.logger.message).not.toBe(ErrorMessage.incompatibleFrameworks(["foo", "ui5"])); }); From e4469d79b5a0cf85e8503388d98edee89fd03bc7 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Tue, 20 Oct 2020 16:46:04 +0800 Subject: [PATCH 20/23] add setTimeout --- test/integration/integration.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/integration.test.js b/test/integration/integration.test.js index f5e53e91..bf1c868d 100644 --- a/test/integration/integration.test.js +++ b/test/integration/integration.test.js @@ -9,7 +9,7 @@ const TEST_TIMEOUT = 5 * 60 * 1000; // 5 minutes let server; // Increase test timeout (default 5s) -jest.(TEST_TIMEOUT); +jest.setTimeout(TEST_TIMEOUT); const registerIntegrationTest = async (configPath) => { it(configPath, async () => { From ad18be1cdbe7bef788d484ee01fffac2e5cbef2e Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Fri, 23 Oct 2020 16:04:44 +0800 Subject: [PATCH 21/23] testDone should log test module and test name instead of test obj --- lib/client/browser.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/client/browser.js b/lib/client/browser.js index 7e488faf..43215f56 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -302,21 +302,23 @@ require("./discovery.js"); [], success: details.result, log: msg, - time: new Date().getTime() - timer + time: new Date().getTime() - timer, + testObj: details }; karma.result(result); } }); QUnit.testDone(function(test) { - const testSuiteWithHTMLFilePath = [qunitHtmlFile, test]; + const testSuiteWithHTMLFilePath = [qunitHtmlFile, test.module, test.name]; const testSuite = testSuiteWithHTMLFilePath.slice(1); const result = { description: test.name, suite: test.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], success: testResult.success, log: testResult.errors || [], - time: new Date().getTime() - timer + time: new Date().getTime() - timer, + testObj: test }; karma.result(result); From 63f44850b3c7c9039a8ebe575a68c25b6e076206 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Fri, 23 Oct 2020 16:08:23 +0800 Subject: [PATCH 22/23] remove test obj from code --- lib/client/browser.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/client/browser.js b/lib/client/browser.js index 43215f56..5b12c2df 100644 --- a/lib/client/browser.js +++ b/lib/client/browser.js @@ -302,8 +302,7 @@ require("./discovery.js"); [], success: details.result, log: msg, - time: new Date().getTime() - timer, - testObj: details + time: new Date().getTime() - timer }; karma.result(result); } @@ -317,8 +316,7 @@ require("./discovery.js"); suite: test.module && config.logHTMLFilePath ? testSuiteWithHTMLFilePath : testSuite || [], success: testResult.success, log: testResult.errors || [], - time: new Date().getTime() - timer, - testObj: test + time: new Date().getTime() - timer }; karma.result(result); From 775545ded8e5eb50fa5c4ff37cebef582a17a0c1 Mon Sep 17 00:00:00 2001 From: "2499128545@qq.com" <2499128545@qq.com> Date: Mon, 2 Nov 2020 15:27:03 +0800 Subject: [PATCH 23/23] fix ui5 tooling iframe path assertion fail on windows --- .../integration/application-ui5-tooling-iframe/karma.conf.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/integration/application-ui5-tooling-iframe/karma.conf.js b/test/integration/application-ui5-tooling-iframe/karma.conf.js index 8debd2dd..b0f0b9c7 100644 --- a/test/integration/application-ui5-tooling-iframe/karma.conf.js +++ b/test/integration/application-ui5-tooling-iframe/karma.conf.js @@ -40,7 +40,10 @@ module.exports = function(config) { module.exports.assertions = function({expect, log}) { const coverage = require("./coverage/json/coverage-final.json"); + const sWindowsExpect = "application-ui5-tooling-iframe\\webapp\\foo.js"; + const sLinuxExpect = "application-ui5-tooling-iframe/webapp/foo.js"; const files = Object.keys(coverage); expect(files).toHaveLength(1); - expect(files[0]).toEndWith("application-ui5-tooling-iframe/webapp/foo.js"); + const sActual = files[0] && files[0].replace(sWindowsExpect, sLinuxExpect); + expect(sActual).toEndWith(sLinuxExpect); };