Skip to content

Commit

Permalink
add and improve test coverage (#8)
Browse files Browse the repository at this point in the history
* Update vis-data and commit package-lock

* Prepare the package for TypeScript

* Update dependencies

* Fix coverage reports

* Fix Mocha never finishing

* New package lock (who knows why)

* Regenerate package lock

If anybody has any advice about merging package locks I'm all ears.

* Add coverage to root index.html

* Set up ESLint with Prettier for TS files

Prettier is not used for JavaScript files at the moment.

* Add tsconfig

* Install missing deps

* Fix ESLint config

* Add NodesHandler test

Brings the coverage from red/yellow to yellow/green numbers.
  • Loading branch information
Thomaash authored and mojoaxel committed Jul 25, 2019
1 parent 90794f3 commit 8ea5e64
Show file tree
Hide file tree
Showing 57 changed files with 81,488 additions and 3,246 deletions.
42 changes: 38 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
{
"presets": [
["@babel/preset-env", {
"targets": "> 0.1% or not dead"
}]
]
[
"@babel/preset-env",
{
"targets": "> 0.1% or not dead"
}
],
"@babel/preset-typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread",
"@babel/plugin-transform-runtime"
],
"env": {
"test": {
"presets": [
[
"@babel/preset-env",
{
"targets": "maintained node versions"
}
],
"@babel/preset-typescript"
]
},
"test-cov": {
"presets": [
[
"@babel/preset-env",
{
"targets": "maintained node versions"
}
],
"@babel/preset-typescript"
],
"plugins": ["istanbul"]
}
}
}
64 changes: 63 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ module.exports = {
mocha: true
},

parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: "module",
ecmaVersion: 2019,
project: 'tsconfig.json',
},

extends: "eslint:recommended",
plugins: ['prettier', '@typescript-eslint'],

extends: ['eslint:recommended', 'prettier'],

// For the full list of rules, see: http://eslint.org/docs/rules/
rules: {
'prettier/prettier': ['off'],

complexity: [2, 55],
"max-statements": [2, 115],
"no-unreachable": 1,
Expand All @@ -39,4 +46,59 @@ module.exports = {
}],
"guard-for-in": 1,
},
overrides: [
{
files: ['**/*.ts'],
rules: {
'prettier/prettier': ['error'],

// @TODO: Seems to mostly work just fine but I'm not 100 % sure.
// @TODO: Deprecated, anything like this for tsdoc?
'valid-jsdoc': [
'error',
{
prefer: {
arg: 'param',
argument: 'param',
return: 'returns',
},
requireParamDescription: true,
requireParamType: false,
requireReturn: false, // Requires return for void functions.
requireReturnDescription: true,
requireReturnType: false,
},
],

// Class related.
'@typescript-eslint/member-naming': [
'error',
{ private: '^_', protected: '^_', public: '^[^_]' },
],
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/prefer-readonly': 'error',

// Other.
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-regexp-exec': 'error',
// @TODO: Seems like a good thing, not yet on npm though.
// '@typescript-eslint/require-await': 'error',

// These are hoisted, I have no idea why it reports them by default.
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false, classes: false, typedefs: false },
],
// False positives for overloading, also tsc compiles with errors anyway.
'no-dupe-class-members': 'off',
// Blocks typesafe exhaustive switch (switch (x) { … default: const never: never = x }).
'no-case-declarations': 'off',
// Reports typeof bigint as an error, tsc validates this anyway so no problem turning this off.
'valid-typeof': 'off',
},
},
],
}
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts", "js"],
"require": ["./babel.mocha.js"],
"spec": ["./test/**/*.test.js", "./test/**/*.test.ts"]
}
8 changes: 8 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exclude": ["**/*.test.*", "**/*.d.ts"],
"extension": ["ts", "js"],
"include": ["lib/**/*"],
"instrument": false,
"reporter": ["text-summary", "lcov"],
"sourceMap": false
}
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"endOfLine": "lf",
"parser": "typescript",
"printWidth": 80,
"quoteProps": "consistent",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
3 changes: 3 additions & 0 deletions babel.mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('@babel/register')({
extensions: ['.ts', '.js'],
})
6 changes: 3 additions & 3 deletions dist/vis-network.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
</head>
<body>
<ul>
<li><a href="./coverage/lcov-report/">Coverage</a></li>
<li><a href="./docs/">Documentation</a></li>
<li><a href="./examples/">Examples</a></li>
</ul>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion lib/network/Network.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load custom shapes into CanvasRenderingContext2D
import './shapes';

import Emitter from 'emitter-component';
import Emitter from 'component-emitter';
import util from 'vis-util';
import dotparser from './dotparser';
import gephiParser from './gephiParser';
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/Activator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var keycharm = require('keycharm');
var Emitter = require('emitter-component');
var Emitter = require('component-emitter');
var Hammer = require('../module/hammer');
var util = require('vis-util');

Expand Down
Loading

0 comments on commit 8ea5e64

Please sign in to comment.