Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Feb 19, 2022
1 parent 917abb0 commit 47b4250
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/unified-lint-rule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"vfile": "^5.0.0"
},
"scripts": {
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage"
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage",
"test": "tape test.js"
},
"xo": false,
"typeCoverage": {
Expand Down
35 changes: 35 additions & 0 deletions packages/unified-lint-rule/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import test from 'tape'
import {VFile} from 'vfile'
import {lintRule} from './index.js'

test('`this` value', async (t) => {
t.plan(1)
const processor = {}
lintRule('this-value', rule).call(processor)(
undefined /* tree */,
new VFile(),
() => {} /* next */
)

function rule() {
t.equal(
this,
processor,
"rule's `this` value should be the processor using it"
)
}
})

test('`fileSet` argument', async (t) => {
t.plan(1)
const expected = {}
lintRule('fileSet-argument', rule)(undefined /* options */, expected)(
undefined /* tree */,
new VFile(),
() => {} /* next */
)

function rule(tree, file, options, actual) {
t.equal(actual, expected, 'should pass the `fileSet` argument to the rule')
}
})

0 comments on commit 47b4250

Please sign in to comment.