Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update second half of examples that start with "c" to use jest #1830

Merged
merged 7 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/complex_init/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
}
};
9,617 changes: 7,848 additions & 1,769 deletions examples/complex_init/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/complex_init/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"scripts": {
"pretest": "ts-node --transpile-only --ignore=false test/pretest.ts",
"test": "ts-node --transpile-only --ignore=false test/test.ts"
"test": "jest"
},
"dependencies": {
"azle": "0.22.0"
},
"devDependencies": {
"@dfinity/agent": "^0.19.2",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
}
Expand Down
13 changes: 7 additions & 6 deletions examples/complex_init/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { describe } from '@jest/globals';
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';
import { runTests } from 'azle/test/jest';

import { createActor as createComplexActor } from '../test/dfx_generated/complex_init';
// @ts-ignore
import { createActor as createRecActor } from '../test/dfx_generated/rec_init';
import { get_rec_tests, get_tests } from './tests';
import { getRecTests, getTests } from './tests';

const complexInitCanister = createComplexActor(getCanisterId('complex_init'), {
agentOptions: {
Expand All @@ -18,7 +19,7 @@ const recInitCanister = createRecActor(getCanisterId('rec_init'), {
}
});

runTests([
...get_tests(complexInitCanister),
...get_rec_tests(recInitCanister)
]);
runTests(() => {
describe('complex init canister', getTests(complexInitCanister));
describe('rec init canister', getRecTests(recInitCanister));
});
44 changes: 17 additions & 27 deletions examples/complex_init/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';
import { expect, it, Test } from 'azle/test/jest';

import { _SERVICE as _COMPLEX_SERVICE } from './dfx_generated/complex_init/complex_init.did';
// @ts-ignore
import { _SERVICE as _REC_SERVICE } from './dfx_generated/rec_init/rec_init.did';

export function get_tests(
export function getTests(
complex_init_canister: ActorSubclass<_COMPLEX_SERVICE>
): Test[] {
return [
{
name: 'get_user',
test: async () => {
const result = await complex_init_canister.greetUser();
): Test {
return () => {
it('accepts a simple type as an argument for the init method', async () => {
const result = await complex_init_canister.greetUser();

return {
Ok: result === 'Oh hello there user 1'
};
}
}
];
expect(result).toBe('Oh hello there user 1');
});
};
}

export function get_rec_tests(
export function getRecTests(
rec_init_canister: ActorSubclass<_REC_SERVICE>
): Test[] {
return [
{
name: 'count branches',
test: async () => {
const result = await rec_init_canister.countBranches();
): Test {
return () => {
it('accepts a recursive structure as an argument for the init method', async () => {
const result = await rec_init_canister.countBranches();

return {
Ok: result === 1n
};
}
}
];
expect(result).toBe(1n);
});
};
}
9 changes: 9 additions & 0 deletions examples/complex_types/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest'
}
};
Loading
Loading