-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move getCanisterActor into separte file to avoid jest
- Loading branch information
Showing
3 changed files
with
44 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { HttpAgent, Identity } from '@dfinity/agent'; | ||
import { ActorSubclass } from '@dfinity/agent'; | ||
import { Agent } from '@dfinity/agent'; | ||
import { join } from 'path'; | ||
|
||
import { getCanisterId } from '../dfx'; | ||
|
||
type GetCanisterActorOptions = { | ||
identity?: Identity; | ||
agent?: Agent; | ||
parentDir?: string; | ||
}; | ||
|
||
export async function getCanisterActor<T>( | ||
canisterName: string, | ||
options: GetCanisterActorOptions = {} | ||
): Promise<ActorSubclass<T>> { | ||
const parentDir = options.parentDir ?? join(process.cwd(), 'test'); | ||
const { createActor } = await import( | ||
join(parentDir, 'dfx_generated', canisterName) | ||
); | ||
|
||
const agent = | ||
options.agent ?? | ||
(await HttpAgent.create({ | ||
host: 'http://127.0.0.1:8000', | ||
shouldFetchRootKey: true | ||
})); | ||
|
||
const actor = createActor(getCanisterId(canisterName), { | ||
agent | ||
}); | ||
|
||
if (typeof canisterName === 'string') { | ||
throw new Error( | ||
'This prop tests uses getCanisterActor and is good to go' | ||
); | ||
} | ||
|
||
return actor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters