Snapshot testing
See original GitHub issueCurrently, a typical test looks roughly like this:
it("test coalesce operator", function() {
var ast = parser.parseEval("$var = $a ?? true;");
ast.children[0].right.kind.should.be.exactly("bin");
ast.children[0].right.type.should.be.exactly("??");
ast.children[0].right.left.kind.should.be.exactly("variable");
ast.children[0].right.right.kind.should.be.exactly("boolean");
});
After working with snapshot-based testing for a while in prettier/plugin-php, I’ve really come to appreciate not having to write my own assertions anymore.
If we were to introduce snapshot-based testing here, the test case above would essentialy boil down to just one line, which could even be stored in a .php
file:
$var = $a ?? true;
The testing framework would then generate the snapshot and save it in a file:
{
"kind": "program",
"children": [
{
"kind": "assign",
"operator": "=",
"left": {
"kind": "variable",
"name": "var",
"byref": false,
"curly": false
},
"right": {
"kind": "bin",
"type": "??",
"left": {
"kind": "variable",
"name": "a",
"byref": false,
"curly": false
},
"right": {
"kind": "boolean",
"value": true,
"raw": "true"
}
}
}
],
"errors": []
}
Like this, we’d see the exact AST changes that every PR introduces to any of the existing test cases.
It seems that Esprima is using a similar approach.
If you’re interested, I could try preparing a little proof of concept - let me know what you think! 😄
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly. A typical snapshot test...
Read more >Snapshot Testing: Benefits and Drawbacks - SitePen
Snapshot testing is a type of “output comparison” or “golden master” testing. These tests prevent regressions by comparing the current ...
Read more >What is a snapshot test? - Lara Schenck
A snapshot test is a specific kind of technique for regression testing, that is, tests that make sure changes to a code-base do...
Read more >GitHub - pointfreeco/swift-snapshot-testing
Dozens of snapshot strategies. Snapshot testing isn't just for UIView s and CALayer s. Write snapshots against any value. Write your own snapshot...
Read more >Snapshot Testing - objc.io
Snapshot tests are run at the same time as the rest of your tests. They don't have to run as another test scheme....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks @b4dnewz, I’ve merged your PR #157, all tests are under Jest and the code coverage is great, you’ve done an amazing work !
Many thanks dude 👍
Would love to be of help, I’ll try my best to find some spare time and help with whatever I can 😃