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

Commit

Permalink
Merge pull request #437 from LiskHQ/426-change_testing_suite
Browse files Browse the repository at this point in the history
Change testing suite to follow lisk standards - Closes #448
  • Loading branch information
willclarktech authored Feb 26, 2018
2 parents fceb06c + 3c8a68f commit ee93414
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 94 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"babel-plugin-istanbul": "=4.1.5",
"babel-preset-env": "=1.6.1",
"babel-register": "=6.26.0",
"chai": "=4.1.2",
"chai-as-promised": "=7.1.1",
"coveralls": "=3.0.0",
"eslint": "=4.11.0",
"eslint-config-airbnb-base": "=12.1.0",
Expand All @@ -78,8 +80,7 @@
"mocha-bdd": "=0.1.2",
"nyc": "=11.3.0",
"prettier": "=1.9.2",
"should": "=13.1.3",
"should-sinon": "=0.0.6",
"sinon": "=4.1.2"
"sinon": "=4.1.2",
"sinon-chai": "=2.14.0"
}
}
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function itShouldResolveToAnObjectWithThePassphraseAndThePublicKeyAndTheA
publicKey,
address,
};
return returnValue.should.be.fulfilledWith(expectedObject);
return returnValue.should.eventually.eql(expectedObject);
}
```

Expand Down
40 changes: 26 additions & 14 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,41 @@
*/
import os from 'os';
import 'babel-polyfill';
import should from 'should';
import chai, { Assertion } from 'chai';
import 'chai/register-should';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
import sinon from 'sinon';
import 'should-sinon';
import mochaBDD from 'mocha-bdd';

process.env.NODE_ENV = 'test';
process.env.LISKY_CONFIG_DIR =
process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`;

should.use((_, Assertion) => {
// istanbul ignore next
Assertion.add('hexString', function hexString() {
this.params = {
operator: 'to be hex string',
};
Buffer.from(this.obj, 'hex')
.toString('hex')
.should.equal(this.obj);
});
/* eslint-disable no-underscore-dangle */
Assertion.addMethod('matchAny', function handleAssert(matcher) {
const obj = this._obj;

new Assertion(obj).to.be.an('array');
const result = obj.some(val => matcher(val));
this.assert(
result,
'expected #{this} to match at least once',
'expected #{this} not to match',
);
});

Assertion.addMethod('customError', function handleAssert(error) {
const obj = this._obj;
new Assertion(obj).to.be.instanceOf(Error);
new Assertion(obj.name).to.equal(error.name);
new Assertion(obj.message).to.equal(error.message);
});
/* eslint-enable no-underscore-dangle */

mochaBDD();
// See https://github.com/shouldjs/should.js/issues/41
Object.defineProperty(global, 'should', { value: should });

[sinonChai, chaiAsPromised].forEach(chai.use);

global.sinon = sinon;
global.sandbox = sinon.sandbox.create();
8 changes: 4 additions & 4 deletions test/steps/api/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getFirstBoolean } from '../utils';

export function itShouldNotSetTheLiskAPIInstanceTestnetSetting() {
const { liskAPIInstance } = this.test.ctx;
return liskAPIInstance.setTestnet.should.not.be.called();
return liskAPIInstance.setTestnet.should.not.be.called;
}

export function itShouldSetTheLiskAPIInstanceTestnetSettingTo() {
Expand All @@ -42,7 +42,7 @@ export function itShouldUseTheLiskAPIInstanceToSendARequestToTheEndpointUsingThe

export function itShouldNotBroadcastTheSignature() {
const { liskAPIInstance } = this.test.ctx;
return liskAPIInstance.broadcastSignatures.should.not.be.called();
return liskAPIInstance.broadcastSignatures.should.not.be.called;
}

export function itShouldBroadcastTheSignature() {
Expand All @@ -54,7 +54,7 @@ export function itShouldBroadcastTheSignature() {

export function itShouldNotBroadcastTheTransaction() {
const { liskAPIInstance } = this.test.ctx;
return liskAPIInstance.broadcastTransaction.should.not.be.called();
return liskAPIInstance.broadcastTransaction.should.not.be.called;
}

export function itShouldBroadcastTheTransaction() {
Expand All @@ -66,7 +66,7 @@ export function itShouldBroadcastTheTransaction() {

export function itShouldResolveToTheAPIResponse() {
const { returnValue, apiResponse } = this.test.ctx;
return returnValue.should.be.fulfilledWith(apiResponse);
return returnValue.should.eventually.eql(apiResponse);
}

export function theLiskAPIInstanceShouldBeALiskJSAPIInstance() {
Expand Down
2 changes: 1 addition & 1 deletion test/steps/childProcesses/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function itShouldExecuteAScriptExecutingThirdInASeparateChildProcess() {
}

export function itShouldNotExecuteAThirdScriptInASeparateChildProcess() {
return childProcess.exec.should.not.be.calledThrice();
return childProcess.exec.should.not.be.calledThrice;
}

export function theLiskyInstanceShouldLogTheFirstChildProcessOutputFirst() {
Expand Down
2 changes: 1 addition & 1 deletion test/steps/config/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function itShouldUpdateTheConfigVariableToBoolean() {

export function itShouldResolveToTheConfig() {
const { returnValue, config } = this.test.ctx;
return returnValue.should.be.fulfilledWith(config);
return returnValue.should.eventually.eql(config);
}

export function theDefaultConfigShouldBeExported() {
Expand Down
34 changes: 17 additions & 17 deletions test/steps/crypto/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export function itShouldSignTheMessageWithThePassphrase() {

export function itShouldResolveToTheResultOfSigningTheMessage() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
return returnValue.should.eventually.equal(cryptoResult);
}

export function itShouldResolveToTheResultOfDecryptingThePassphrase() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
return returnValue.should.eventually.equal(cryptoResult);
}

export function itShouldDecryptThePassphraseUsingTheIVAndThePassword() {
Expand All @@ -46,7 +46,7 @@ export function itShouldDecryptThePassphraseUsingTheIVAndThePassword() {

export function itShouldResolveToTheResultOfEncryptingThePassphraseCombinedWithThePublicKey() {
const { returnValue, cryptoResult, publicKey } = this.test.ctx;
return returnValue.should.be.fulfilledWith(
return returnValue.should.eventually.eql(
Object.assign({}, cryptoResult, { publicKey }),
);
}
Expand All @@ -61,7 +61,7 @@ export function itShouldEncryptThePassphraseUsingThePassword() {

export function itShouldResolveToTheResultOfEncryptingThePassphrase() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
return returnValue.should.eventually.equal(cryptoResult);
}

export function itShouldDecryptTheMessageUsingTheNonceThePassphraseAndTheSenderPublicKey() {
Expand All @@ -76,7 +76,7 @@ export function itShouldDecryptTheMessageUsingTheNonceThePassphraseAndTheSenderP

export function itShouldResolveToTheResultOfDecryptingTheMessage() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
return returnValue.should.eventually.equal(cryptoResult);
}

export function itShouldEncryptTheMessageWithThePassphraseForTheRecipient() {
Expand All @@ -90,7 +90,7 @@ export function itShouldEncryptTheMessageWithThePassphraseForTheRecipient() {

export function itShouldResolveToTheResultOfEncryptingTheMessage() {
const { returnValue, cryptoResult } = this.test.ctx;
return returnValue.should.be.fulfilledWith(cryptoResult);
return returnValue.should.eventually.equal(cryptoResult);
}

export function itShouldResolveToAnObjectWithThePassphraseAndThePublicKeyAndTheAddress() {
Expand All @@ -105,12 +105,12 @@ export function itShouldResolveToAnObjectWithThePassphraseAndThePublicKeyAndTheA
publicKey,
address,
};
return returnValue.should.be.fulfilledWith(expectedObject);
return returnValue.should.eventually.eql(expectedObject);
}

export function theSignatureShouldBeReturned() {
const { returnValue, signature } = this.test.ctx;
return returnValue.should.be.eql(signature);
return returnValue.should.be.equal(signature);
}

export function liskJSCryptoShouldBeUsedToSignTheMessage() {
Expand Down Expand Up @@ -146,7 +146,7 @@ export function liskJSCryptoShouldBeUsedToGetTheKeysForThePassphrase() {

export function theKeysShouldBeReturned() {
const { returnValue, keys } = this.test.ctx;
return returnValue.should.eql(keys);
return returnValue.should.equal(keys);
}

export function theErrorResponseShouldBeHandled() {
Expand All @@ -164,7 +164,7 @@ export function liskJSCryptoShouldBeUsedToGetTheEncryptedPassphraseAndIV() {

export function theEncryptedPassphraseAndIVShouldBeReturned() {
const { returnValue, cipherAndIv } = this.test.ctx;
return returnValue.should.eql(cipherAndIv);
return returnValue.should.equal(cipherAndIv);
}

export function liskJSCryptoShouldBeUsedToGetTheDecryptedPassphrase() {
Expand All @@ -191,7 +191,7 @@ export function liskJSCryptoShouldBeUsedToGetTheEncryptedMessageAndNonce() {

export function theEncryptedMessageAndNonceShouldBeReturned() {
const { returnValue, cipherAndNonce } = this.test.ctx;
return returnValue.should.eql(cipherAndNonce);
return returnValue.should.equal(cipherAndNonce);
}

export function liskJSCryptoShouldBeUsedToGetTheDecryptedMessage() {
Expand All @@ -215,12 +215,12 @@ export function theDecryptedMessageShouldBeReturned() {

export function itShouldResolveToThePassphrase() {
const { returnValue, passphrase } = this.test.ctx;
return returnValue.should.be.fulfilledWith(passphrase);
return returnValue.should.eventually.equal(passphrase);
}

export function itShouldReturnAnObjectWithThePassphrase() {
const { returnValue, passphrase } = this.test.ctx;
return returnValue.should.be.fulfilledWith({
return returnValue.should.eventually.eql({
passphrase,
secondPassphrase: null,
password: null,
Expand All @@ -230,7 +230,7 @@ export function itShouldReturnAnObjectWithThePassphrase() {

export function itShouldReturnAnObjectWithTheSecondPassphrase() {
const { returnValue, secondPassphrase } = this.test.ctx;
return returnValue.should.be.fulfilledWith({
return returnValue.should.eventually.eql({
passphrase: null,
secondPassphrase,
password: null,
Expand All @@ -240,7 +240,7 @@ export function itShouldReturnAnObjectWithTheSecondPassphrase() {

export function itShouldReturnAnObjectWithThePassword() {
const { returnValue, password } = this.test.ctx;
return returnValue.should.be.fulfilledWith({
return returnValue.should.eventually.eql({
passphrase: null,
secondPassphrase: null,
password,
Expand All @@ -250,7 +250,7 @@ export function itShouldReturnAnObjectWithThePassword() {

export function itShouldReturnAnObjectWithTheData() {
const { returnValue, data } = this.test.ctx;
return returnValue.should.be.fulfilledWith({
return returnValue.should.eventually.eql({
passphrase: null,
secondPassphrase: null,
password: null,
Expand All @@ -266,7 +266,7 @@ export function itShouldReturnAnObjectWithThePassphraseTheSecondPassphraseThePas
password,
data,
} = this.test.ctx;
return returnValue.should.be.fulfilledWith({
return returnValue.should.eventually.eql({
passphrase,
secondPassphrase,
password,
Expand Down
4 changes: 2 additions & 2 deletions test/steps/files/3_then.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export function theDefaultConfigShouldBeWrittenToTheConfigFile() {
}

export function theConfigFileShouldNotBeWritten() {
return fsUtils.writeJSONSync.should.not.be.called();
return fsUtils.writeJSONSync.should.not.be.called;
}

export function itShouldResolveToTheFirstLineOfTheFile() {
const { returnValue, passphrase } = this.test.ctx;
return returnValue.should.be.fulfilledWith(passphrase);
return returnValue.should.eventually.equal(passphrase);
}
Loading

0 comments on commit ee93414

Please sign in to comment.