Skip to content

Commit cee913e

Browse files
committed
Add eslint rule snapshot comparison
`npm test` will now run a snapshot comparison. `npm run test:update` will update the snapshot to the latest eslint run. Add ava & file-manager-js devDependencies. Update documentation.
1 parent 68f2158 commit cee913e

File tree

8 files changed

+90
-97
lines changed

8 files changed

+90
-97
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/reports/**
1212
analysis.json
1313
npm-debug.log
14+
/demo/test/snapshots/*results.txt

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Utilizes the following plugins:
2323
1. Add either `eslint-config-tree` or `eslint-config-frontier-react` as a devDependency.
2424

2525
1. Add this repository as a package devDependency:
26-
26+
2727
> "eslint-config-tree": "github:fs-webdev/eslint-config-tree#semver:^1",
2828
2929
1. In your `eslintrc.js` file, put the following:
@@ -42,3 +42,9 @@ Utilizes the following plugins:
4242
1. Add both `tree` and the frontier eslint configuration of your choice as Code Climate `prepare` resources (see: [extended eslint docs](https://www.familysearch.org/frontier/legacy/ui-components/eslint-config-frontier/)).
4343

4444
1. Enjoy.
45+
46+
## Testing/Updating:
47+
48+
Occasionally, there may be an update which breaks a rule in particular or linting in general. To this end, when running `npm test`, we output the current linting results to a text file, clean it up a little, and employ ava to run a snapshot comparison unit test to determine if our linting output has changed from the previous run.
49+
50+
If there has been a change (say you added a new rule, or there is a new valid violation triggered), you can update the snapshot via `npm run test:update`.

demo/test/index.html

-18
This file was deleted.

demo/test/lint-output.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import test from 'ava';
2+
const fileManager = require('file-manager-js');
3+
4+
test('Should have consistent rule output', async t => {
5+
// Run previously via npm test, save off results, and read output
6+
return fileManager.readFile('./demo/test/snapshots/new-lint-results.txt')
7+
.then((content) => {
8+
const eslintOutput = content.toString(); // content is instance of Buffer, so it needs to be parsed
9+
t.snapshot(eslintOutput);
10+
})
11+
.catch((err) => {
12+
console.log(err);
13+
t.fail();
14+
});
15+
});

demo/test/snapshots/lint-output.js.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Snapshot report for `demo/test/lint-output.js`
2+
3+
The actual snapshot is saved in `lint-output.js.snap`.
4+
5+
Generated by [AVA](https://ava.li).
6+
7+
## Should have consistent rule output
8+
9+
> Snapshot 1
10+
11+
`␊
12+
example.js␊
13+
6:0 warning Inline eslint-disable found bestpractices/no-eslint-disable␊
14+
8:1 warning Unexpected 'FIXME' comment no-warning-comments␊
15+
9:1 warning Unexpected 'TODO' comment no-warning-comments␊
16+
10:1 warning Unexpected 'HACK' comment no-warning-comments␊
17+
11:1 warning Unexpected 'HERE BE DRAGONS' comment no-warning-comments␊
18+
21:1 warning Missing JSDoc @description declaration jsdoc/require-description␊
19+
21:1 warning JSDoc @returns declaration present but return expression not available in function jsdoc/require-returns-check␊
20+
21:1 warning JSDoc syntax error valid-jsdoc␊
21+
23:0 warning Expected @param names to be "params". Got "a, b" jsdoc/check-param-names␊
22+
23:0 warning Missing JSDoc @param "a" description jsdoc/require-param-description␊
23+
24:0 warning Missing JSDoc @param "b" type jsdoc/require-param-type␊
24+
24:0 warning Missing JSDoc @param "b" description jsdoc/require-param-description␊
25+
25:0 warning Missing JSDoc @returns type jsdoc/require-returns-type␊
26+
25:0 warning Missing JSDoc @returns description jsdoc/require-returns-description␊
27+
30:5 error 'variable' is assigned a value but never used no-unused-vars␊
28+
30:16 error This conditional operation returns the same value whether the condition is "true" or "false" sonarjs/no-all-duplicated-branches␊
29+
30:17 error Unexpected constant condition no-constant-condition␊
30+
30:25 error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary␊
31+
32:5 error Correct one of the identical sub-expressions on both sides of operator "&&" sonarjs/no-identical-expressions␊
32+
32:16 warning Unexpected use of undefined no-undefined␊
33+
32:40 warning Unexpected use of undefined no-undefined␊
34+
33:3 error This function expects 1 argument, but 2 were provided sonarjs/no-extra-arguments␊
35+
34:28 error Module path/to/legacyModule is deprecated. Use module x instead deprecate/import␊
36+
36:3 error Function deprecatedFunction is deprecated. Use function x from package y instead deprecate/function␊
37+
36:3 error 'deprecatedFunction' is not defined no-undef␊
38+
37:3 error '$' is not defined no-undef␊
39+
37:3 error Member expression $.each is deprecated. Use native forEach instead deprecate/member-expression␊
40+
38:3 error Unexpected 'debugger' statement no-debugger␊
41+
42+
example.json␊
43+
4:5 error Property keys must be doublequoted json/undefined␊
44+
4:13 error Value expected json/valueexpected␊
45+
5:11 error Colon expected json/colonexpected␊
46+
6:5 error Expected comma json/commaexpected␊
47+
5:5 warning Duplicate object key json/duplicatekey␊
48+
6:19 error Trailing comma json/trailingcomma␊
49+
8:2 error End of file expected json/undefined␊
50+
51+
✖ 35 problems (18 errors, 17 warnings)␊
52+
`
1.15 KB
Binary file not shown.

demo/test/unit_test.html

-72
This file was deleted.

package.json

+15-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"githubAutomatorOptions": {
1717
"disableSlackNotifications": true
1818
},
19+
"ava": {
20+
"files": [
21+
"demo/test/*.js"
22+
]
23+
},
1924
"dependencies": {
2025
"babel-eslint": "^8",
2126
"eslint": "^5",
@@ -33,14 +38,18 @@
3338
"eslint-plugin-standard": "^4"
3439
},
3540
"devDependencies": {
36-
"eslint-config-frontier": "github:fs-webdev/eslint-config-frontier"
41+
"ava": "^2.4.0",
42+
"eslint-config-frontier": "github:fs-webdev/eslint-config-frontier",
43+
"file-manager-js": "^3.1.6"
3744
},
3845
"scripts": {
39-
"lint": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html'",
40-
"lint-fix": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html' --fix",
41-
"lint-report": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html' --format html --output-file ./reports/linter/lintresults.html & eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html' --format json --output-file ./reports/linter/lintresults.json",
46+
"lint": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json'",
47+
"lint:fix": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --fix",
48+
"lint:report": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' '**/*.html' --format html --output-file ./reports/linter/lintresults.html & eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --format json --output-file ./reports/linter/lintresults.json",
49+
"lint:snapshot": "eslint --ignore-pattern '.*' '**/*.js' '**/*.json' --no-color --output-file ./demo/test/snapshots/new-lint-results.txt; npm run test:format",
4250
"preinstall": "git config --global url.https://github.com/.insteadOf git://github.com/",
43-
"pretest": "npm run lint-fix",
44-
"test": "echo \"Error: no test specified\" && exit 1"
51+
"test": "npm run lint:snapshot; ava",
52+
"test:format": "sed -i '' 's|^.*eslint-config-tree/demo/||g' demo/test/snapshots/new-lint-results.txt",
53+
"test:update": "npm run lint:snapshot; ava --update-snapshots"
4554
}
4655
}

0 commit comments

Comments
 (0)