Skip to content
This repository was archived by the owner on Apr 15, 2019. It is now read-only.

Change testing suite to follow lisk standards - Closes #448#437

Merged
willclarktech merged 6 commits into1.0.0from
426-change_testing_suite
Feb 26, 2018
Merged

Change testing suite to follow lisk standards - Closes #448#437
willclarktech merged 6 commits into1.0.0from
426-change_testing_suite

Conversation

@shuse2
Copy link
Copy Markdown
Contributor

@shuse2 shuse2 commented Feb 14, 2018

Closes #448

@shuse2 shuse2 self-assigned this Feb 14, 2018
@shuse2 shuse2 force-pushed the 426-change_testing_suite branch from d866859 to 2dd5643 Compare February 14, 2018 19:30
Comment thread test/setup.js Outdated

new Assertion(obj).to.be.an('array');
let result = false;
obj.forEach(val => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prefer using const and .some.

Comment thread test/setup.js Outdated
// See https://github.com/shouldjs/should.js/issues/41
Object.defineProperty(global, 'should', { value: should });

[sinonChai, chaiAsPromised].forEach(plugin => chai.use(plugin));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be neater to use just .forEach(chai.use)?

Comment thread test/setup.js Outdated
this.assert(
result,
'expected #{this} to match at least once',
'expected #{this} to not to match',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not to match

Comment thread test/setup.js Outdated
const expected = Buffer.from(actual, 'hex').toString('hex');
this.assert(
expected === actual,
'expected #{this} to be a hexString',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need camelcase in the user-facing message.

Comment thread test/steps/api/3_then.js Outdated
export function itShouldResolveToTheAPIResponse() {
const { returnValue, apiResponse } = this.test.ctx;
return returnValue.should.be.fulfilledWith(apiResponse);
return returnValue.should.be.eventually.eql(apiResponse);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.should.eventually.eql

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.

I think we need be verb in natural language?

Comment thread test/steps/config/3_then.js Outdated
export function itShouldResolveToTheConfig() {
const { returnValue, config } = this.test.ctx;
return returnValue.should.be.fulfilledWith(config);
return returnValue.should.be.eventually.eql(config);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As above.

Comment thread test/steps/general/3_then.js Outdated
return testFunction.should
.throw()
.and.has.property('message')
.which.include(message);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All these testFunction.should.throw()s seem redundant. It's awkward, but I think it would be better to store that in a variable and make further assertions against it.

Comment thread test/steps/general/3_then.js Outdated
return testFunction.should
.throw()
.and.has.property('message')
.which.include(message);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's extract the common functionality into a helper function, so these then steps can be cleaner at least. Can we even add a method to chai?

Comment thread test/steps/general/3_then.js Outdated
err.should.be.instanceOf(Error);
err.should.have.property('name').which.equal('FileSystemError');
return err.should.have.property('message').which.include(message);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar suggestion about adding a method to chai.

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.

great idea! it's much cleaner.
I will add customError check function

export function itShouldReturnNull() {
const { returnValue } = this.test.ctx;
return should(returnValue).be.null();
return should.equal(returnValue, null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is another downside to switching to chai.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But I guess it'll be solved when we switch to expect.

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.

yes, it will.
I almost tried to port except to global, too... lol

@willclarktech willclarktech mentioned this pull request Feb 22, 2018
10 tasks
@shuse2 shuse2 changed the title Change testing suite to follow lisk standards - Closes #426 Change testing suite to follow lisk standards - Closes #448,3450 Feb 22, 2018
@shuse2 shuse2 changed the title Change testing suite to follow lisk standards - Closes #448,3450 Change testing suite to follow lisk standards - Closes #448,#450 Feb 22, 2018
@shuse2 shuse2 force-pushed the 426-change_testing_suite branch from 55147d3 to c06eecb Compare February 26, 2018 15:56
@shuse2 shuse2 force-pushed the 426-change_testing_suite branch from c06eecb to 5182fed Compare February 26, 2018 15:58
Copy link
Copy Markdown
Contributor

@willclarktech willclarktech left a comment

Choose a reason for hiding this comment

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

  • README.md then step should be updated.
  • Prettier should be run on all files.

Comment thread test/steps/crypto/3_then.js Outdated
export function itShouldResolveToThePassphrase() {
const { returnValue, passphrase } = this.test.ctx;
return returnValue.should.be.fulfilledWith(passphrase);
return returnValue.should.eventually.eql(passphrase);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prefer .equal where possible.

Comment thread test/steps/general/3_then.js Outdated
const message = getFirstQuotedString(this.test.title);
return returnValue.should.be.rejectedWith(new FileSystemError(message));
return returnValue.should.be.rejected.then(err => {
return err.should.be.customError(new FileSystemError(message));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prefer direct return without function body.

Comment thread test/steps/general/3_then.js Outdated
const message = getFirstQuotedString(this.test.title);
return returnValue.should.be.rejectedWith(new ValidationError(message));
return returnValue.should.be.rejected.then(err => {
return err.should.be.customError(new ValidationError(message));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As above.

@willclarktech willclarktech changed the title Change testing suite to follow lisk standards - Closes #448,#450 Change testing suite to follow lisk standards - Closes #448 Feb 26, 2018
@willclarktech willclarktech merged commit ee93414 into 1.0.0 Feb 26, 2018
@willclarktech willclarktech deleted the 426-change_testing_suite branch February 26, 2018 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants