Repository navigation
modules_testing
A testing suite that proposes some tools that help you organize and easily escalate your own tests. ** Attention! ** All of tests in the same context are ran before tests on the following context.
Assertions should run inside of a test scope, see a simple example:
import test from "@acai/testing";
test("Test that 2 + 2 is equal 4", expect => {
expect(2 + 2).toEqual(4);
});
// You can run all the tests recorded using test.run, this will print
// in the console
test.run();You can automatically search for tests in your current project using await test.find(/regex/), you can pass a regex to match a test file.
You can group tests to easily distinguish between them without writing multiple files.
import test from "@acai/tester";
test.group("Group description", () => {
/*Your tests here*/
});You can filter tests to be ran with except/only, working opposite of one another. They stack, so if you have two only tests, those two will run.
test.only("test description", () => {
// Your test here
});You can also pass a second parameter to true, to force running all tests, ignoring the except/only.
You can tag your tests/groups, to filter them when running your tests. For example:
test("test description", () => {
// Your test here
}).tag(["tag1", "tag2"]);
test("other test description", () => {
// Your test here
}).tag(["tag3"]);
// Will only run tests marked with the tag2 tag
await test.run(["tag2"]);Most of the times you want to debug a value that cannot be accessed otherwise, and simply console log would mess the CLI up. So we provide an organized and (almost) serializable way of debugging your code. There are two ways of doing so:
// you can use it as an assertion
expect(value).cache("optional title for organization");
// or simply call it inside a test context (means it must run when calling a test itself)
test.cache(value);
// or
test.cache("title", value);Makes an exact, and deeply compares objects and arrays.
Makes an exact match and rejects if are equals, deeply compares objects and arrays.
Returns the typeof of the expect and compare it.
Checks if value is not undefined.
Checks if value is defined
Checks value to be null
Checks value to not be null
Expects an callable function that will be run (can be async), and it expects it to throw.
Check if expect value contains parts of the assertion. This will act differently depending on what it receives:
- object: will check if contain array of keys
- array: will check if it contain values
- string: will check if it contains text
Not actually an assertion, but allows you to verify values after the tests.
For your convenience, we recommend you setting up a test.ts or test.js in your project root and placing the following:
// run from command line
async function main () {
// with this you can change the test regex find from cli
const path = process.argv.includes("--path") && process.argv[process.argv.indexOf("--path") + 1];
// you can filter tags through the cli
const tags = `${process.argv.includes("--tags") && process.argv[process.argv.indexOf("--tags") + 1] || ""}`.split(",").filter(i => i);
// force run all tests
const all = process.argv.includes("--all");
// skip printing
const print = !process.argv.includes("--no-print");
await test.find(path || "./**/*.{test,tests}.{js,ts}");
await test.runAndPrint({
tags : tags,
forceAll: all,
spinner : print,
});
}
main();And adding to your package.json in the scripts category: "test": "ts-node ./test.ts", you can also use any runtime typescript compiler or simply run with node in case you don't use typescript. Now you have access to run your tests through the CLI.
Do you have a question? Please open an issue on our main repo.
Copyright (c) 2021 The Nuinalp Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright (c) 2021 APO Softworks. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.