Skip to content

Commit c206e79

Browse files
committed
Update documentation
1 parent 40c65e6 commit c206e79

5 files changed

Lines changed: 111 additions & 3 deletions

File tree

website/blog/v0.7.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
tags: [v0.7.0, patch]
2+
tags: [v0.7.0, patch, major]
33
sidebar_position: 3
44
date: 2022-05-17
55
authors:

website/blog/v0.8.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
tags: [v0.8.0, patch]
2+
tags: [v0.8.0, patch, major]
33
sidebar_position: 4
44
date: 2022-05-18
55
authors:

website/blog/v0.9.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
tags: [v0.9.0, patch, fast-check]
2+
tags: [v0.9.0, patch, fast-check, major]
33
sidebar_position: 4
44
date: 2022-05-22
55
authors:

website/blog/v0.9.1.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
tags: [v0.9.1, patch, minor]
3+
sidebar_position: 5
4+
date: 2022-09-13
5+
authors:
6+
- name: Jesse Mitchell
7+
title: Developer of Pineapple
8+
url: https://github.com/TotalTechGeek
9+
image_url: https://github.com/TotalTechGeek.png
10+
---
11+
12+
# Improving Property Based Testing (v0.9.1)
13+
14+
Hi all!
15+
16+
This release is focused on providing some small quality of life improvements to the property-based testing features within Pineapple.
17+
18+
There are two main additions to the technology:
19+
20+
#### Namespaces
21+
22+
```js
23+
/**
24+
* Creates the static values for use in various scenarios in our codebase.
25+
* @pineapple_define friends
26+
*/
27+
function define () {
28+
return {
29+
kevin: { /* ... */ },
30+
shane: { /* ... */ },
31+
emily: { /* ... */ }
32+
}
33+
}
34+
35+
/**
36+
* #friends.emily, #friends.shane returns 'Battle won!'
37+
* #friends.shane, #friends.kevin returns 'Battle draw!'
38+
*/
39+
function fight (attacker, defender) {
40+
/* ... */
41+
}
42+
```
43+
44+
Namespaces might make it simpler to set up various generators & static values that you might wish to use throughout your tests.
45+
46+
#### Better Constant Detection
47+
48+
When you set up definitions in Pineapple, the testing framework will do its best to try to keep track of whether your "arbitrary expression" is actually constant.
49+
50+
This prevents a bunch of duplicate tests from taking place, particularly when it would be annoying (like in snapshots).
51+
52+
Previously, when one would try the following:
53+
54+
```js
55+
/**
56+
* @pineapple_define
57+
*/
58+
function define () {
59+
return { age: 17 }
60+
}
61+
62+
/**
63+
* @test { name: 'Kevin', age: #age }
64+
* The above would not be detected as static in v0.9.0,
65+
* but will be in v0.9.1
66+
*/
67+
function setupAccount({ name, age }) {
68+
/* ... */
69+
}
70+
71+
/**
72+
* @test #age returns false
73+
* The above will be detected as constant in both v0.9.0 and v0.9.1
74+
*/
75+
function isAmericanDrinkingAge (age) {
76+
return age >= 21
77+
}
78+
```
79+
80+
Pineapple would not be able to detect that the expression `{ name: 'Kevin', age: #age }` was actually a constant expression. However, if you used `#age`
81+
outside of a structure as seen in the second example, it would work!
82+
83+
To make developer's lives easier, Pineapple has been improved to try to do a better job of detecting
84+
constant structures.

website/docs/writing-tests/fuzzing-property-based.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,27 @@ function ofAge (person) {
115115
return person.age > 21
116116
}
117117
```
118+
119+
It is also possible to provide namespaces for your arbitraries:
120+
121+
```js
122+
/**
123+
* @pineapple_define tavern
124+
*/
125+
function arbitraries () {
126+
return {
127+
// you can pass in an arbitrary, a function that returns an arbitrary, or a value that'll be constant.
128+
// it will be named the value that you define here in the Pineapple engine.
129+
person: fc.record({ id: fc.integer(), name: fc.string(), age: fc.integer(12, 80) })
130+
}
131+
}
132+
133+
/**
134+
* @test #tavern.person returns args.0.age > 21
135+
*/
136+
function ofAge (person) {
137+
return person.age > 21
138+
}
139+
```
140+
141+
This should make it simpler to organize some of your static / generated data sets that you would like to use for your tests.

0 commit comments

Comments
 (0)