-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: Renamed algorandFixture
's beforeEach
to newScope
#362
Open
robdmoore
wants to merge
1
commit into
main
Choose a base branch
from
fixture-newscope
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||||
---|---|---|---|---|---|---|
|
@@ -24,15 +24,37 @@ import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' | |||||
|
||||||
### Using with Jest | ||||||
|
||||||
To integrate with [Jest](https://jestjs.io/) you need to pass the `fixture.beforeEach` method into Jest's `beforeEach` method and then within each test you can access `fixture.context` to access per-test isolated fixture values. | ||||||
To integrate with [Jest](https://jestjs.io/) you need to pass the `fixture.newScope` method into Jest's `beforeEach` method (for per test isolation) or `beforeAll` method (for test suite isolation) and then within each test you can access `fixture.context` to access the isolated fixture values. | ||||||
|
||||||
#### Per-test isolation | ||||||
|
||||||
```typescript | ||||||
import { describe, test, beforeEach } from '@jest/globals' | ||||||
import { algorandFixture } from './testing' | ||||||
|
||||||
describe('MY MODULE', () => { | ||||||
const fixture = algorandFixture() | ||||||
beforeEach(fixture.beforeEach, 10_000) | ||||||
beforeEach(fixture.newScope, 10_000) // Add a 10s timeout to cater for occasionally slow LocalNet calls | ||||||
|
||||||
test('MY TEST', async () => { | ||||||
const { algorand, testAccount /* ... */ } = fixture.context | ||||||
|
||||||
// Test stuff! | ||||||
}) | ||||||
}) | ||||||
``` | ||||||
|
||||||
Occasionally there may be a delay when first running the fixture setup so we add a 10s timeout to avoid intermittent test failures (`10_000`). | ||||||
|
||||||
#### Test suite isolation | ||||||
|
||||||
```typescript | ||||||
import { describe, test, beforeAll } from '@jest/globals' | ||||||
import { algorandFixture } from './testing' | ||||||
|
||||||
describe('MY MODULE', () => { | ||||||
const fixture = algorandFixture() | ||||||
beforeAll(fixture.newScope, 10_000) // Add a 10s timeout to cater for occasionally slow LocalNet calls | ||||||
|
||||||
test('MY TEST', async () => { | ||||||
const { algorand, testAccount /* ... */ } = fixture.context | ||||||
|
@@ -46,15 +68,37 @@ Occasionally there may be a delay when first running the fixture setup so we add | |||||
|
||||||
### Using with vitest | ||||||
|
||||||
To integrate with [vitest](https://vitest.dev/) you need to pass the `fixture.beforeEach` method into vitest's `beforeEach` method and then within each test you can access `fixture.context` to access per-test isolated fixture values. | ||||||
To integrate with [vitest](https://vitest.dev/) you need to pass the `fixture.beforeEach` method into vitest's `beforeEach` method (for per test isolation) or `beforeAll` method (for test suite isolation) and then within each test you can access `fixture.context` to access the isolated fixture values. | ||||||
|
||||||
#### Per-test isolation | ||||||
|
||||||
```typescript | ||||||
import { describe, test, beforeEach } from 'vitest' | ||||||
import { algorandFixture } from './testing' | ||||||
|
||||||
describe('MY MODULE', () => { | ||||||
const fixture = algorandFixture() | ||||||
beforeEach(fixture.beforeEach, 10_000) | ||||||
beforeEach(fixture.newScope, 10_000) // Add a 10s timeout to cater for occasionally slow LocalNet calls | ||||||
|
||||||
test('MY TEST', async () => { | ||||||
const { algorand, testAccount /* ... */ } = fixture.context | ||||||
|
||||||
// Test stuff! | ||||||
}) | ||||||
}) | ||||||
``` | ||||||
|
||||||
Occasionally there may be a delay when first running the fixture setup so we add a 10s timeout to avoid intermittent test failures (`10_000`). | ||||||
|
||||||
#### Test suite isolation | ||||||
|
||||||
```typescript | ||||||
import { describe, test, beforeAll } from 'vitest' | ||||||
import { algorandFixture } from './testing' | ||||||
|
||||||
describe('MY MODULE', () => { | ||||||
const fixture = algorandFixture() | ||||||
beforeAll(fixture.newScope, 10_000) // Add a 10s timeout to cater for occasionally slow LocalNet calls | ||||||
|
||||||
test('MY TEST', async () => { | ||||||
const { algorand, testAccount /* ... */ } = fixture.context | ||||||
|
@@ -64,6 +108,8 @@ describe('MY MODULE', () => { | |||||
}) | ||||||
``` | ||||||
|
||||||
Occasionally there may be a delay when first running the fixture setup so we add a 10s timeout to avoid intermittent test failures (`10_000`). | ||||||
|
||||||
### Fixture configuration | ||||||
|
||||||
When calling `algorandFixture()` you can optionally pass in some fixture configuration, with any of these properties (all optional): | ||||||
|
@@ -72,6 +118,7 @@ When calling `algorandFixture()` you can optionally pass in some fixture configu | |||||
- `indexer?: Indexer` - An optional indexer client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet | ||||||
- `kmd?: Kmd` - An optional kmd client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet | ||||||
- `testAccountFunding?: AlgoAmount` - The [amount](./amount.md) of funds to allocate to the default testing account, if not specified then it will get `10` ALGO | ||||||
- `accountGetter?: (algod: Algodv2, kmd?: Kmd) => Promise<Account>` - Optional override for how to get an account; this allows you to retrieve test accounts from a known or cached list of accounts. | ||||||
|
||||||
### Using the fixture context | ||||||
|
||||||
|
@@ -84,7 +131,7 @@ The `fixture.context` property is of type [`AlgorandTestAutomationContext`](../c | |||||
- `transactionLogger: TransactionLogger` - Transaction logger that will log transaction IDs for all transactions issued by `algod` | ||||||
- `testAccount: Account` - Funded test account that is ephemerally created for each test | ||||||
- `generateAccount: (params: GetTestAccountParams) => Promise<Account>` - Generate and fund an additional ephemerally created account | ||||||
- `waitForIndexer: () => Promise<void>` - Wait for the indexer to catch up with all transactions logged by transactionLogger | ||||||
- `waitForIndexer()` - Waits for indexer to catch up with that latest transaction that has been captured by the `transactionLogger` in the Algorand fixture | ||||||
- `waitForIndexerTransaction: (transactionId: string) => Promise<TransactionLookupResult>` - Wait for the indexer to catch up with the given transaction ID | ||||||
|
||||||
## Log capture fixture | ||||||
|
@@ -170,7 +217,7 @@ This means it's easy to create tests that are flaky and have intermittent test f | |||||
The testing capability provides mechanisms for waiting for indexer to catch up, namely: | ||||||
|
||||||
- `algotesting.runWhenIndexerCaughtUp(run: () => Promise<T>)` - Executes the given action every 200ms up to 20 times until there is no longer an error with a `status` property with `404` and then returns the result of the action; this will work for any call that calls indexer APIs expecting to return a single record | ||||||
- `algorandFixture.waitForIndexer()` - Waits for indexer to catch up with all transactions that have been captured by the `transactionLogger` in the Algorand fixture | ||||||
- `algorandFixture.waitForIndexer()` - Waits for indexer to catch up with that latest transaction that has been captured by the `transactionLogger` in the Algorand fixture | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `algorandFixture.waitForIndexerTransaction(transactionId)` - Waits for indexer to catch up with the single transaction of the given ID | ||||||
|
||||||
## Logging transactions | ||||||
|
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.