Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add custom assertions via plugins #19

Closed
mroderick opened this issue Mar 3, 2018 · 8 comments
Closed

Feature: add custom assertions via plugins #19

mroderick opened this issue Mar 3, 2018 · 8 comments

Comments

@mroderick
Copy link
Member

As an author, it is currently rather inconvenient to add custom assertions to referee.

I always end up creating some meta file and importing that

// referee-with-custom-assertions.js
referee.add(/* arguments */);

module.exports = referee;

// some-module.test.js
var referee = require('../test/referee-with-custom-assertions');

This doesn't make it very convenient for me to re-use my domain specific assertions easily across repositories.

It would be really handy, if I could add custom assertions to referee via plugins, in the same fashion as plugins for eslint.

My custom assertions could then be published to an internal registry (or the public registry), and re-used across projects.

// referee.config.js
module.exports = {
    plugins: [
        require('path/to/max/assertions'),
        require('morgan-assertions')
    ]
};

// some-module.test.js
var referee = require('referee');

Thoughts?

@mantoni
Copy link
Member

mantoni commented Oct 27, 2018

I was wondering the same thing today. While your suggestion is fine for node, how about browser support?

Maybe this can even be achieved without changing anything. E.g. with Mocha your can require additional modules:

mocha -r ./path/to/assertions -r morgan-assertions

When using something browserify based this can also be done the same way.

@mroderick
Copy link
Member Author

How would that work in browsers?

Should the plugins export things into the global scope, that can be detected by referee when it is loaded?

@mantoni
Copy link
Member

mantoni commented Oct 27, 2018

The plugins can simply require('referee').add(...) as before.

@mroderick
Copy link
Member Author

I am a bit slow today, would that make the config file obsolete?

@mantoni
Copy link
Member

mantoni commented Oct 27, 2018

Yes. You'd essentially pass the file paths to require to the test runner instead.

@mroderick
Copy link
Member Author

I think we'll need to create a running example of how this would work. Perhaps this can be the foundation of a how-to article about using custom assertions with referee.

@mroderick
Copy link
Member Author

https://github.com/sinonjs/referee-custom-assert-with-mocha

mgred added a commit to mgred/referee that referenced this issue Oct 28, 2018
This adds an example on how to load custom assertions as modules as
described in https://github.com/sinonjs/referee-custom-assert-with-mocha
to docs. See: sinonjs#19
A typo was fixed as well: helps -> help
@mgred
Copy link
Contributor

mgred commented Oct 28, 2018

👍 That's awesome, I've stolen your work for the docs 😁

mgred added a commit to mgred/referee that referenced this issue Oct 28, 2018
Change bold text to 4th level heading

See: sinonjs#19
mgred added a commit that referenced this issue Oct 28, 2018
* feat(docs): Add example on loading custom assertions with mocha

This adds an example on how to load custom assertions as modules as
described in https://github.com/sinonjs/referee-custom-assert-with-mocha
to docs. See: #19
A typo was fixed as well: helps -> help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants