Skip to content

[INTERNAL] improve test coverage #88

Merged
RandomByte merged 6 commits into
masterfrom
test-coverage-server
Dec 20, 2018
Merged

[INTERNAL] improve test coverage #88
RandomByte merged 6 commits into
masterfrom
test-coverage-server

Conversation

@svbender
Copy link
Copy Markdown
Contributor

Added more tests to improve test coverage.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 14, 2018

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+13.4%) to 88.438% when pulling 679cc87 on test-coverage-server into e0c5318 on master.

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 19, 2018

Coverage Status

Coverage increased (+15.6%) to 90.669% when pulling f861afd on test-coverage-server into e0c5318 on master.

Comment thread test/lib/server/ports.js Outdated
});
}).catch((error) => {
nodeServer.close();
t.is(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should use throws here.

If server does not throw in this test, no other asserts will explicitly make the test fail. It will still fail because no asserts are executed, but the moment someone adds another assertion, we can't be sure that the server actually threw.

Comment thread test/lib/server/ports.js Outdated
});
});
}).catch((error) => {
t.fail(error);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not necessary, ava tests fail automatically if the returned promise rejects

methods.forEach(function(method) {
res = {
status: function(status) {
t.is(status, 404, "Status should be 404");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather use t.deepEqual. We do not care whether this is the same object but whether it is of equal value

t.is is like ==
t.deepEqual is like ===
(also see Object.is

t.is(status, 404, "Status should be 404");
return {
end: function(message) {
t.is(message, "Cannot " + method + " somePath", "Finished with error message.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

t.deepEqual

Comment thread test/lib/server/ports.js
return server.serve(tree, {
port: 3335
}).then((serveResult) => {
serve = serveResult;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of storing this in a closure variable, store it at t.context to prevent side effects with other concurrently runnign tests.

See https://github.com/avajs/ava/tree/v0.25.0#test-context

Comment thread test/lib/server/sslUtil.js Outdated

mock("devcert-sanscache", function(name) {
t.is(name, "ui5-tooling", "Create certificate for ui5-tooling.");
return new Promise((resolve) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather use:

return Promise.resolve({
	key: sslKey,
	cert: sslCert
});

Comment thread test/lib/server/sslUtil.js Outdated
});

mock("devcert-sanscache", function(name) {
t.is(name, "ui5-tooling", "Create certificate for ui5-tooling.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather use t.deepEquals

Comment thread test/lib/server/sslUtil.js Outdated
const sslPathCert = path.join(sslPath, "someOtherServer1.crt");
const result = sslUtil.getSslCertificate(sslPathKey, sslPathCert);
return result.then((res) => {
t.is(res.key, sslKey, "Key should be returned");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

t.deepEqual

Comment thread test/lib/server/sslUtil.js Outdated
fileExists(sslPathCert)
]);
}).then((fileExistsResult) => {
t.is(fileExistsResult[0], true, "Key was created.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

t.deepEqual

Comment thread test/lib/server/sslUtil.js Outdated
const sslPathCert = path.join(sslPath, "someOtherServer2.crt");
const result = sslUtil.getSslCertificate(sslPathKey, sslPathCert);
return result.catch((error) => {
t.is(error, "Certificate installation aborted! Please install the SSL certificate manually.", "Certificate install aborted.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

t.deepEqual

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've updated it. Could you please check again.

Updated some test assertions to use t.throws.
Removed unnecessary promise rejection handling.
Added t.plan to most of the tests.
Copy link
Copy Markdown
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

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

Please squash all commits and use the [INTERNAL] prefix in the squash commit

@RandomByte RandomByte merged commit 96a74e9 into master Dec 20, 2018
@RandomByte RandomByte deleted the test-coverage-server branch December 20, 2018 15:05
d3xter666 pushed a commit to UI5/cli that referenced this pull request Sep 25, 2025
Added more tests to improve test coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants