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.

Make RuleTester test runner agnostic

See original GitHub issue

Hey guys!

I have a few ESLint plugin repos I’m maintaining, where we use AVA as the test runner instead of mocha (including eslint-plugin-ava 😄). What we did until now was to wrap the whole RuleTester call in one AVA test, which made the test feedback pretty bad (it’s all good or all fail, you don’t know which one crashed, and the error messages were simplistic), just like if you would simply run the test file using node instead of mocha.

I noticed that by overriding the RuleTester’s before and itmethods, I could create proper test suite à la mocha, and created https://github.com/jfmengels/eslint-ava-rule-tester. It feels a bit hacky and fragile, so I would have liked to know if there was a better way, or if we could introduce one, to make RuleTester more test runner agnostic.

I provided screenshots of actual behavior with AVA and the behavior with eslint-ava-rule-tester in this PR (source code available there if needed) https://github.com/avajs/eslint-plugin-ava/pull/105.

I’m not sure about the solution to offer, but it would probably be something like adding a new parameter to RuleTester, which could be either an object with keys describe and it (which would be functions that create tests), or a new function that returns that.

var test = require('ava');

var avaTestCreator = {
  describe: function(test, method) {
    return method.apply(this);
  },
  it: function (text, method) {
    test(text, method);
  };
};

var ruleTester = new RuleTester({
    env: {
        es6: true
    } // and other options
}, avaTestCreator);

(cc @sindresorhus @twada @jamestalmage)

Oh, and by the way: Love the work that you guys are doing, thanks so much for the work you’re putting into this ❤️, I don’t express it often enough.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, May 26, 2016

Yeah, it and describe are part of the API. We should probably document them specifically.

@jamestalmage if you want to propose something around assert, please open a new issue.

0reactions
nzakascommented, May 27, 2016

@jfmengels yeah, that’s a good spot. Probably just a section for customizing RuleTester there would do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Fuchsia Test Runner Framework
A runtime-agnostic, runtime-inclusive testing framework ... Fuchsia aims to be inclusive, for instance in the sense that developers can create ...
Read more >
Framework Agnostic End-to-End Testing with Chrome, GitLab ...
Step 1: Set up a simple JavaScript project that interacts with Chrome over Puppeteer and creates screenshots of a website. First, we need...
Read more >
Creating a Custom ESLint Rule with TDD - DEV Community ‍ ‍
For testing the rule I'm going to use the RuleTester which is a utility for writing tests for ESLint rules, and quite a...
Read more >
Writing a Language-Agnostic Integration Test Suite - GoDaddy
Writing a Language-Agnostic Integration Test Suite. My team at GoDaddy builds and maintains an internal platform for running controlled experiments on ...
Read more >
How to use the eslint.RuleTester function in eslint - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately. Enable here. github vuejs /...
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