-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Zherdev
committed
Jul 10, 2019
1 parent
ad046ca
commit 74632ac
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}] | ||
} | ||
] | ||
}); |