withEnvironment<R> function

R withEnvironment<R>(
  1. Map<String, String> environment,
  2. R body()
)

Runs body with environment in place of the process environment.

Params read their values from the environment, so this sets them for code that body runs, including after an await:

final apiKey = defineSecret('API_KEY');

test('signs requests with the API key', () async {
  await withEnvironment({'API_KEY': 'test-key'}, () async {
    expect(await signRequest(), contains('test-key'));
  });
});

To test functions registered with runFunctionsTest, pass the environment to it instead.

Implementation

R withEnvironment<R>(Map<String, String> environment, R Function() body) =>
    FirebaseEnv.runWithEnvironment(environment, body);