Skip to content

Commit

Permalink
chore: use vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
javadkh2 committed Oct 25, 2023
1 parent 1f952bb commit 0d64b08
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 69 deletions.
9 changes: 4 additions & 5 deletions packages/libs/client-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"lint:pkg": "lint-package",
"lint:src": "eslint src --ext .js,.ts",
"pactjs:generate:contract": "pactjs contract-generate --contract coin --api https://api.chainweb.com/chainweb/0.0/mainnet01/chain/1/pact",
"test": "jest",
"test:integration": "jest --silent -c ./jest.integration.config.js"
"test": "vitest",
"test:integration": "vitest run -c ./vitest.integration.config.ts"
},
"dependencies": {
"@kadena/chainweb-node-client": "workspace:*",
Expand All @@ -69,13 +69,12 @@
"@rushstack/eslint-config": "~3.3.0",
"@rushstack/heft": "~0.50.6",
"@types/debug": "~4.1.7",
"@types/jest": "^29.5.3",
"@types/node": "^16.18.48",
"@types/ramda": "^0.29.5",
"eslint": "^8.45.0",
"jest": "^29.7.0",
"prettier": "~3.0.0",
"prettier-plugin-packagejson": "^2.4.5",
"ts-node": "~10.8.2"
"ts-node": "~10.8.2",
"vitest": "^0.34.6"
}
}
3 changes: 2 additions & 1 deletion packages/libs/client-utils/src/core/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const inspect =
return data;
};

export const validateSign = (
// TODO: check if its possible to check the correctness of the signature as well
export const validateSign = (
tx: IUnsignedCommand,
signedTx: ICommand | IUnsignedCommand,
): ICommand => {
Expand Down
43 changes: 43 additions & 0 deletions packages/libs/client-utils/src/core/utils/test/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { inspect, safeSign, validateSign } from '../helpers';

describe('inspect', () => {
it('returns the value passed in', () => {
expect(inspect('tag')(1)).toBe(1);
});
});

describe('validateSign', () => {
it('check if hash of the tx is not changed ', () => {
const unsignedTx = {
cmd: 'cmd',
hash: 'hash',
sigs: [undefined],
};
const signedTx = {
cmd: 'cmd',
hash: 'hash',
sigs: [{ sig: 'sig' }],
};
expect(validateSign(unsignedTx, signedTx)).toStrictEqual(signedTx);
});
});

describe('safeSign', () => {
it('add signature to the tx by using sign function', async () => {
const signedTx = {
cmd: 'cmd',
hash: 'hash',
sigs: [{ sig: 'sig' }],
};
const sign = vitest.fn().mockResolvedValue(signedTx);
const signFn = safeSign(sign);

const result = await signFn({
cmd: 'cmd',
hash: 'hash',
sigs: [undefined],
});

expect(result).toStrictEqual(signedTx);
});
});
2 changes: 1 addition & 1 deletion packages/libs/client-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./node_modules/@kadena-dev/heft-rig/tsconfig-base.json",
"compilerOptions": {
"types": [".kadena/pactjs-generated", "jest", "node"],
"types": [".kadena/pactjs-generated", "vitest/globals", "node"],
"lib": ["es2019", "DOM"]
}
}
10 changes: 10 additions & 0 deletions packages/libs/client-utils/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['src/**/*.test.ts'],
exclude: ['src/**/*.int.test.ts'],
globals: true,
threads: false, // To prevent error in tests using jsdom environment: Module did not self-register: canvas.node
},
});
9 changes: 9 additions & 0 deletions packages/libs/client-utils/vitest.integration.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['src/**/*.int.test.ts'],
globals: true,
testTimeout: 60000,
},
});
Loading

0 comments on commit 0d64b08

Please sign in to comment.