Skip to content

Commit

Permalink
chore: add unit tests (#316)
Browse files Browse the repository at this point in the history
* Add first round of tests

* Add more unit tests

* Add pull request testing workflow and clean all eslint errors

* Move cognitive complexity rule to .eslintrc and make it a warning not an error

* Add coverage to tests

* Add more tests

* Fix broken code

* Fix pull request testing workflow

* Fix tests

* Trigger CI

* Trigger CI

* fix linter
  • Loading branch information
fmvilas committed May 5, 2020
1 parent 840b5a4 commit 56c3602
Show file tree
Hide file tree
Showing 14 changed files with 7,762 additions and 2,227 deletions.
9 changes: 6 additions & 3 deletions .eslintrc
@@ -1,11 +1,13 @@
env:
node: true
es6: true
jest/globals: true

plugins:
plugins:
- sonarjs
- jest

extends:
extends:
- plugin:sonarjs/recommended

parserOptions:
Expand All @@ -25,6 +27,7 @@ rules:
consistent-this: [0, self]
func-style: 0
max-nested-callbacks: 0
camelcase: 0

# Warnings
no-debugger: 1
Expand All @@ -33,7 +36,7 @@ rules:
no-unused-expressions: 1
no-native-reassign: 1
no-fallthrough: 1
camelcase: 0
sonarjs/cognitive-complexity: 1

# Errors
eqeqeq: 2
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/pull-request-testing.yml
@@ -0,0 +1,22 @@
name: Pull request testing

on:
pull_request

jobs:
release:
name: 'Run linter and tests'
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 13
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ output
*.ids
*.orig
out/
coverage
3 changes: 3 additions & 0 deletions jest.config.js
@@ -0,0 +1,3 @@
module.exports = {
clearMocks: true,
};
3 changes: 3 additions & 0 deletions lib/__mocks__/filtersRegistry.js
@@ -0,0 +1,3 @@
const filtersRegistry = jest.genMockFromModule('../filtersRegistry');

module.exports = filtersRegistry;
18 changes: 18 additions & 0 deletions lib/__mocks__/utils.js
@@ -0,0 +1,18 @@
const utils = jest.genMockFromModule('../utils');

utils.__files = {};
utils.readFile = jest.fn(async (filePath) => {
return utils.__files[filePath];
});

utils.__isFileSystemPathValue = false;
utils.isFileSystemPath = jest.fn(() => utils.__isFileSystemPathValue);

utils.__isLocalTemplateValue = false;
utils.isLocalTemplate = jest.fn(async () => utils.__isLocalTemplateValue);

utils.getLocalTemplateDetails = jest.fn(async () => ({
resolvedLink: utils.__getLocalTemplateDetailsResolvedLinkValue || '',
}));

module.exports = utils;

0 comments on commit 56c3602

Please sign in to comment.