Skip to content

Commit

Permalink
test: esm variant of integration tests (#779)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rflechtner authored Jul 26, 2023
1 parent 9c46955 commit 2cbfd3e
Show file tree
Hide file tree
Showing 84 changed files with 1,254 additions and 1,860 deletions.
23 changes: 6 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
devDependencies: [
'**/*.test.ts',
'**/*.spec.ts',
'**/__integrationtests__/*',
'tests/**/*',
'**/webpack.config.js',
],
},
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = {
'jsdoc/check-tag-names': [
'warn',
{
definedTags: ['group', 'packageDocumentation'],
definedTags: ['packageDocumentation'],
},
],
'@typescript-eslint/no-var-requires': 'off',
Expand All @@ -152,31 +152,20 @@ module.exports = {
'no-console': 'off',
},
},
{
files: ['**/__integrationtests__/*.ts', '**/TestUtils.ts'],
rules: {
'import/extensions': 'off',
'jsdoc/require-jsdoc': 'off',
'no-console': 'off',
},
},
{
files: ['**/augment-api/src/interfaces/**/*.ts'],
rules: {
'license-header/header': 'off',
},
},
{
files: ['tests/*'],
files: ['tests/**/*', 'packages/testing/**/*'],
rules: {
'import/extensions': 'off',
'jsdoc/require-jsdoc': 'off',
'no-console': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['tests/*', 'tests/bundle.spec.ts'],
},
],
'import/no-extraneous-dependencies': 'off'
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-node-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:

- name: run integration tests
timeout-minutes: 60
run: yarn test:integration:ci
run: yarn test:integration -b

bundle_cache:
runs-on: ubuntu-latest
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests-polkadot-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ jobs:
with:
image: ${{ env.TESTCONTAINERS_WATCHER_IMG }}

- name: run integration tests
- name: run integration tests (cjs)
timeout-minutes: 60
run: yarn test:integration:ci
run: yarn test:integration -b

- name: run integration tests (esm)
timeout-minutes: 60
run: yarn test:integration:esm -b

create-issue:
runs-on: ubuntu-latest
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ jobs:
with:
image: ${{ env.TESTCONTAINERS_WATCHER_IMG }}

- name: run integration tests
- name: run integration tests (cjs)
timeout-minutes: 60
run: yarn test:integration:ci
run: yarn test:integration -b

- name: run integration tests (esm)
timeout-minutes: 60
run: yarn test:integration:esm -b


bundle_cache:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[
"@babel/preset-env",
{
"modules": "commonjs"
"modules": "commonjs",
"targets": {"node": "current"}
}
]
]
Expand Down
6 changes: 0 additions & 6 deletions jest-setup/setup.js

This file was deleted.

89 changes: 51 additions & 38 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module.exports = {
preset: 'ts-jest',
const common = {
testEnvironment: 'node',
clearMocks: true,
runner: 'groups',
// Parachain block time is 12s
testTimeout: 15000,
setupFilesAfterEnv: ['../jest-setup/setup.js'],
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/|@digitalbazaar|base.+-universal|crypto-ld)'],
setupFilesAfterEnv: ['<rootDir>/tests/jest.setup.js'],
transformIgnorePatterns: ['/node_modules/(?!@digitalbazaar|base.+-universal|crypto-ld)'],
transform: {
"\\.js$": ["babel-jest", { root: './' }],
"\\.ts$": "ts-jest"
},
resolver: "ts-jest-resolver",
moduleDirectories: [
"node_modules",
"packages/*/src"
],
coverageDirectory: 'coverage',
coverageThreshold: {
global: {
branches: 70,
Expand All @@ -15,37 +21,44 @@ module.exports = {
statements: 80,
},
},
transform: {
"\\.js$": "babel-jest",
"\\.ts$": "ts-jest"
},
collectCoverageFrom: [
'**/*/src/**/*.ts',
'!**/index.ts',
'!**/__integrationtests__/**',
'!**/__mocks__/**',
'!**/__tests__/**',
'!**/lib/**',
'!**/test/**',
'!**/kilt/*',
'!**/types/**/*',
'!**/SDKErrors.ts',
'!utils/src/json-schema/*',
'!testing/**',
'!augment-api/**',
'!type-definitions/**',
'!**/*.chain.ts',
'!did/src/Did.chain.ts',
'!did/src/Did.rpc.ts',
'!did/src/Did.utils.ts',
'!utils/src/jsonabc.ts',
'!core/src/utils.ts',
'packages/*/src/**',
],
coveragePathIgnorePatterns: [
// test and library code
'/node_modules/',
'/lib/',
'/tests/',
// not properly testable
'packages/types/',
'packages/augment-api/',
'packages/type-definitions/',
'packages/core/src/kilt/',
'index.ts',
'types.ts',
'.chain.ts',
'SDKErrors.ts',
'Did.rpc.ts',
'packages/core/src/utils.ts',
// third party code copied to this repo
'packages/utils/src/json-schema/',
'jsonabc.ts',
],
resolver: "ts-jest-resolver",
rootDir: 'packages',
coverageDirectory: 'coverage',
moduleDirectories: [
"node_modules",
"packages/*/src"
]
}

module.exports = {
...common,
testTimeout: 5000,
projects: [
{
...common,
displayName: 'unit',
roots: ['<rootDir>/packages'],
},
{
...common,
displayName: 'breaking',
roots: ['<rootDir>/tests/breakingChanges'],
},
]
}
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
"build": "yarn workspaces foreach -p -t --exclude '{root-workspace}' run build",
"build:docs": "typedoc --theme default --out docs/api --tsconfig tsconfig.docs.json && touch docs/.nojekyll",
"bundle": "yarn workspace @kiltprotocol/sdk-js run bundle",
"clean": "rimraf tests/dist && yarn workspaces foreach -p --exclude '{root-workspace}' run clean",
"clean": "rimraf tests/bundle/dist && rimraf tests/integration/dist && yarn workspaces foreach -p --exclude '{root-workspace}' run clean",
"clean:docs": "rimraf docs/api",
"prepublish": "yarn workspaces foreach -p --no-private exec cp -f ../../LICENSE .",
"publish": "yarn workspaces foreach -pt --no-private npm publish",
"lint": "eslint packages --format=codeframe",
"lint": "eslint packages tests --format=codeframe",
"lint:fix": "yarn lint --fix",
"set:version": "npm version --no-git-tag-version --no-workspaces-update --workspaces --include-workspace-root",
"style": "prettier -l packages",
"style:fix": "yarn style --write",
"test": "jest --coverage --group=unit",
"test:breaking": "jest --group=breaking",
"test": "jest --coverage --selectProjects=unit",
"test:breaking": "jest --selectProjects=breaking",
"test:ci": "yarn test --ci --forceExit",
"test:integration": "jest --group=integration -w 3 --testTimeout=30000",
"test:integration:ci": "jest --group=integration -b -w 3 --testTimeout=60000",
"test:integration": "jest -c tests/integration/jest.config.integration.js",
"build:esm-tests": "rimraf tests/integration/dist && tsc -p tests/integration/tsconfig.esm.json && echo '{\"type\":\"module\"}' > tests/integration/dist/package.json",
"test:integration:esm": "yarn build:esm-tests && yarn node --experimental-vm-modules $(yarn bin jest) -c tests/integration/jest.config.integration.esm.js",
"test:integration:latest-develop": "TESTCONTAINERS_NODE_IMG=kiltprotocol/mashnet-node:latest-develop yarn test:integration",
"test:watch": "yarn test --watch",
"test:bundle": "tsc -p tests/tsconfig.json && yarn ./tests playwright test --config playwright.config.ts",
"test:bundle": "tsc -p tests/bundle/tsconfig.json && yarn ./tests/bundle playwright test --config playwright.config.ts",
"test:ci:bundle": "yarn test:ci:bundle:preparation && yarn test:bundle",
"test:ci:bundle:preparation": "yarn playwright install-deps && yarn playwright install chromium"
},
Expand All @@ -47,7 +48,7 @@
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@playwright/test": "^1.21.1",
"@types/jest": "^27.4.0",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^7.32.0",
Expand All @@ -58,15 +59,12 @@
"eslint-plugin-license-header": "^0.2.1",
"eslint-plugin-prettier": "^3.4.1",
"husky": "^4.2.5",
"jest": "^27.4.7",
"jest-docblock": "^27.4.0",
"jest-runner": "^27.4.6",
"jest-runner-groups": "^2.1.0",
"jest": "^29.6.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"testcontainers": "^9.0.0",
"ts-jest": "^27.1.2",
"ts-jest-resolver": "^2.0.0",
"ts-jest": "^29.1.1",
"ts-jest-resolver": "^2.0.1",
"typedoc": "^0.23.0",
"typescript": "^4.8.3"
},
Expand Down
1 change: 0 additions & 1 deletion packages/chain-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bugs": "https://github.com/KILTprotocol/sdk-js/issues",
"homepage": "https://github.com/KILTprotocol/sdk-js#readme",
"devDependencies": {
"@kiltprotocol/testing": "workspace:*",
"@polkadot/keyring": "^12.0.0",
"rimraf": "^3.0.2",
"typescript": "^4.8.3"
Expand Down
6 changes: 1 addition & 5 deletions packages/chain-helpers/src/blockchain/Blockchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/blockchain
*/

import { ApiMocks } from '@kiltprotocol/testing'
import { ConfigService } from '@kiltprotocol/config'
import type { KeyringPair } from '@kiltprotocol/types'
import { Crypto, SDKErrors } from '@kiltprotocol/utils'

import { ApiMocks } from '../../../../tests/testUtils'
import {
IS_FINALIZED,
IS_IN_BLOCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/util
*/

import { SDKErrors } from '@kiltprotocol/utils'
import { makeSubscriptionPromise } from './SubscriptionPromise'

Expand Down
4 changes: 0 additions & 4 deletions packages/chain-helpers/src/errorhandling/ErrorHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/errorhandling
*/

import type { ISubmittableResult } from '@kiltprotocol/types'
import type { EventRecord } from '@polkadot/types/interfaces'
import { ErrorHandler } from './index'
Expand Down
4 changes: 0 additions & 4 deletions packages/config/src/ConfigService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/ConfigService
*/

/* eslint-disable dot-notation */
import { ApiPromise, WsProvider } from '@polkadot/api'
import { LogLevel, Logger } from 'typescript-logging'
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"bugs": "https://github.com/KILTprotocol/sdk-js/issues",
"homepage": "https://github.com/KILTprotocol/sdk-js#readme",
"devDependencies": {
"@kiltprotocol/testing": "workspace:*",
"@types/uuid": "^8.0.0",
"rimraf": "^3.0.2",
"testcontainers": "^9.0.0",
Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/attestation/Attestation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/attestation
*/

/* eslint-disable @typescript-eslint/ban-ts-comment */

import { ConfigService } from '@kiltprotocol/config'
import type {
IAttestation,
CTypeHash,
DidUri,
IAttestation,
ICType,
IClaim,
ICredential,
CTypeHash,
} from '@kiltprotocol/types'
import { SDKErrors } from '@kiltprotocol/utils'
import { ApiMocks } from '@kiltprotocol/testing'
import { ConfigService } from '@kiltprotocol/config'

import { ApiMocks } from '../../../../tests/testUtils'
import * as Claim from '../claim'
import * as CType from '../ctype'
import * as Credential from '../credential'
import * as CType from '../ctype'
import * as Attestation from './Attestation'

let mockedApi: any
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/balance/Balance.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* found in the LICENSE file in the root directory of this source tree.
*/

/**
* @group unit/balance
*/

import { BN } from '@polkadot/util'
import type {
BalanceNumber,
Expand Down Expand Up @@ -261,7 +257,7 @@ describe('toFemtoKilt', () => {
expect(() =>
toFemtoKilt('-0.0000001', 'nano').toString()
).toThrowErrorMatchingInlineSnapshot(
`"Too many decimal places: input with unit \\"nano\\" and value \\"-0.0000001\\" exceeds the 6 possible decimal places by 1"`
`"Too many decimal places: input with unit "nano" and value "-0.0000001" exceeds the 6 possible decimal places by 1"`
)
expect(toFemtoKilt('-0').toString()).toEqual(new BN('0').toString())
expect(toFemtoKilt('-0.000001', 'nano').toString()).toEqual(
Expand Down
Loading

0 comments on commit 2cbfd3e

Please sign in to comment.