-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.spec.js
53 lines (41 loc) · 2.13 KB
/
run.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-env jest */
const td = require('testdouble')
require('testdouble-jest')(td, jest)
const getContext = () => {
td.replace('./helpers/getFileContent')
const {getLocalStandard} = td.replace('./helpers/getLocalStandard', {getLocalStandard: td.func()})
td.replace('./helpers/getStandardAdditionalConfig', {getStandardAdditionalConfig: td.func()})
const {isPathIgnored} = td.replace('./helpers/isPathIgnored', {isPathIgnored: td.func()})
const {pass, fail, skip} = td.replace('create-jest-runner', {pass: td.func(), fail: td.func(), skip: td.func()})
const run = require('./run')
return {isPathIgnored, getLocalStandard, skip, pass, run, fail}
}
test('it marks test as skipped if file path is ignored', () => {
const {isPathIgnored, skip, run} = getContext()
const testPath = 'ignoredPath'
td.when(isPathIgnored(td.matchers.anything(), td.matchers.anything(), testPath)).thenReturn(true)
run({testPath, config: {}})
td.verify(skip(td.matchers.contains({
test: {path: testPath}
})))
})
test('it marks test as passed if the errorCount equals 0', () => {
const {getLocalStandard, pass, run} = getContext()
const standardMock = {lintTextSync: td.func()}
td.when(getLocalStandard(td.matchers.anything())).thenReturn(standardMock)
td.when(standardMock.lintTextSync(td.matchers.anything(), td.matchers.anything())).thenReturn({errorCount: 0})
const testPath = 'passingTest'
run({testPath, config: {}})
td.verify(pass(td.matchers.contains({test: {path: testPath}})))
})
test('it marks test as failed if the errorCount is greater than 0', () => {
const {getLocalStandard, fail, run} = getContext()
const standardMock = {lintTextSync: td.func()}
td.when(getLocalStandard(td.matchers.anything())).thenReturn(standardMock)
td.when(standardMock.lintTextSync(td.matchers.anything(), td.matchers.anything())).thenReturn({errorCount: 2, results: [{messages: []}]})
const testPath = 'passingTest'
run({testPath, config: {}})
td.verify(fail(td.matchers.contains({test: {path: testPath, errorMessage: '', title: 'Standard error'}})))
})
// TODO try to generate the error message
// TODO test for fixing when STANDARD_AUTOFIX is set