Skip to content

Commit ba86d4a

Browse files
fabiorigamlucanicoladebiasirodolfopietro97Luca Debiasi
authored
Improve test naming (#571)
* test: 514: improve test naming to specify which involve mock, testnet, solo, or combine them * fix: from instead caller * fix: test names * feat: check tests naming script * fix: add exit code * fix: correct exit condition and naming correctly last test * fix: 514-improve-test-naming merged files conflicting with main: command not found * fix: update contributing guidelines for tests --------- Co-authored-by: ldebiasi <luca.nicola.debiasi@gmail.com> Co-authored-by: rodolfopietro97 <rodolfo@rodolfopietro.it> Co-authored-by: Rodolfo Pietro Calabrò <33911400+rodolfopietro97@users.noreply.github.com> Co-authored-by: Luca Debiasi <ldebiasi@x1e.ht.home>
1 parent bf215d8 commit ba86d4a

File tree

99 files changed

+96
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+96
-17
lines changed

.github/CONTRIBUTING.md

+23

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
yarn build
55
yarn lint
66
yarn test:unit && git add docs
7+
yarn check-tests-naming

package.json

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,21 @@
88
"scripts": {
99
"start-thor-solo": "echo 'Starting thor solo node ...' && docker compose up -d --wait && echo '\nThor solo node started ...'",
1010
"stop-thor-solo": "echo 'Stopping thor solo node ...' && docker compose down && echo 'Thor solo node stopped ...'",
11-
1211
"postinstall": "husky install",
13-
1412
"build": "turbo build",
15-
1613
"generate:apidocs": "typedoc --options typedoc.json --logLevel Error",
1714
"generate:apidocs-debug": "typedoc --options typedoc.json --logLevel Verbose --plugin typedoc-plugin-missing-exports --validation.notDocumented",
18-
1915
"lint": "turbo lint",
2016
"format": "turbo format",
21-
2217
"test:unit": "turbo test:unit",
23-
2418
"test:integration": "turbo test:integration",
2519
"test:integration:solo": "(yarn start-thor-solo && yarn test:integration && yarn stop-thor-solo) || yarn stop-thor-solo",
26-
2720
"test:examples": "turbo test:examples",
2821
"test:examples:solo": "(yarn start-thor-solo && yarn test:examples && yarn stop-thor-solo) || yarn stop-thor-solo",
29-
3022
"test": "turbo test --force && yarn merge-coverage",
3123
"test:solo": "(yarn start-thor-solo && yarn test && yarn stop-thor-solo) || yarn stop-thor-solo",
32-
33-
"merge-coverage": "ts-node scripts/merge-coverage.ts"
24+
"merge-coverage": "ts-node scripts/merge-coverage.ts",
25+
"check-tests-naming": "ts-node scripts/check-tests-naming.ts"
3426
},
3527
"private": true,
3628
"workspaces": [
@@ -53,6 +45,7 @@
5345
"eslint-plugin-prettier": "^5.1.3",
5446
"eslint-plugin-promise": "^6.0.0",
5547
"fs-extra": "^11.2.0",
48+
"glob": "^10.3.10",
5649
"husky": "^9.0.11",
5750
"jest": "^29.7.0",
5851
"jest-docblock": "^29",
File renamed without changes.
File renamed without changes.

packages/network/tests/thor-client/nodes/nodes.testnet.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('ThorClient - Nodes Module', () => {
1212
*/
1313
test('Should get nodes', async () => {
1414
/**
15-
* client required to access a node
15+
* client required accessing a node
1616
* @internal
1717
*/
1818
const thorClient = new ThorClient(testNetwork);

packages/network/tests/utils/subscriptions/subscriptions.solo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const TIMEOUT = 15000; // 15-second timeout
2626
*
2727
* @group integration/utils/subscriptions
2828
*/
29-
describe('Subscriptions Solo', () => {
29+
describe('Subscriptions Solo network tests', () => {
3030
test(
3131
'Should receive new blocks from the block subscription',
3232
async () => {

packages/network/tests/utils/subscriptions/subscriptions.testnet.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { testnetUrl } from '../../fixture';
1414
/**
1515
* Test suite for the Subscriptions utility methods for getting the subscription URLs
1616
*
17-
* @group unit/utils/subscriptions
17+
* @group integration/utils/subscriptions
1818
*/
1919
describe('Subscriptions Testnet', () => {
2020
/**

packages/provider/tests/rpc-mapper/methods/eth_accounts/eth_accounts.test.ts packages/provider/tests/rpc-mapper/methods/eth_accounts/eth_accounts.solo.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeEach, describe, expect, test } from '@jest/globals';
22
import { RPC_METHODS, RPCMethodsMap, VechainProvider } from '../../../../src';
33
import { ThorClient } from '@vechain/vechain-sdk-network';
4-
import { testNetwork, THOR_SOLO_ACCOUNTS_BASE_WALLET } from '../../../fixture';
4+
import { soloNetwork, THOR_SOLO_ACCOUNTS_BASE_WALLET } from '../../../fixture';
55
import { type Wallet } from '@vechain/vechain-sdk-wallet';
66

77
/**
@@ -25,7 +25,7 @@ describe('RPC Mapper - eth_accounts method tests', () => {
2525
*/
2626
beforeEach(() => {
2727
// Init thor client
28-
thorClient = new ThorClient(testNetwork);
28+
thorClient = new ThorClient(soloNetwork);
2929

3030
// Init provider
3131
provider = new VechainProvider(

packages/provider/tests/rpc-mapper/methods/eth_requestAccounts/eth_requestAccounts.test.ts packages/provider/tests/rpc-mapper/methods/eth_requestAccounts/eth_requestAccounts.solo.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeEach, describe, expect, test } from '@jest/globals';
22
import { RPC_METHODS, RPCMethodsMap, VechainProvider } from '../../../../src';
33
import { ThorClient } from '@vechain/vechain-sdk-network';
4-
import { testNetwork, THOR_SOLO_ACCOUNTS_BASE_WALLET } from '../../../fixture';
4+
import { soloNetwork, THOR_SOLO_ACCOUNTS_BASE_WALLET } from '../../../fixture';
55
import { type Wallet, type WalletAccount } from '@vechain/vechain-sdk-wallet';
66
import { ProviderRpcError } from '@vechain/vechain-sdk-errors';
77

@@ -26,7 +26,7 @@ describe('RPC Mapper - eth_requestAccounts method tests', () => {
2626
*/
2727
beforeEach(() => {
2828
// Init thor client
29-
thorClient = new ThorClient(testNetwork);
29+
thorClient = new ThorClient(soloNetwork);
3030

3131
// Init provider
3232
provider = new VechainProvider(

scripts/check-tests-naming.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Define the glob pattern
2+
import { glob } from 'glob';
3+
4+
/**
5+
* Pattern to match all test files starting from the root of the project
6+
*/
7+
const test_pattern = './packages/**/**/*.test.ts';
8+
9+
/**
10+
* Allowed names for test files
11+
*/
12+
const allowed_names = [
13+
// Unit tests
14+
'.unit.test.ts',
15+
16+
// Integration tests
17+
'.testnet.test.ts',
18+
'.mainnet.test.ts',
19+
'.solo.test.ts',
20+
21+
// Mocks
22+
'.mock.testnet.ts',
23+
'.mock.mainnet.ts',
24+
'.mock.solo.ts'
25+
];
26+
27+
/**
28+
* Exit with error code 1 if any test file is not named correctly.
29+
* The Default exit code is 0.
30+
* As good programmers, we assume we're naming tests correctly :D
31+
*/
32+
let exit_code = 0;
33+
34+
/**
35+
* Get all test files
36+
*/
37+
glob(test_pattern, { ignore: 'node_modules/**' }).then((test_files) => {
38+
/**
39+
* Iterate over all test files to check if they are named correctly
40+
*/
41+
test_files.forEach((file) => {
42+
// File naming is not ok by default
43+
let file_naming_ok = false;
44+
45+
/**
46+
* Iterate over all allowed names to check if the file is named correctly
47+
*/
48+
allowed_names.forEach((allowed_name) => {
49+
if (file.endsWith(allowed_name)) {
50+
file_naming_ok = true;
51+
}
52+
});
53+
54+
if (!file_naming_ok) {
55+
console.error(`Test file \`${file}\` is not named correctly`);
56+
exit_code = 1;
57+
}
58+
});
59+
60+
// Exit with the correct code
61+
process.exit(exit_code);
62+
});

0 commit comments

Comments
 (0)