question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currently, 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:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ichiriaccommented, Jul 8, 2018

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 👍

2reactions
DaGhostmancommented, Apr 15, 2018

Would love to be of help, I’ll try my best to find some spare time and help with whatever I can 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found