2 min read
How to start a new instance of emulator
Flow Javascript Testing Framework exposes emulator
singleton allowing you to run and stop emulator instance
programmatically. There are two methods available on it.
Starts emulator on random available port, unless overriden in options. Returns Promise.
Name | Type | Optional | Description |
---|---|---|---|
options | EmulatorOptions | ✅ | an object containing options for starting the emulator |
Key | Type | Optional | Description |
---|---|---|---|
logging | boolean | ✅ | whether log messages from emulator shall be added to the output (default: false) |
flags | string | ✅ | custom command-line flags to supply to the emulator (default: "") |
adminPort | number | ✅ | override the port which the emulator will run the admin server on (default: auto) |
restPort | number | ✅ | override the port which the emulator will run the REST server on (default: auto) |
grpcPort | number | ✅ | override the port which the emulator will run the GRPC server on (default: auto) |
Type | Description |
---|---|
Promise | Promise, which resolves to true if emulator started successfully |
1import {emulator, init} from "@onflow/flow-js-testing"23describe("test setup", () => {4// Instantiate emulator and path to Cadence files5beforeEach(async () => {6const basePath = path.resolve(__dirname, "../cadence")78await init(basePath)910// Start emulator instance on auto-selected available ports11await emulator.start()12})13})
Stops emulator instance. Returns Promise.
This method does not expect any arguments.
1import {emulator, init} from "@onflow/flow-js-testing"23describe("test setup", () => {4// Instantiate emulator and path to Cadence files5beforeEach(async () => {6const basePath = path.resolve(__dirname, "../cadence")78await init(basePath)9await emulator.start()10})1112// Stop emulator, so it could be restarted13afterEach(async () => {14await emulator.stop()15})16})
Set logging flag on emulator, allowing to temporally enable/disable logging.
Name | Type | Description |
---|---|---|
newState | boolean | Enable/disable logging |
1import {emulator, init} from "@onflow/flow-js-testing"23describe("test setup", () => {4// Instantiate emulator and path to Cadence files5beforeEach(async () => {6const basePath = path.resolve(__dirname, "../cadence")78await init(basePath)9await emulator.start()10})1112// Stop emulator, so it could be restarted13afterEach(async () => {14await emulator.stop()15})1617test("basic test", async () => {18// Turn on logging from begining19emulator.setLogging(true)20// some asserts and interactions2122// Turn off logging for later calls23emulator.setLogging(false)24// more asserts and interactions here25})26})