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.

Feature request: Support snapshot testing

See original GitHub issue

We test rules with a custom rule tester doing a snapshot test.

The built-in RuleTester can’t customize the output assertion, we don’t have the output to send to RuleTester, so we have to use SourceCodeFixer to apply fix from messages. Full implementation

We definitely want a better way to do snapshot test, maybe pass an assert option in future, but before that, can we expose SourceCodeFixer, so I can apply fix from the message?

The version of ESLint you are using.

8.0.0-beta.0

The problem you want to solve.

Fix our rule tester.

Are you willing to submit a pull request to implement this change?

Yes.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:35 (25 by maintainers)

github_iconTop GitHub Comments

4reactions
bmishcommented, Jan 2, 2022

FYI: I am hoping to work on this / write an RFC in the near future.

We have snapshot testing in a related linter I work on, ember-template-lint, which could be useful as prior art:

3reactions
fiskercommented, Aug 26, 2021

Thanks for working on this.

I’m afraid it won’t work for my case, as I understand, the outputAssert used to assert output and messages[index].suggestions[index].output, but I need assert message too.

As you can see in this snapshot, there is a code frame pointing the report range, this is the inital propose adding this custom tester, because it’s hard to test the report range using the start/end.

How about pass all the output and messages(including suggestion.ouput)?

ruleTester.run("foo", replaceProgramWith5Rule, {
    valid: [],
    invalid: [
        {
            code: "var foo = bar;",
            output: "5",
			errors: 3,
            assert(actual, scenario) {
                assert.strictEqual(actual.output, scenario.output, 'Message');
                // Or maybe we can use `this`, but not important
                // assert.strictEqual(actual.output, this.output, 'Message');
                assert.strictEqual(actual.messages.length, scenario.errors, 'Message');
            },
        }
    ]
});

Also, @lydell need assert in each invalid scenario to use toMatchInlineSnapshot, but I don’t need that, so can we also support put assertOutput on the root?

ruleTester.run("foo", replaceProgramWith5Rule, {
	assertOutput() {
		// ...
	},
    valid: [],
    invalid: [
        {
            code: "var foo = bar;",
            output: "5",
			errors: 3,
        }
    ]
});
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.
Read more >
btrfs snapshot management + VM - Page 3 - Forums - Unraid
February 14, 2019 in Feature Requests ... instance consider a subvolume at /mnt/cache/Video_Conversion/test/sv trying to create a snapshot ...
Read more >
Frontend testing standards and style guidelines - GitLab Docs
By now you've probably heard of Jest snapshot tests and why they are useful for various reasons. To use them within GitLab, there...
Read more >
Snapshot Simple Feature Request. | Proxmox Support Forum
I use snapshots for default configurations of guests testing software. Therefore I often make changes and need to roll back.
Read more >
Contribution guide - cdk8s
An issue can either be a bug report or a feature-request. If you wish to ask a question or seek ... Our integration...
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