Skip to main content

Emulator

Flow Javascript Testing Framework exposes emulator singleton allowing you to run and stop emulator instance programmatically. There are two methods available on it.

emulator.start(options)

Starts emulator on random available port, unless overriden in options. Returns Promise.

Arguments

NameTypeOptionalDescription
optionsEmulatorOptionsan object containing options for starting the emulator

EmulatorOptions

KeyTypeOptionalDescription
loggingbooleanwhether log messages from emulator shall be added to the output (default: false)
flagsstringcustom command-line flags to supply to the emulator (default: "")
adminPortnumberoverride the port which the emulator will run the admin server on (default: auto)
restPortnumberoverride the port which the emulator will run the REST server on (default: auto)
grpcPortnumberoverride the port which the emulator will run the GRPC server on (default: auto)
debuggerPortnumberoverride the port which the emulator will run the debug server on (default: auto)

Returns

TypeDescription
PromisePromise, which resolves to true if emulator started successfully

Usage


_13
import {emulator, init} from "@onflow/flow-js-testing"
_13
_13
describe("test setup", () => {
_13
// Instantiate emulator and path to Cadence files
_13
beforeEach(async () => {
_13
const basePath = path.resolve(__dirname, "../cadence")
_13
_13
await init(basePath)
_13
_13
// Start emulator instance on auto-selected available ports
_13
await emulator.start()
_13
})
_13
})

emulator.stop()

Stops emulator instance. Returns Promise.

Arguments

This method does not expect any arguments.

Usage


_16
import {emulator, init} from "@onflow/flow-js-testing"
_16
_16
describe("test setup", () => {
_16
// Instantiate emulator and path to Cadence files
_16
beforeEach(async () => {
_16
const basePath = path.resolve(__dirname, "../cadence")
_16
_16
await init(basePath)
_16
await emulator.start()
_16
})
_16
_16
// Stop emulator, so it could be restarted
_16
afterEach(async () => {
_16
await emulator.stop()
_16
})
_16
})

emulator.setLogging(newState)

Set logging flag on emulator, allowing to temporally enable/disable logging.

Arguments

NameTypeDescription
newStatebooleanEnable/disable logging

Usage


_26
import {emulator, init} from "@onflow/flow-js-testing"
_26
_26
describe("test setup", () => {
_26
// Instantiate emulator and path to Cadence files
_26
beforeEach(async () => {
_26
const basePath = path.resolve(__dirname, "../cadence")
_26
_26
await init(basePath)
_26
await emulator.start()
_26
})
_26
_26
// Stop emulator, so it could be restarted
_26
afterEach(async () => {
_26
await emulator.stop()
_26
})
_26
_26
test("basic test", async () => {
_26
// Turn on logging from begining
_26
emulator.setLogging(true)
_26
// some asserts and interactions
_26
_26
// Turn off logging for later calls
_26
emulator.setLogging(false)
_26
// more asserts and interactions here
_26
})
_26
})