Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a7bf937
Update browser.js
EdStrickland Mar 24, 2020
2e56125
Update browser.js
EdStrickland Mar 25, 2020
b9605f3
Update browser.js
EdStrickland Apr 8, 2020
262a7d9
Merge pull request #1 from SAP/master
EdStrickland Apr 23, 2020
ccdef05
Merge pull request #2 from SAP/master
EdStrickland Apr 23, 2020
377d7ff
add integration tests(unfinished)
EdStrickland Apr 23, 2020
66ef536
Merge pull request #3 from EdStrickland/master
EdStrickland Apr 23, 2020
62ca5db
add integration tests and add config initialization
EdStrickland May 6, 2020
5400109
fix eslint
EdStrickland May 6, 2020
51c331b
Update test/integration/application-log-assersion/webapp/test/Gherkin…
EdStrickland May 28, 2020
dde019c
Update test/integration/application-log-assersion/webapp/test/Website…
EdStrickland May 28, 2020
d0d11d8
Update test/integration/application-log-assersion/karma.conf.js
EdStrickland May 28, 2020
98f551a
enhance config and integration tests
EdStrickland Jun 2, 2020
9d37b93
fix bug`
EdStrickland Jun 2, 2020
58b2d1c
fix gitignore
EdStrickland Jun 2, 2020
7bbaa7a
bug fix
EdStrickland Jun 3, 2020
dadbdec
change ui5 resource to relative path
EdStrickland Jun 3, 2020
cc6117b
simplify mock OPA tests
EdStrickland Jun 9, 2020
d9973f5
simplify mock OPA tests
EdStrickland Jun 9, 2020
72ceeef
fix check
EdStrickland Jun 9, 2020
e9f0660
add the flags in readme
EdStrickland Jun 9, 2020
afe9192
Merge branch 'master' into patch-1
EdStrickland Jul 24, 2020
051d588
Merge branch 'master' into patch-1
EdStrickland Oct 20, 2020
d53933b
fix eslint
EdStrickland Oct 20, 2020
e4469d7
add setTimeout
EdStrickland Oct 20, 2020
ad18be1
testDone should log test module and test name instead of test obj
EdStrickland Oct 23, 2020
63f4485
remove test obj from code
EdStrickland Oct 23, 2020
775545d
fix ui5 tooling iframe path assertion fail on windows
EdStrickland Nov 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
53 changes: 53 additions & 0 deletions test/integration/application-log-assersion/karma-reporter/index.js
Original file line number Diff line number Diff line change
@@ -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]
};
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
};
61 changes: 61 additions & 0 deletions test/integration/application-log-assersion/karma.conf.js
Original file line number Diff line number Diff line change
@@ -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);
};
3 changes: 3 additions & 0 deletions test/integration/application-log-assersion/webapp/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sap.ui.define(function() {
return "foo";
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sap.app": {
"id": "sap.karma.ui5.test"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Test</title>

<script id="sap-ui-bootstrap" src="../resources/sap-ui-core.js" data-sap-ui-resourceRoots='{ "test.app": "../" }'></script>
<link rel="stylesheet" href="../resources/sap/ui/thirdparty/qunit-2.css">
<script src="../resources/sap/ui/thirdparty/qunit-2.js"></script>
<script src="./test.qunit.js"></script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Testsuite</title>
<script src="../resources/sap/ui/qunit/qunit-redirect.js"></script>
<script src="testsuite.qunit.js" data-sap-ui-testsuite></script>
</head>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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;
};