-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for configuring k6-jslib-testing via the environment (#9)
Introduces support for the `K6_TESTING_COLORIZE`, `K6_TESTING_DISPLAY`, `K6_TESTING_TIMEOUT` and `K6_TESTING_INTERVAL` environment variables to configure the expect keyword accordingly. Precedence, from higher to lower is env > js `configure` call > defaults. See README for documentation.
- Loading branch information
Showing
7 changed files
with
296 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { assertEquals } from "jsr:@std/assert"; | ||
|
||
import { ConfigLoader } from "./config.ts"; | ||
import { withEnv } from "./test_helpers.ts"; | ||
|
||
Deno.test("ConfigLoader.load", async (t) => { | ||
await t.step("colorize defaults to true", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.colorize, true); | ||
}); | ||
|
||
await t.step( | ||
"colorize can be enforced by setting the K6_TESTING_COLORIZE environment variable to true", | ||
() => { | ||
withEnv("K6_TESTING_COLORIZE", "true", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.colorize, true); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"colorize can be enforced by setting the K6_TESTING_COLORIZE environment variable", | ||
() => { | ||
withEnv("K6_TESTING_COLORIZE", "", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.colorize, true); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"colorize can be disabled by setting the K6_TESTING_COLORIZE environment variable to false", | ||
() => { | ||
withEnv("K6_TESTING_COLORIZE", "false", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.colorize, false); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step( | ||
"colorize is enabled if K6_TESTING_COLORIZE is set to any other value than false", | ||
() => { | ||
withEnv("K6_TESTING_COLORIZE", "foo", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.colorize, true); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step("display defaults to pretty", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.display, "pretty"); | ||
}); | ||
|
||
await t.step( | ||
"display can be set to inline by setting the K6_TESTING_DISPLAY environment variable to inline", | ||
() => { | ||
withEnv("K6_TESTING_DISPLAY", "inline", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.display, "inline"); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step("timeout defaults to 5000", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.timeout, 5000); | ||
}); | ||
|
||
await t.step( | ||
"timeout can be set by setting the K6_TESTING_TIMEOUT environment variable", | ||
() => { | ||
withEnv("K6_TESTING_TIMEOUT", "10000", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.timeout, 10000); | ||
}); | ||
}, | ||
); | ||
|
||
await t.step("interval defaults to 100", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.interval, 100); | ||
}); | ||
|
||
await t.step( | ||
"interval can be set by setting the K6_TESTING_INTERVAL environment variable", | ||
() => { | ||
withEnv("K6_TESTING_INTERVAL", "200", () => { | ||
const config = ConfigLoader.load(); | ||
assertEquals(config.interval, 200); | ||
}); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.