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 first half of examples that start with "c" to use jest #1829

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/call_raw/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,615 changes: 7,847 additions & 1,768 deletions examples/call_raw/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion examples/call_raw/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
6 changes: 3 additions & 3 deletions examples/call_raw/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';
import { runTests } from 'azle/test/jest';

import { createActor } from '../test/dfx_generated/call_raw';
import { get_tests } from './tests';
import { getTests } from './tests';

const callRawCanister = createActor(getCanisterId('call_raw'), {
agentOptions: {
host: 'http://127.0.0.1:8000'
}
});

runTests(get_tests(callRawCanister));
runTests(getTests(callRawCanister));
136 changes: 55 additions & 81 deletions examples/call_raw/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,98 +1,72 @@
import { ActorSubclass } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { ok, Test } from 'azle/test';
import { expect, it, Test } from 'azle/test/jest';

import { _SERVICE } from './dfx_generated/call_raw/call_raw.did';

export function get_tests(call_raw_canister: ActorSubclass<_SERVICE>): Test[] {
return [
{
name: 'execute_call_raw raw_rand',
test: async () => {
const result = await call_raw_canister.executeCallRaw(
Principal.fromText('aaaaa-aa'),
'raw_rand',
'()',
0n
);
export function getTests(call_raw_canister: ActorSubclass<_SERVICE>): Test {
return () => {
it('calls raw rand via execute_call_raw', async () => {
const result = await call_raw_canister.executeCallRaw(
Principal.fromText('aaaaa-aa'),
'raw_rand',
'()',
0n
);

if (!ok(result)) {
return {
Err: result.Err
};
}

return {
Ok: result.Ok.includes('blob')
};
if ('Err' in result) {
throw new Error(result.Err);
}
},
{
name: 'execute_call_raw create_canister',
test: async () => {
const result = await call_raw_canister.executeCallRaw(
Principal.fromText('aaaaa-aa'),
'create_canister',
'(record { settings = null })',
100_000_000_000n
);

if (!ok(result)) {
return {
Err: result.Err
};
}
expect(result).toHaveProperty('Ok');
expect(result.Ok).toMatch('blob');
});

it('calls create_canister via execute_call_raw', async () => {
const result = await call_raw_canister.executeCallRaw(
Principal.fromText('aaaaa-aa'),
'create_canister',
'(record { settings = null })',
100_000_000_000n
);

return {
Ok:
result.Ok.includes('record') &&
result.Ok.includes('principal')
};
if ('Err' in result) {
throw new Error(result.Err);
}
},
{
name: 'execute_call_raw128 raw_rand',
test: async () => {
const result = await call_raw_canister.executeCallRaw128(
Principal.fromText('aaaaa-aa'),
'raw_rand',
'()',
0n
);

if (!ok(result)) {
return {
Err: result.Err
};
}
expect(result.Ok).toMatch('record');
expect(result.Ok).toMatch('principal');
});

it('calls raw_rand via execute_call_raw128', async () => {
const result = await call_raw_canister.executeCallRaw128(
Principal.fromText('aaaaa-aa'),
'raw_rand',
'()',
0n
);

return {
Ok: result.Ok.includes('blob')
};
if ('Err' in result) {
throw new Error(result.Err);
}
},
{
name: 'execute_call_raw128 create_canister',
test: async () => {
const result = await call_raw_canister.executeCallRaw128(
Principal.fromText('aaaaa-aa'),
'create_canister',
'(record { settings = null })',
100_000_000_000n
);

if (!ok(result)) {
return {
Err: result.Err
};
}
expect(result.Ok).toMatch('blob');
});

return {
Ok:
result.Ok.includes('record') &&
result.Ok.includes('principal')
};
it('calls create_canister via execute_call_raw128', async () => {
const result = await call_raw_canister.executeCallRaw128(
Principal.fromText('aaaaa-aa'),
'create_canister',
'(record { settings = null })',
100_000_000_000n
);

if ('Err' in result) {
throw new Error(result.Err);
}
}
];

expect(result.Ok).toMatch('record');
expect(result.Ok).toMatch('principal');
});
};
}
9 changes: 9 additions & 0 deletions examples/candid_encoding/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