- create
jest.config.js
in project root - create
test-env/
dir in project root - copy / clone
setup.js
,setup-test-accounts.js
and.test.env
intotest-env/
- run jest tests
First time the global setup is run it will generate:
process.env.TEST_ACCOUNTS_COUNT
accounts- write them to
test-env/accounts.json
for faster startup in the future
If you need more/less accounts just delete test-env/accounts.json
and change TEST_ACCOUNTS_COUNT
value then run your tests again (to repeat the above process for the new count).
Test accounts will be accessible in jest tests by
assuming prefix is
TEST_ACCOUNT_ADDRESS_
process.env.TEST_ACCOUNT_ADDRESS_0 // 0, 1, 2...up to TEST_ACCOUNTS_COUNT - 1
generic
// accountNumber = 0, 1, 2...up to TEST_ACCOUNTS_COUNT - 1
process.env[`${process.env.TEST_ACCOUNT_ENV_PREFIX}${accountNumber}`];
if you want to have a clean slate when running tests you can install docker-compose (NPM)
npm i -D docker-compose
and copy/clone the file test-env/reset-sandbox.js
make sure to update the path to your sandbox dir! the file currently assumes it is in projectRoot/algorand-sandbox
then update your test-env/setup.js
file to utilize it
require("dotenv").config({ path: __dirname + "/.test.env" });
const resetSandbox = require("./reset-sandbox");
const setupTestAccounts = require("./setup-test-accounts");
module.exports = async () => {
await resetSandbox();
await setupTestAccounts();
};