Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[FIX] HTML mode: QUnit.config.noglobals with coverage enabled #223

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,30 @@ require("./discovery.js");
QUnit.testStart(function(test) {
timer = new Date().getTime();
testResult = {success: true, errors: []};

// Prevent false-positives when the "noglobals" config is enabled.
// Code instrumented by istanbul introduces global variables
// (cov_* for each file and a global __coverage__ variable).
// Adding them to the already collected "pollution" list prevents issues
// when the original "after" hook compares the list with the current state.
const config = QUnit.config;
if (!config.noglobals) {
return;
}
const currentTest = config.current;
const originalAfter = currentTest.after;
currentTest.after = function(...args) {
for (const key in testWindow.contentWindow) {
if (
Object.prototype.hasOwnProperty.call(testWindow.contentWindow, key) &&
(key.indexOf("cov_") === 0 || key === "__coverage__") &&
config.pollution.indexOf(key) === -1
) {
config.pollution.push(key);
}
}
return originalAfter.apply(currentTest, args);
};
});

QUnit.log(function(details) {
Expand Down
25 changes: 19 additions & 6 deletions test/integration/application-proxy/webapp/test/test.qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@ 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();
QUnit.test("Karma", function(assert) {
assert.ok(parent.__karma__.files["/base/webapp/.dotfile"], "Karma files should contain dotfiles");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to the change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not. The test has been there before.

});

QUnit.test(
"Loading files during a test should not result into 'Introduced global variable(s)' issues " +
"when QUnit.config.noglobals is active",
function(assert) {
const done = assert.async();
sap.ui.require(["test/app/foo"], function() {
assert.ok(true, "test/app/foo has been loaded");
done();
}, function(err) {
assert.ok(false, "Failed to load test/app/foo: " + err);
});
}
);
QUnit.config.noglobals = true;

QUnit.start();
});