Skip to content

Commit

Permalink
Add tests for create-ava-rule.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Zherdev committed Jul 10, 2019
1 parent ad046ca commit 74632ac
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/create-ava-rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import {visitIf} from 'enhance-visitors';
import createAvaRule from '../create-ava-rule';

const rule = {
create: context => {
const ava = createAvaRule();

return ava.merge({
'Program:exit': node => {
if (!ava.isInTestFile()) {
context.report({node, message: 'not a test file'});
}
}
});
}
};

const ruleTester = avaRuleTester(test, {
env: {
es6: true,
},
parserOptions: {
sourceType: 'module'
}
});

ruleTester.run('rule-fixture', rule, {
valid: [
'const test = require(\'ava\');',
'const {serial} = require(\'ava\');',
'const {serial: test} = require(\'ava\');',
'import test from \'ava\';',
'import {serial} from \'ava\';',
'import {serial as test} from \'ava\';'
],

invalid: [
{
code: 'const test2 = require(\'ava\');',
errors: [{message: 'not a test file'}]
},
{
code: 'const {serial2} = require(\'ava\');',
errors: [{message: 'not a test file'}]
},
{
code: 'const {serial2: test} = require(\'ava\');',
errors: [{message: 'not a test file'}]
},
{
code: 'import test2 from \'ava\';',
errors: [{message: 'not a test file'}]
},
{
code: 'import {serial2} from \'ava\';',
errors: [{message: 'not a test file'}]
},
{
code: 'import {serial2 as test} from \'ava\';',
errors: [{message: 'not a test file'}]
}
]
});

0 comments on commit 74632ac

Please sign in to comment.