Pragmatic Testing in AdonisJS with Japa #1.3

Running Tests with the Test Runner

In This Lesson

We'll learn about the various ways we can use the Ace CLI and Japa's test runner to execute all, some, or individual tests.

Created by
@tomgobich
Published

Notes Used to Craft This Lesson

When we ran node ace test, what the Ace CLI did was run Japa's test runner. As the name implies, this is what actually finds and runs our tests.

As the tests are run, it'll then print this output to us on a per-test basis, then give us a summary of all tests at the end, detailing the number that passed and the number that failed.

We can take this a step further, though, and tell the test runner specific things to run.

For example, if we just want to run a specific suite, we can do:

node ace test -- unit
Copied!

We can run specific spec files with:

node ace test --files=tests/unit/assertions.spec.ts
Copied!

And, even specific tests with:

node ace test --tests="my first test"
Copied!

We can even have it rerun tests automatically using the watch flag

node ace test --watch
Copied!

And tests will automatically be re-run as we save our files.

VS Code Japa Extension

If you're working in VS Code, there is also a dedicated Japa Extension that adds several superpowers to your text editor as well! This includes the ability to run tests with convenient buttons and a dedicated test explorer as well.

Join the Discussion 0 comments

Create a free account to join in on the discussion
robot comment bubble

Be the first to comment!