-
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.
Merge pull request #1870 from demergent-labs/jest_r
jest examples r
- Loading branch information
Showing
36 changed files
with
39,528 additions
and
9,775 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
'^.+\\.js$': 'ts-jest' | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,75 @@ | ||
import { ActorSubclass } from '@dfinity/agent'; | ||
import { Test } from 'azle/test'; | ||
import { expect, it, please, Test } from 'azle/test'; | ||
import { execSync } from 'child_process'; | ||
|
||
// @ts-ignore this path may not exist when these tests are imported into other test projects | ||
import { _SERVICE } from './dfx_generated/randomness/randomness.did'; | ||
|
||
let globalResults: Set<string> = new Set(); | ||
|
||
export function getTests(randomnessCanister: ActorSubclass<_SERVICE>): Test[] { | ||
return [ | ||
{ | ||
name: 'first round', | ||
test: async () => { | ||
const randomNumberCall_0Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_1Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_2Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_3Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_4Result = | ||
await randomnessCanister.randomNumber(); | ||
export function getTests(randomnessCanister: ActorSubclass<_SERVICE>): Test { | ||
return () => { | ||
it('first round', async () => { | ||
const randomNumberCall_0Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_1Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_2Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_3Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_4Result = | ||
await randomnessCanister.randomNumber(); | ||
|
||
const results = [ | ||
randomNumberCall_0Result.toString(), | ||
randomNumberCall_1Result.toString(), | ||
randomNumberCall_2Result.toString(), | ||
randomNumberCall_3Result.toString(), | ||
randomNumberCall_4Result.toString() | ||
]; | ||
const results = [ | ||
randomNumberCall_0Result.toString(), | ||
randomNumberCall_1Result.toString(), | ||
randomNumberCall_2Result.toString(), | ||
randomNumberCall_3Result.toString(), | ||
randomNumberCall_4Result.toString() | ||
]; | ||
|
||
for (const result of results) { | ||
globalResults.add(result); | ||
} | ||
|
||
return { | ||
Ok: globalResults.size === 5 | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'dfx deploy', | ||
prep: async () => { | ||
execSync('dfx deploy --upgrade-unchanged'); | ||
for (const result of results) { | ||
globalResults.add(result); | ||
} | ||
}, | ||
{ | ||
name: 'getRedeployed', | ||
test: async () => { | ||
const result = await randomnessCanister.getRedeployed(); | ||
return { | ||
Ok: result === true | ||
}; | ||
} | ||
}, | ||
{ | ||
name: 'second round', | ||
test: async () => { | ||
const randomNumberCall_0Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_1Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_2Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_3Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_4Result = | ||
await randomnessCanister.randomNumber(); | ||
|
||
const results = [ | ||
randomNumberCall_0Result.toString(), | ||
randomNumberCall_1Result.toString(), | ||
randomNumberCall_2Result.toString(), | ||
randomNumberCall_3Result.toString(), | ||
randomNumberCall_4Result.toString() | ||
]; | ||
expect(globalResults.size).toBe(5); | ||
}, 20_000); | ||
|
||
please('dfx deploy', async () => { | ||
execSync('dfx deploy --upgrade-unchanged'); | ||
}); | ||
|
||
for (const result of results) { | ||
globalResults.add(result); | ||
} | ||
it('getRedeployed', async () => { | ||
const result = await randomnessCanister.getRedeployed(); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
return { | ||
Ok: globalResults.size === 10 | ||
}; | ||
it('second round', async () => { | ||
const randomNumberCall_0Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_1Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_2Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_3Result = | ||
await randomnessCanister.randomNumber(); | ||
const randomNumberCall_4Result = | ||
await randomnessCanister.randomNumber(); | ||
|
||
const results = [ | ||
randomNumberCall_0Result.toString(), | ||
randomNumberCall_1Result.toString(), | ||
randomNumberCall_2Result.toString(), | ||
randomNumberCall_3Result.toString(), | ||
randomNumberCall_4Result.toString() | ||
]; | ||
|
||
for (const result of results) { | ||
globalResults.add(result); | ||
} | ||
} | ||
]; | ||
|
||
expect(globalResults.size).toBe(10); | ||
}, 20_000); | ||
}; | ||
} |
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,10 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
'^.+\\.js$': 'ts-jest' | ||
}, | ||
transformIgnorePatterns: ['/node_modules/(?!(azle)/)'] // Make sure azle is transformed | ||
}; |
Oops, something went wrong.