Skip to content

Commit 2cbfd3e

Browse files
authored
test: esm variant of integration tests (#779)
* test: move integration tests to tests directory * test: integration tests on esm * tests: move test utils to tests folder * tests: move jest setup file * tests: use projects instead of group runner * tests: update test coverage setup * tests: fix failing & flaky integration tests * ci: run esm tests in ci
1 parent 9c46955 commit 2cbfd3e

84 files changed

Lines changed: 1254 additions & 1860 deletions

File tree

Some content is hidden

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

.eslintrc.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
devDependencies: [
3838
'**/*.test.ts',
3939
'**/*.spec.ts',
40-
'**/__integrationtests__/*',
40+
'tests/**/*',
4141
'**/webpack.config.js',
4242
],
4343
},
@@ -142,7 +142,7 @@ module.exports = {
142142
'jsdoc/check-tag-names': [
143143
'warn',
144144
{
145-
definedTags: ['group', 'packageDocumentation'],
145+
definedTags: ['packageDocumentation'],
146146
},
147147
],
148148
'@typescript-eslint/no-var-requires': 'off',
@@ -152,31 +152,20 @@ module.exports = {
152152
'no-console': 'off',
153153
},
154154
},
155-
{
156-
files: ['**/__integrationtests__/*.ts', '**/TestUtils.ts'],
157-
rules: {
158-
'import/extensions': 'off',
159-
'jsdoc/require-jsdoc': 'off',
160-
'no-console': 'off',
161-
},
162-
},
163155
{
164156
files: ['**/augment-api/src/interfaces/**/*.ts'],
165157
rules: {
166158
'license-header/header': 'off',
167159
},
168160
},
169161
{
170-
files: ['tests/*'],
162+
files: ['tests/**/*', 'packages/testing/**/*'],
171163
rules: {
164+
'import/extensions': 'off',
165+
'jsdoc/require-jsdoc': 'off',
172166
'no-console': 'off',
173167
'@typescript-eslint/explicit-function-return-type': 'off',
174-
'import/no-extraneous-dependencies': [
175-
'error',
176-
{
177-
devDependencies: ['tests/*', 'tests/bundle.spec.ts'],
178-
},
179-
],
168+
'import/no-extraneous-dependencies': 'off'
180169
},
181170
},
182171
],

.github/workflows/test-node-candidate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090

9191
- name: run integration tests
9292
timeout-minutes: 60
93-
run: yarn test:integration:ci
93+
run: yarn test:integration -b
9494

9595
bundle_cache:
9696
runs-on: ubuntu-latest

.github/workflows/tests-polkadot-deps.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ jobs:
122122
with:
123123
image: ${{ env.TESTCONTAINERS_WATCHER_IMG }}
124124

125-
- name: run integration tests
125+
- name: run integration tests (cjs)
126126
timeout-minutes: 60
127-
run: yarn test:integration:ci
127+
run: yarn test:integration -b
128+
129+
- name: run integration tests (esm)
130+
timeout-minutes: 60
131+
run: yarn test:integration:esm -b
128132

129133
create-issue:
130134
runs-on: ubuntu-latest

.github/workflows/tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ jobs:
161161
with:
162162
image: ${{ env.TESTCONTAINERS_WATCHER_IMG }}
163163

164-
- name: run integration tests
164+
- name: run integration tests (cjs)
165165
timeout-minutes: 60
166-
run: yarn test:integration:ci
166+
run: yarn test:integration -b
167+
168+
- name: run integration tests (esm)
169+
timeout-minutes: 60
170+
run: yarn test:integration:esm -b
171+
167172

168173
bundle_cache:
169174
runs-on: ubuntu-latest

babel.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
[
44
"@babel/preset-env",
55
{
6-
"modules": "commonjs"
6+
"modules": "commonjs",
7+
"targets": {"node": "current"}
78
}
89
]
910
]

jest-setup/setup.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.js

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
module.exports = {
2-
preset: 'ts-jest',
1+
const common = {
32
testEnvironment: 'node',
43
clearMocks: true,
5-
runner: 'groups',
6-
// Parachain block time is 12s
7-
testTimeout: 15000,
8-
setupFilesAfterEnv: ['../jest-setup/setup.js'],
9-
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/|@digitalbazaar|base.+-universal|crypto-ld)'],
4+
setupFilesAfterEnv: ['<rootDir>/tests/jest.setup.js'],
5+
transformIgnorePatterns: ['/node_modules/(?!@digitalbazaar|base.+-universal|crypto-ld)'],
6+
transform: {
7+
"\\.js$": ["babel-jest", { root: './' }],
8+
"\\.ts$": "ts-jest"
9+
},
10+
resolver: "ts-jest-resolver",
11+
moduleDirectories: [
12+
"node_modules",
13+
"packages/*/src"
14+
],
15+
coverageDirectory: 'coverage',
1016
coverageThreshold: {
1117
global: {
1218
branches: 70,
@@ -15,37 +21,44 @@ module.exports = {
1521
statements: 80,
1622
},
1723
},
18-
transform: {
19-
"\\.js$": "babel-jest",
20-
"\\.ts$": "ts-jest"
21-
},
2224
collectCoverageFrom: [
23-
'**/*/src/**/*.ts',
24-
'!**/index.ts',
25-
'!**/__integrationtests__/**',
26-
'!**/__mocks__/**',
27-
'!**/__tests__/**',
28-
'!**/lib/**',
29-
'!**/test/**',
30-
'!**/kilt/*',
31-
'!**/types/**/*',
32-
'!**/SDKErrors.ts',
33-
'!utils/src/json-schema/*',
34-
'!testing/**',
35-
'!augment-api/**',
36-
'!type-definitions/**',
37-
'!**/*.chain.ts',
38-
'!did/src/Did.chain.ts',
39-
'!did/src/Did.rpc.ts',
40-
'!did/src/Did.utils.ts',
41-
'!utils/src/jsonabc.ts',
42-
'!core/src/utils.ts',
25+
'packages/*/src/**',
26+
],
27+
coveragePathIgnorePatterns: [
28+
// test and library code
29+
'/node_modules/',
30+
'/lib/',
31+
'/tests/',
32+
// not properly testable
33+
'packages/types/',
34+
'packages/augment-api/',
35+
'packages/type-definitions/',
36+
'packages/core/src/kilt/',
37+
'index.ts',
38+
'types.ts',
39+
'.chain.ts',
40+
'SDKErrors.ts',
41+
'Did.rpc.ts',
42+
'packages/core/src/utils.ts',
43+
// third party code copied to this repo
44+
'packages/utils/src/json-schema/',
45+
'jsonabc.ts',
4346
],
44-
resolver: "ts-jest-resolver",
45-
rootDir: 'packages',
46-
coverageDirectory: 'coverage',
47-
moduleDirectories: [
48-
"node_modules",
49-
"packages/*/src"
50-
]
5147
}
48+
49+
module.exports = {
50+
...common,
51+
testTimeout: 5000,
52+
projects: [
53+
{
54+
...common,
55+
displayName: 'unit',
56+
roots: ['<rootDir>/packages'],
57+
},
58+
{
59+
...common,
60+
displayName: 'breaking',
61+
roots: ['<rootDir>/tests/breakingChanges'],
62+
},
63+
]
64+
}

package.json

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@
1111
"build": "yarn workspaces foreach -p -t --exclude '{root-workspace}' run build",
1212
"build:docs": "typedoc --theme default --out docs/api --tsconfig tsconfig.docs.json && touch docs/.nojekyll",
1313
"bundle": "yarn workspace @kiltprotocol/sdk-js run bundle",
14-
"clean": "rimraf tests/dist && yarn workspaces foreach -p --exclude '{root-workspace}' run clean",
14+
"clean": "rimraf tests/bundle/dist && rimraf tests/integration/dist && yarn workspaces foreach -p --exclude '{root-workspace}' run clean",
1515
"clean:docs": "rimraf docs/api",
1616
"prepublish": "yarn workspaces foreach -p --no-private exec cp -f ../../LICENSE .",
1717
"publish": "yarn workspaces foreach -pt --no-private npm publish",
18-
"lint": "eslint packages --format=codeframe",
18+
"lint": "eslint packages tests --format=codeframe",
1919
"lint:fix": "yarn lint --fix",
2020
"set:version": "npm version --no-git-tag-version --no-workspaces-update --workspaces --include-workspace-root",
2121
"style": "prettier -l packages",
2222
"style:fix": "yarn style --write",
23-
"test": "jest --coverage --group=unit",
24-
"test:breaking": "jest --group=breaking",
23+
"test": "jest --coverage --selectProjects=unit",
24+
"test:breaking": "jest --selectProjects=breaking",
2525
"test:ci": "yarn test --ci --forceExit",
26-
"test:integration": "jest --group=integration -w 3 --testTimeout=30000",
27-
"test:integration:ci": "jest --group=integration -b -w 3 --testTimeout=60000",
26+
"test:integration": "jest -c tests/integration/jest.config.integration.js",
27+
"build:esm-tests": "rimraf tests/integration/dist && tsc -p tests/integration/tsconfig.esm.json && echo '{\"type\":\"module\"}' > tests/integration/dist/package.json",
28+
"test:integration:esm": "yarn build:esm-tests && yarn node --experimental-vm-modules $(yarn bin jest) -c tests/integration/jest.config.integration.esm.js",
2829
"test:integration:latest-develop": "TESTCONTAINERS_NODE_IMG=kiltprotocol/mashnet-node:latest-develop yarn test:integration",
2930
"test:watch": "yarn test --watch",
30-
"test:bundle": "tsc -p tests/tsconfig.json && yarn ./tests playwright test --config playwright.config.ts",
31+
"test:bundle": "tsc -p tests/bundle/tsconfig.json && yarn ./tests/bundle playwright test --config playwright.config.ts",
3132
"test:ci:bundle": "yarn test:ci:bundle:preparation && yarn test:bundle",
3233
"test:ci:bundle:preparation": "yarn playwright install-deps && yarn playwright install chromium"
3334
},
@@ -47,7 +48,7 @@
4748
"@commitlint/cli": "^9.0.1",
4849
"@commitlint/config-conventional": "^9.0.1",
4950
"@playwright/test": "^1.21.1",
50-
"@types/jest": "^27.4.0",
51+
"@types/jest": "^29.5.3",
5152
"@typescript-eslint/eslint-plugin": "^5.7.0",
5253
"@typescript-eslint/parser": "^5.7.0",
5354
"eslint": "^7.32.0",
@@ -58,15 +59,12 @@
5859
"eslint-plugin-license-header": "^0.2.1",
5960
"eslint-plugin-prettier": "^3.4.1",
6061
"husky": "^4.2.5",
61-
"jest": "^27.4.7",
62-
"jest-docblock": "^27.4.0",
63-
"jest-runner": "^27.4.6",
64-
"jest-runner-groups": "^2.1.0",
62+
"jest": "^29.6.1",
6563
"prettier": "^2.4.1",
6664
"rimraf": "^3.0.2",
6765
"testcontainers": "^9.0.0",
68-
"ts-jest": "^27.1.2",
69-
"ts-jest-resolver": "^2.0.0",
66+
"ts-jest": "^29.1.1",
67+
"ts-jest-resolver": "^2.0.1",
7068
"typedoc": "^0.23.0",
7169
"typescript": "^4.8.3"
7270
},

packages/chain-helpers/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"bugs": "https://github.com/KILTprotocol/sdk-js/issues",
3131
"homepage": "https://github.com/KILTprotocol/sdk-js#readme",
3232
"devDependencies": {
33-
"@kiltprotocol/testing": "workspace:*",
3433
"@polkadot/keyring": "^12.0.0",
3534
"rimraf": "^3.0.2",
3635
"typescript": "^4.8.3"

packages/chain-helpers/src/blockchain/Blockchain.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
* found in the LICENSE file in the root directory of this source tree.
66
*/
77

8-
/**
9-
* @group unit/blockchain
10-
*/
11-
12-
import { ApiMocks } from '@kiltprotocol/testing'
138
import { ConfigService } from '@kiltprotocol/config'
149
import type { KeyringPair } from '@kiltprotocol/types'
1510
import { Crypto, SDKErrors } from '@kiltprotocol/utils'
1611

12+
import { ApiMocks } from '../../../../tests/testUtils'
1713
import {
1814
IS_FINALIZED,
1915
IS_IN_BLOCK,

0 commit comments

Comments
 (0)