|
| 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. |
0 commit comments