Skip to content

Commit

Permalink
v0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalTechGeek committed Oct 18, 2022
1 parent 85808f0 commit 5a24472
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const formatOption = new Option('-f, --format <format>', 'The output format').ch

program
.name('pineapple')
.version('0.9.1')
.version('0.10.0')
.option('-i, --include <files...>', 'Comma separated globs of files.')
.option('-a, --accept-all', 'Accept all snapshots.')
.option('-u, --update-all', 'Update all snapshots.')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pineapple",
"version": "0.9.1",
"version": "0.10.0",
"description": "A testing framework for humans.",
"main": "index.js",
"scripts": {
Expand Down
43 changes: 43 additions & 0 deletions website/blog/v0.10.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
tags: [v0.10.0, patch, major]
sidebar_position: 5
date: 2022-10-18
authors:
- name: Jesse Mitchell
title: Developer of Pineapple
url: https://github.com/TotalTechGeek
image_url: https://github.com/TotalTechGeek.png
---

# Improving Snapshots & User Output (v0.10.0)

Hey everyone!

This release is focused on providing some additional small quality of life improvements to the tool.

## Better Snapshots

Prior to this release, all snapshots were captured in a global `pineapple-snapshot`, and while this worked, I don't believe it made reviewing particularly effective.

When snapshots are captured, it will now save in close proximity to your file that you're testing, appending a `.psnap` to the file name.

So if you were testing a `./src/math.js` file, the snapshot will be persisted to `./src/math.js.psnap`

## More Hooks

This version introduces a few new hooks for test lifecycle management.

You may now use:

- `@beforeGlobal`
- `@beforeEachGlobal`
- `@afterGlobal`
- `@afterEachGlobal`

These hooks were introduced to make it easier to pair Pineapple with measurement frameworks, where you might need to reset certain fields.

Right now, the functions invoked do not receive any arguments, but this will likely be addressed in a future version.

## Better Output

In certain cases, important error feedback was suppressed by the framework, thus making it difficult to rectify issues identified by the test. This feedback should no longer be suppressed.
39 changes: 34 additions & 5 deletions website/docs/writing-tests/setup-and-teardown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ sidebar_position: 6

Continuing down the path of writing more complex tests with Pineapple, there may be certain situations where you need to perform some additional setup & teardown. While not strictly required, these are recommended to be embedded in a `.test.js` file.

## Global Before / After Hooks

## Before / After all of the tests
### Before All / After All

If you wish to run a function before / after all of the tests are run (like an initial setup for every single test you're going to run), you are able to simply add a JSDoc annotation to a function without any other descriptors.


```js
/**
* For the purposes of demonstrating beforeAll, this function
* is an async function that populates either some set or a database
* @beforeAll
*/
export async function initializeCityDatabase() {
...
// ...
}


Expand All @@ -35,6 +35,36 @@ export async function isCity(city) {

The annotations for this are `beforeAll` and `afterAll`. You may define multiple functions to be invoked.

### Before / After (Global)

If you need to run a function before or after each set of tests (before each function), you may use the `@beforeGlobal` and `@afterGlobal` tags.

```js
/**
* @beforeGlobal
*/
function resetCounts() {
// ...
}
```

This might make sense if you're using a framework and you're performing measurements in each test set.

### Before Each / After Each (Global)

If you need to run a function before or after each test (every individual test case), you may use the `@beforeEachGlobal` and `@afterEachGlobal` tags.

```js
/**
* @beforeEachGlobal
*/
function resetCounts() {
// ...
}
```

This might make sense if you're using a framework and you're performing measurements in each test.

## Before / After tests within a function

If you need to run the setup with the function itself, you have multiple options; these annotation require you to specify what you'd like to have executed (usually methods imported using `pineapple_import`).
Expand Down Expand Up @@ -79,7 +109,6 @@ export async function example(name) {

If you'd prefer for it to run before / after each test case,


```js
let person

Expand Down Expand Up @@ -110,4 +139,4 @@ export function levelUp(amount) {

In general, I'd encourage you to avoid using these annotations. They have been added to the framework to introduce flexibility, but if your tests necessitate the use of setup & teardown, you likely have a use-case that unit tests aren't ideal for. Scenario Tests with a framework like Cucumber would likely be far more fitting.

There might be some use-cases where `@beforeAll` and `@afterAll` might make sense, but please be mindful that there may be better options.
There might be some use-cases where `@beforeAll` and `@afterAll` might make sense, but please be mindful that there may be better options.

0 comments on commit 5a24472

Please sign in to comment.