Skip to content

Commit

Permalink
Configure jest unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Mar 15, 2024
1 parent 09ee7d6 commit 787c335
Show file tree
Hide file tree
Showing 11 changed files with 5,573 additions and 3,094 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ yarn-error.log
# IDE-specific directories
.idea/
.vscode/

# Tests artifacts
.coverage/

19 changes: 19 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const common = {
transform: {
"^.+\\.(t|j)s$": ["ts-jest", { tsconfig: "./tsconfig.json" }]
},
rootDir: ".",
setupFiles: ["./test/setup.ts"]
};

module.exports = {
collectCoverageFrom: ["./src/**/*.{js,ts}"],
projects: [
{
displayName: "unit",
...common,
testMatch: ["<rootDir>/src/**/*.spec.ts"],
setupFilesAfterEnv: ["./test/setup-unit-tests.ts"]
}
]
};
8,583 changes: 5,523 additions & 3,060 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
"prepare": "husky",
"prepublishOnly": "npm run build:production",
"test": "npm run test:unit",
"test:unit": "tap --ts tests/test_*.ts",
"test:unit-snapshot": "tap --ts --snapshot tests/test_*.ts"
"test:cov": "jest --selectProjects unit functional --coverage",
"test:unit": "tap --ts tests/test_*.ts && jest --selectProjects unit",
"test:unit-snapshot": "tap --ts --snapshot tests/test_*.ts",
"test:unit:cov": "jest --selectProjects unit --coverage",
"test:unit:watch": "jest --selectProjects unit --watch"
},
"lint-staged": {
"*.{js,ts}": [
Expand All @@ -59,20 +62,24 @@
"simple-jsonrpc-js": "^1.2.0"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@types/atob": "^2.1.2",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.5",
"@types/json-stable-stringify": "^1.0.34",
"@types/node-fetch": "2",
"@types/sinon": "^10.0.11",
"@types/tap": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.2",
"node-polyfill-webpack-plugin": "^1.1.4",
"prettier": "^3.2.5",
"rimraf": "^5.0.1",
"sinon": "^13.0.1",
"tap": "^15.1.6",
"ts-jest": "^29.1.2",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"ts-proto": "^1.104.0",
Expand Down
2 changes: 1 addition & 1 deletion src/certificates/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { create as create509, pems } from "./generate509";
import { SigningStargateClient } from "@cosmjs/stargate";
import { messages as stargateMessages } from "../stargate";
import { createStarGateMessage } from "../pbclient";
import { createStarGateMessage } from "../pbclient/pbclient";

import { QueryCertificatesRequest, QueryCertificatesResponse } from "../protobuf/akash/cert/v1beta3/query";
import { CertificateFilter } from "../protobuf/akash/cert/v1beta1/cert";
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export * as wallet from "./wallet";
export * as network from "./network";
export * as rpc from "./rpc";

export * as protoclient from "./pbclient";
export * as protoclient from "./pbclient/pbclient";
export * as sdl from "./sdl";
16 changes: 16 additions & 0 deletions src/pbclient/pbclient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { faker } from "@faker-js/faker";

import { createAminoMessage } from "./pbclient";
import { messages } from "../stargate";

describe("createAminoMessage", () => {
it("creates an amino message", () => {
const message = faker.helpers.arrayElement(Object.values(messages));
const messageBody = "messageBody";
const result = createAminoMessage(message, messageBody);
expect(result).toEqual({
typeUrl: message,
value: messageBody
});
});
});
File renamed without changes.
Empty file added test/setup-unit-tests.ts
Empty file.
Empty file added test/setup.ts
Empty file.
30 changes: 0 additions & 30 deletions tests/test_leases.ts

This file was deleted.

0 comments on commit 787c335

Please sign in to comment.