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
| Name | Type | Optional | Description | 
|---|---|---|---|
| options | EmulatorOptions | ✅ | an object containing options for starting the emulator | 
EmulatorOptions
| 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) | 
Returns
| Type | Description | 
|---|---|
| Promise | Promise, which resolves to true if emulator started successfully | 
Usage
_13import {emulator, init} from "@onflow/flow-js-testing"_13_13describe("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
_16import {emulator, init} from "@onflow/flow-js-testing"_16_16describe("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
| Name | Type | Description | 
|---|---|---|
| newState | boolean | Enable/disable logging | 
Usage
_26import {emulator, init} from "@onflow/flow-js-testing"_26_26describe("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})