Skip to content

Commit

Permalink
- Testing: Add nyc for coverage
Browse files Browse the repository at this point in the history
- Testing: Test against source (using `esm`)
- Linting (ESLint): Remove redundant "use strict" with switch to ESM
- npm: Add `test-cov` script
  • Loading branch information
brettz9 committed Jan 13, 2020
1 parent d25655d commit 0d84b65
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 60 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
docs/ts
coverage
13 changes: 3 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,15 @@ module.exports = {
}
},
{
"files": ["test/**", "test-helpers/node-env.js"],
"files": ["test/**"],
"globals": {
"assert": "readonly",
"jsonpath": "readonly",
"require": "readonly",
"module": "readonly"
},
"parserOptions": {
"sourceType": "script"
"jsonpath": "readonly"
},
"env": {"mocha": true},
"rules": {
"strict": ["error", "global"],
"import/no-commonjs": 0,
"import/unambiguous": 0,
"quotes": 0,
"import/unambiguous": 0,
// Todo: Reenable
"max-len": 0
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ reports
target
*.log
docs/ts
coverage
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lgtm.yml
.idea
.remarkrc
docs
.nyc_output
coverage
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"eslint-plugin-sonarjs": "^0.5.0",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-unicorn": "^15.0.1",
"esm": "^3.2.25",
"mocha": "^7.0.0",
"node-static": "^0.7.11",
"nyc": "^15.0.0",
Expand All @@ -89,13 +90,32 @@
"browserslist": [
"cover 100%"
],
"nyc": {
"reporter": [
"text",
"html"
],
"exclude": [
".eslintrc.js",
"rollup.config.js",
".idea",
"coverage",
"dist",
"demo",
"docs",
"test",
"test-helpers/node-env.js"
]
},
"scripts": {
"remark": "remark -q -f .",
"typescript": "tsc src/jsonpath.d.ts",
"build-docs": "typedoc --out docs/ts src --includeDeclarations",
"open-docs": "open-cli http://localhost:8084/docs/ts/ && npm start",
"mocha": "mocha --require test-helpers/node-env.js test",
"coverage": "open-cli http://localhost:8084/coverage/ && npm start",
"mocha": "mocha --require esm --require test-helpers/node-env.js test",
"test": "npm run rollup && npm run mocha",
"test-cov": "nyc --all npm run mocha",
"open": "open-cli http://localhost:8084/demo/ && npm start",
"start": "static -p 8084",
"rollup": "rollup -c",
Expand Down
9 changes: 6 additions & 3 deletions test-helpers/node-env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use strict';
global.jsonpath = require('../').JSONPath;
global.assert = require('chai').assert;
import {assert} from 'chai';

import {JSONPath} from '../src/jsonpath.js';

global.jsonpath = JSONPath;
global.assert = assert;
54 changes: 27 additions & 27 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>

<script src="../dist/index-umd.js"></script>
</head>
<body>
<h1>JSONPath Tests</h1>
<div id="mocha"></div>
<script>
/* globals chai, JSONPath */
'use strict';

<script type="module">
/* globals chai */
import {JSONPath} from '../src/jsonpath.js';

mocha.setup('bdd');
window.assert = chai.assert;
window.jsonpath = JSONPath.JSONPath;
window.jsonpath = JSONPath;
mocha.globals(['jsonpath']);
</script>
<script src="test.all.js"></script>
<script src="test.arr.js"></script>
<script src="test.at_and_dollar.js"></script>
<script src="test.callback.js"></script>
<script src="test.custom-properties.js"></script>
<script src="test.errors.js"></script>
<script src="test.escaping.js"></script>
<script src="test.eval.js"></script>
<script src="test.examples.js"></script>
<script src="test.intermixed.arr.js"></script>
<script src="test.parent-selector.js"></script>
<script src="test.path_expressions.js"></script>
<script src="test.performance.js"></script>
<script src="test.pointer.js"></script>
<script src="test.properties.js"></script>
<script src="test.return.js"></script>
<script src="test.toPath.js"></script>
<script src="test.toPointer.js"></script>
<script src="test.type-operators.js"></script>

<script>
'use strict';
<script type="module">
import './test.all.js';
import './test.arr.js';
import './test.at_and_dollar.js';
import './test.callback.js';
import './test.custom-properties.js';
import './test.errors.js';
import './test.escaping.js';
import './test.eval.js';
import './test.examples.js';
import './test.intermixed.arr.js';
import './test.parent-selector.js';
import './test.path_expressions.js';
import './test.performance.js';
import './test.pointer.js';
import './test.properties.js';
import './test.return.js';
import './test.toPath.js';
import './test.toPointer.js';
import './test.type-operators.js';

mocha.run();
</script>
</body>
Expand Down
1 change: 0 additions & 1 deletion test/test.all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - All', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.arr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Array', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.at_and_dollar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - At and Dollar sign', function () {
const t1 = {
Expand Down
1 change: 0 additions & 1 deletion test/test.callback.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Callback', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.custom-properties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Custom properties', function () {
const t1 = {
Expand Down
1 change: 0 additions & 1 deletion test/test.errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Errors', function () {
it('should throw with missing `path`', function () {
Expand Down
1 change: 0 additions & 1 deletion test/test.escaping.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Escaping', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.eval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Eval', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.examples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Examples', function () {
// tests based on examples at http://goessner.net/articles/jsonpath/
Expand Down
1 change: 0 additions & 1 deletion test/test.intermixed.arr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Intermixed Array', function () {
// tests based on examples at http://goessner.net/articles/jsonpath/
Expand Down
1 change: 0 additions & 1 deletion test/test.parent-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Parent selector', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.path_expressions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Path expressions', function () {
// tests based on examples at http://goessner.net/articles/JsonPath/
Expand Down
1 change: 0 additions & 1 deletion test/test.performance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Performance', function () {
const arraySize = 12333,
Expand Down
1 change: 0 additions & 1 deletion test/test.pointer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Pointers', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.properties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Properties', function () {
const json = {
Expand Down
1 change: 0 additions & 1 deletion test/test.return.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Return', function () {
const json = {"store": {
Expand Down
1 change: 0 additions & 1 deletion test/test.toPath.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - toPath*', function () {
it('toPathString', () => {
Expand Down
1 change: 0 additions & 1 deletion test/test.toPointer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - toPointer', function () {
it('toPointer', () => {
Expand Down
1 change: 0 additions & 1 deletion test/test.type-operators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

describe('JSONPath - Type Operators', function () {
// tests based on examples at http://goessner.net/articles/jsonpath/
Expand Down

0 comments on commit 0d84b65

Please sign in to comment.