Skip to content

Commit 71d109b

Browse files
committed
feat: add logging support
1 parent cfe0927 commit 71d109b

File tree

14 files changed

+287
-67
lines changed

14 files changed

+287
-67
lines changed

docs/docs/guides/02-using-jest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const config: Config = {
8585
testEnvironment: 'node',
8686
globalSetup: '<rootDir>/global-setup.ts',
8787
globalTeardown: '<rootDir>/global-teardown.ts',
88+
testTimeout: 30_000,
8889
};
8990

9091
export default config;

docs/docs/guides/03-using-vitest.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default defineConfig({
108108
test: {
109109
root: 'examples/counter/tests',
110110
globalSetup: './global-setup.ts',
111+
testTimeout: 30_000,
111112
},
112113
});
113114
```

examples/clock/src/main.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Time "mo:base/Time";
22
import { now } = "mo:base/Time";
33
import { setTimer; recurringTimer } = "mo:base/Timer";
4+
import Debug "mo:base/Debug";
45

56
actor Clock {
67
private type Time = Time.Time;
78
private stable var time : Time = 0;
89

910
public query func get() : async Time {
11+
Debug.print("Getting current time...");
1012
return time / 1_000_000;
1113
};
1214

examples/clock/tests/global-setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { PocketIcServer } from '@hadronous/pic';
22

33
module.exports = async function (): Promise<void> {
4-
const pic = await PocketIcServer.start();
4+
const pic = await PocketIcServer.start({
5+
pipeStdout: false,
6+
pipeStderr: true,
7+
});
58
const url = pic.getUrl();
69

710
process.env.PIC_URL = url;

examples/clock/tests/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config: Config = {
66
testEnvironment: 'node',
77
globalSetup: '<rootDir>/global-setup.ts',
88
globalTeardown: '<rootDir>/global-teardown.ts',
9+
testTimeout: 30_000,
910
};
1011

1112
export default config;

examples/counter/tests/vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default defineConfig({
44
test: {
55
root: 'examples/counter/tests',
66
globalSetup: './global-setup.ts',
7+
testTimeout: 30_000,
78
},
89
});

examples/multicanister/tests/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config: Config = {
66
testEnvironment: 'node',
77
globalSetup: '<rootDir>/global-setup.ts',
88
globalTeardown: '<rootDir>/global-teardown.ts',
9+
testTimeout: 30_000,
910
};
1011

1112
export default config;

examples/nns_proxy/tests/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config: Config = {
66
testEnvironment: 'node',
77
globalSetup: '<rootDir>/global-setup.ts',
88
globalTeardown: '<rootDir>/global-teardown.ts',
9+
testTimeout: 30_000,
910
};
1011

1112
export default config;

examples/todo/tests/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const config: Config = {
66
testEnvironment: 'node',
77
globalSetup: '<rootDir>/global-setup.ts',
88
globalTeardown: '<rootDir>/global-teardown.ts',
9+
testTimeout: 30_000,
910
};
1011

1112
export default config;

packages/pic/src/identity.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ import { Ed25519KeyIdentity } from '@dfinity/identity';
2222
*
2323
* @example
2424
* ```ts
25-
* import { PocketIc, createIdentity } from '@hadronous/pic';
25+
* import { PocketIc, PocketIcServer, createIdentity } from '@hadronous/pic';
2626
* import { AnonymousIdentity } from '@dfinity/agent';
2727
* import { _SERVICE, idlFactory } from '../declarations';
2828
*
2929
* const wasmPath = resolve('..', '..', 'canister.wasm');
3030
*
31-
* const pic = await PocketIc.create();
31+
* const picServer = await PocketIcServer.create();
32+
* const pic = await PocketIc.create(picServer.getUrl());
3233
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
3334
* const { actor } = fixture;
3435
*
3536
* const bob = createIdentity('SuperSecretSeedPhraseForBob');
3637
* actor.setIdentity(bob);
38+
*
39+
* await pic.tearDown();
40+
* await picServer.stop();
3741
* ```
3842
*/
3943
export function createIdentity(seedPhrase: string): Identity {
@@ -67,18 +71,22 @@ function generateMnemonic(): string {
6771
*
6872
* @example
6973
* ```ts
70-
* import { PocketIc, generateRandomIdentity } from '@hadronous/pic';
74+
* import { PocketIc, PocketIcServer, generateRandomIdentity } from '@hadronous/pic';
7175
* import { AnonymousIdentity } from '@dfinity/agent';
7276
* import { _SERVICE, idlFactory } from '../declarations';
7377
*
7478
* const wasmPath = resolve('..', '..', 'canister.wasm');
7579
*
76-
* const pic = await PocketIc.create();
80+
* const picServer = await PocketIcServer.create();
81+
* const pic = await PocketIc.create(picServer.getUrl());
7782
* const fixture = await pic.setupCanister<_SERVICE>(idlFactory, wasmPath);
7883
* const { actor } = fixture;
7984
*
8085
* const bob = generateRandomIdentity();
8186
* actor.setIdentity(bob);
87+
*
88+
* await pic.tearDown();
89+
* await picServer.stop();
8290
* ```
8391
*/
8492
export function generateRandomIdentity(): Identity {

0 commit comments

Comments
 (0)