Skip to content

Releases: japa/core

Add support for defining cleanup hooks within the test callback

12 Sep 08:32
Compare
Choose a tag to compare

In the following code example, if the select query raises an exception, the cleanup code connection.destory will never be called. Therefore, you will have an open connection even
after the test is over (aka failed).

test('find all users', async () => {
  // Setup
  const connection = await makeConnection()

  // Test logic
  await connection.select('*').from('users')

  // Cleanup
  await connection.destroy()
})

In order to counter situations like this, you can wrap the select query inside try/finally block and close the connection inside the finally block.

try {
  await connection.select('*').from('users')
} finally {
  await connection.destroy()
}

I usually avoid try/catch (whenever possible) because of the visual noise it creates. Therefore, this releases exposes a cleanup function that you can use to define the cleanup handlers that always run regardless of the test passes or fails.

test('find all users', async ({ cleanup }) => {
  const connection = await makeConnection()

  /**
   * Runs after the test is completed
   */
  cleanup(() => connection.destroy())

  await connection.select('*').from('users')
})
  • feat: add support for defining cleanup hooks from within the test 2a8aa8f

Full Changelog: v7.1.0...v7.2.0

Allow reporters to have names

12 Sep 05:20
Compare
Choose a tag to compare

With this release, one can register a reporter with a name and a handler function as follows.

runner.registerReporter({
  name: 'spec',
  handler: () => {
  }
})
  • feat: ReporterContract can now be named (#65) 0cb9899

What's Changed

New Contributors

Full Changelog: v7.0.1...v7.1.0

Update dependencies

07 Sep 10:00
Compare
Choose a tag to compare
  • chore: update dependencies f4cfde2
  • docs(README): remove v4 upgrade note b39378e
  • docs(README): update japa.dev link 01b5efc
  • chore: remove github health files in favor of central .github repo eb56a41

Full Changelog: v7.0.0...v7.0.1

Drill down layers when applying filters

02 Sep 19:03
Compare
Choose a tag to compare

Breaking change

After this release, creating a new instance of suite will need a refiner instance. It does not impact the public API of @japa/runner. But direct consumers of @japa/core are impacted.

Improvements to the filters

Before this release, a group will run its hooks even when all the tests inside that group were filtered out (aka skipped). Similarly, a suite will run its hooks even when all the groups and its tests were filtered out.

Ideally, this does not impact the correctness of the tests. But still, you end up paying cost for running those hooks.

After this release, the upper layers have knowledge about their children and skip running themselves when children have been skipped/filtered out. For example:

  • A suite will not run, if all the groups/tests within that group were filtered.
  • A group will not run, if all the tests within that group were filtered.

Commits

  • fix: build issues 1ebee5d
  • refactor: refiner to drill down layers when filtering groups 29a5494

v6.0.7...v7.0.0

Full Changelog: v6.0.7...v7.0.0

v6.0.7

02 Sep 07:32
Compare
Choose a tag to compare

Fix to not run lone tests when group filter is applied

This release contains a bug fix for not running lone tests when a group filter is applied. Let's say you have defined the following tests, where two of the tests are inside their respective groups and the third one is a lone test (without a group)

import { test } from '@japa/runner'

test.group('GroupOne', (group) => {
  test('My Test', ({ assert }) => {
    assert.isTrue(true)
  })
})

test.group('GroupTwo', (group) => {
  test('My Test', ({ assert }) => {
    assert.isTrue(true)
  })
})

test('Root', () => console.log('hey'))

Now when you run tests with the following filters, you would expect only the tests within the GroupOne should run.

node bin/test.js --groups "GroupOne"

However, before this release, the lone test was also running.

Reference literal values in dynamic test titles

If you have a test using dataset with literal values, now you can reference the literal value using the special $self keyboard. For example:

test('validate {$self}')
.with([
  'some+user@gmail.com',
  'some.user@gmail.com',
  'email@123.123.123.123'
])
.run({ assert }, email) => {
  assert.isTrue(validateEmail(email))
})

Earlier, there was no way to reference literal values from the dataset and that forces you to always use objects inside the dataset array.

Commits

  • feat: allow referencing literal values in dynamic test title 9fd89cb
  • fix: types breaking changes after moving for TypeScript 4.8 f23c4c4
  • test: fix breaking test after fixing #63 86beab3
  • docs(README): reference sponsors image from central CDN 6cb4278
  • fix: do not run lone tests when group filter is applied 4429e20
  • chore: update dependencies 6cad5c6
  • chore: update dependencies 77363c0
  • docs(README): add sponsors 4e48239
  • test: remove only modifier and run all tests ae4d674
  • chore: update dependencies 50738c2

Full Changelog: v6.0.6...v6.0.7

Fix super.emit to forward all arguments to parent class

17 May 08:20
Compare
Choose a tag to compare

Update dependencies

17 May 06:44
Compare
Choose a tag to compare
  • chore: update dependencies 21100ac

v6.0.4...v6.0.5

update dependencies

02 Apr 03:18
Compare
Choose a tag to compare
  • chore: update dependencies 09e70bb
  • chore: update dependencies ce6c5b8

v6.0.3...v6.0.4

Upgrade to the latest version of macroable

23 Mar 10:32
Compare
Choose a tag to compare

Each test of dataset now receives a fresh context

23 Mar 07:13
Compare
Choose a tag to compare
  • fix: pass fresh context instance to every test generated using dataset 3c4b39f

v6.0.1...v6.0.2