Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Restructure the integration tests for Jest - Closes #3986 #3985

Merged
merged 15 commits into from
Jul 27, 2019

Conversation

nazarhussain
Copy link
Contributor

@nazarhussain nazarhussain commented Jul 22, 2019

What was the problem?

There were old integration tests in "Mocha" which are some what outdated. So instead of fixing those, we decided to rewrite these tests in the Jest, obviously using the much of the code possible from old test.

How did I fix it?

In this PR, we just added the empty skeleton for integration tests.

Review checklist

yatki
yatki previously requested changes Jul 22, 2019
Copy link
Contributor

@yatki yatki left a comment

Choose a reason for hiding this comment

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

This is quite a lot of effort. Thanks nazar.

I just have one concern, I highlighted. Let me know what you think @shuse2 @pablitovicente

@@ -0,0 +1,19 @@
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

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

missing licence header

describe('exceptions for senderPublicKey transactions', () => {
describe('send funds to account', () => {
describe('details of the accounts', () => {
describe('when forging block with transaction with collision publicKey', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just highlighting this line as an example. But In general, please avoid nested describe blocks as much as possible. The 3 describe blocks above can be merged into one. We can always add more describe blocks when it's really needed.

If we don't do it in this PR, others will follow the same pattern and we'll end up having bunch of redundant describe blocks.

So would be great if we could improve test descriptions by following the rules below,
1 - Each describe block (except the root one) should start with when.
2 - Each it should start with should.
3 - We don't need describe blocks which contain only one test. We should add them when it's really needed.

@shuse2 there are 53 files in the PR. I think @nazarhussain mainly copied the testing structure from mocha and wasn't planning to spend more time on it. But I think these refactorings are important and maybe we can assign more people to split the files to write test cases properly.

Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yatki I agree to all what you said and related to that I asked @shuse2 to decided on some practices e.g. nested level for describe etc and then individual person working on each tests will follow those.

In this PR, I just extracted the skeleton from existing tests and restructured the files a bit to follow current source structure.

@shuse2
Copy link
Collaborator

shuse2 commented Jul 22, 2019

@nazarhussain GJ on the PR.
@yatki
The main purpose of this PR is to setup the good test standard for the integration test.
So, I agree that it still needs to improve the description, as the way you pointed out, too.

At the end, Im expecting to have the good standard for writing the test description for integration and above that we can follow. However, at the same time, I didn't want to loose the current test scenarios too.
Therefore, I ask @nazarhussain to convert the current test to jest and we can improve from there.
Let's improve this PR to the point that can be standard with couple

@shuse2 shuse2 changed the title Restructure the integration tests for Jest Restructure the integration tests for Jest - Closes #3986 Jul 22, 2019
describe('applyBlock', () => {
describe('applyConfirmedStep', () => {
describe('after applying new block fails', () => {
it.todo('should have pooled transactions in queued state');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe combine this in an it with the describe above it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are multiple specs in this describe, so seems ok to not merge.

'use strict';

describe('integration test (blocks) - chain/popLastBlock', () => {
describe('popLastBlock', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe simplify the level of describes here so we have less levels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It follows the structure of the code, anyone who implement and refactor the code as well can improve it.

it.todo('should load block 3 from db: block with transactions');
});

describe('loadBlocksOffset() - block/transaction errors', () => {
Copy link
Contributor

@pablitovicente pablitovicente Jul 23, 2019

Choose a reason for hiding this comment

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

Maybe split these into describe('loadBlocksOffset() - block errors') and describe('loadBlocksOffset() - transaction errors') ?


it.todo('all blocks should have version = 0');

describe('increase block version = 1 and exceptions for height = 5', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do not nest this cases and repeat setup for each of the three scenarios?


'use strict';

describe('validateOwnChain', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for framework/test/jest/integration/specs/modules/chain/loader/validate_own_chain/first_round.spec.js

@2snEM6 2snEM6 self-requested a review July 23, 2019 09:05

'use strict';

describe('validateOwnChain', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for framework/test/jest/integration/specs/modules/chain/loader/validate_own_chain/first_round.spec.js


'use strict';

describe('validateOwnChain', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for framework/test/jest/integration/specs/modules/chain/loader/validate_own_chain/first_round.spec.js


'use strict';

describe('validateOwnChain', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as for framework/test/jest/integration/specs/modules/chain/loader/validate_own_chain/first_round.spec.js

});

describe('when forging a new block', () => {
describe('when transaction pool is full and current context (last block height) at forging time, no longer matches the transaction matcher', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remove the extra describe? or split in two different describes?

'use strict';

describe('rebuilding', () => {
describe('rebuilding to end of round 2 when blockchain contains 303 blocks', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remove extra describe or add more scenarios if the idea was that there might be more?

@nazarhussain
Copy link
Contributor Author

@shuse2 There seems to be a lot of updates going on this PR from different point of view. We should rather first agree on some basic stuff then refactor and review the PR accordingly. e.g. How much nested levels these test should support, should we split tests to different files based on different describe blocks

You want to make this refactoring a standard, although for me its vice versa. First we describe some standards or practices then refactor this PR accordingly. In any case, unless we have such coding practices documented anywhere, every individual person can't extract it from looking at test files.

@nazarhussain
Copy link
Contributor Author

@pablitovicente @shuse2 @limiaspasdaniel @yatki Feel free to add your commits to the PR directly, so we can close it earliest possible.

Copy link
Contributor

@pablitovicente pablitovicente left a comment

Choose a reason for hiding this comment

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

I think we still can continue improving the descriptions. Once we start re-writing the tests we should check again the descriptions to make sure they work as very clear documentation.

@shuse2 shuse2 merged commit bdc8c16 into development Jul 27, 2019
@shuse2 shuse2 deleted the nh-integration-tests-jest branch July 27, 2019 12:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate the integration test description to Jest folder with standard.
6 participants