Unverified Commit 393d0d14 authored by Imran Salam's avatar Imran Salam Committed by GitHub
Browse files

Add ESLint plugin for Jest (#505)

parent 126e9eba
Pipeline #161441 passed with stages
in 4 minutes and 20 seconds
...@@ -3,9 +3,9 @@ module.exports = { ...@@ -3,9 +3,9 @@ module.exports = {
extends: [ extends: [
'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended',
'plugin:react/recommended', 'plugin:react/recommended',
'plugin:prettier/recommended' // Displays prettier errors as ESLint errors. This has to be the last in this array (not yet sure why). 'plugin:prettier/recommended', // Displays prettier errors as ESLint errors. This has to be the last in this array (not yet sure why).
], ],
plugins: ['react-hooks'], plugins: ['react-hooks', 'jest'],
parserOptions: { parserOptions: {
ecmaVersion: 2019, ecmaVersion: 2019,
sourceType: 'module', sourceType: 'module',
...@@ -20,7 +20,7 @@ module.exports = { ...@@ -20,7 +20,7 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': 0, '@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/prefer-interface': 0, '@typescript-eslint/prefer-interface': 0,
'@typescript-eslint/explicit-function-return-type': 0, '@typescript-eslint/explicit-function-return-type': 0,
"@typescript-eslint/explicit-module-boundary-types": 0, '@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-explicit-any': 0, '@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-use-before-define': 0, '@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/no-unused-vars': ['warn', { args: 'after-used' }], '@typescript-eslint/no-unused-vars': ['warn', { args: 'after-used' }],
...@@ -29,9 +29,12 @@ module.exports = { ...@@ -29,9 +29,12 @@ module.exports = {
'react/no-unescaped-entities': 0, 'react/no-unescaped-entities': 0,
'react-hooks/rules-of-hooks': 2, 'react-hooks/rules-of-hooks': 2,
'prettier/prettier': 0, 'prettier/prettier': 0,
"no-unused-vars": "off", 'no-unused-vars': 'off',
'no-unneeded-ternary': 'error', 'no-unneeded-ternary': 'error',
'eqeqeq': 'error' 'eqeqeq': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error'
}, },
settings: { settings: {
react: { react: {
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
"dotenv-webpack": "7.0.2", "dotenv-webpack": "7.0.2",
"eslint": "7.27.0", "eslint": "7.27.0",
"eslint-config-prettier": "8.3.0", "eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "3.4.0", "eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.23.2", "eslint-plugin-react": "7.23.2",
"eslint-plugin-react-hooks": "4.2.0", "eslint-plugin-react-hooks": "4.2.0",
...@@ -15922,6 +15923,27 @@ ...@@ -15922,6 +15923,27 @@
"eslint": ">=7.0.0" "eslint": ">=7.0.0"
} }
}, },
"node_modules/eslint-plugin-jest": {
"version": "24.3.6",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.3.6.tgz",
"integrity": "sha512-WOVH4TIaBLIeCX576rLcOgjNXqP+jNlCiEmRgFTfQtJ52DpwnIQKAVGlGPAN7CZ33bW6eNfHD6s8ZbEUTQubJg==",
"dev": true,
"dependencies": {
"@typescript-eslint/experimental-utils": "^4.0.1"
},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">= 4",
"eslint": ">=5"
},
"peerDependenciesMeta": {
"@typescript-eslint/eslint-plugin": {
"optional": true
}
}
},
"node_modules/eslint-plugin-prettier": { "node_modules/eslint-plugin-prettier": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.0.tgz",
...@@ -39861,7 +39883,6 @@ ...@@ -39861,7 +39883,6 @@
"integrity": "sha512-qOtwgiqI3LMqT0eXYNV6ykp7qSu0LQGeXxy3wOBGuDDqAizfgnAjomYEWGFcyKp5ahV7HCRCjxbixAklFPUmyw==", "integrity": "sha512-qOtwgiqI3LMqT0eXYNV6ykp7qSu0LQGeXxy3wOBGuDDqAizfgnAjomYEWGFcyKp5ahV7HCRCjxbixAklFPUmyw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/core": "^7.12.10",
"@babel/generator": "^7.12.11", "@babel/generator": "^7.12.11",
"@babel/parser": "^7.12.11", "@babel/parser": "^7.12.11",
"@babel/plugin-transform-react-jsx": "^7.12.12", "@babel/plugin-transform-react-jsx": "^7.12.12",
...@@ -50226,6 +50247,15 @@ ...@@ -50226,6 +50247,15 @@
"dev": true, "dev": true,
"requires": {} "requires": {}
}, },
"eslint-plugin-jest": {
"version": "24.3.6",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-24.3.6.tgz",
"integrity": "sha512-WOVH4TIaBLIeCX576rLcOgjNXqP+jNlCiEmRgFTfQtJ52DpwnIQKAVGlGPAN7CZ33bW6eNfHD6s8ZbEUTQubJg==",
"dev": true,
"requires": {
"@typescript-eslint/experimental-utils": "^4.0.1"
}
},
"eslint-plugin-prettier": { "eslint-plugin-prettier": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.4.0.tgz",
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
"dotenv-webpack": "7.0.2", "dotenv-webpack": "7.0.2",
"eslint": "7.27.0", "eslint": "7.27.0",
"eslint-config-prettier": "8.3.0", "eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-prettier": "3.4.0", "eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.23.2", "eslint-plugin-react": "7.23.2",
"eslint-plugin-react-hooks": "4.2.0", "eslint-plugin-react-hooks": "4.2.0",
......
...@@ -20,11 +20,14 @@ import faker from 'faker'; ...@@ -20,11 +20,14 @@ import faker from 'faker';
import windowService from 'src/services/window-service'; import windowService from 'src/services/window-service';
class MockWindow { class MockWindow {
private subscribers: { [name: string]: Function[] } = {}; private subscribers: { [name: string]: ((payload?: any) => void)[] } = {};
public postMessage = jest.fn(); public postMessage = jest.fn();
public addEventListener = (name: string, callback: Function) => { public addEventListener = (
name: string,
callback: (payload?: any) => void
) => {
if (!this.subscribers[name]) { if (!this.subscribers[name]) {
this.subscribers[name] = []; this.subscribers[name] = [];
} }
......
...@@ -70,11 +70,13 @@ export class BrowserMessagingService { ...@@ -70,11 +70,13 @@ export class BrowserMessagingService {
} }
const subscribers = this.subscribers[type]; const subscribers = this.subscribers[type];
if (subscribers) { if (subscribers) {
subscribers.forEach((subscriber: Function) => subscriber(payload)); subscribers.forEach((subscriber: (payload?: any) => void) =>
subscriber(payload)
);
} }
}; };
public subscribe = (eventName: string, callback: Function) => { public subscribe = (eventName: string, callback: (payload?: any) => void) => {
if (!this.subscribers[eventName]) { if (!this.subscribers[eventName]) {
this.subscribers[eventName] = new Set(); this.subscribers[eventName] = new Set();
} }
......
...@@ -46,7 +46,7 @@ describe('<TrackPanelTabs />', () => { ...@@ -46,7 +46,7 @@ describe('<TrackPanelTabs />', () => {
const tabs = [...container.querySelectorAll('.trackPanelTab')]; const tabs = [...container.querySelectorAll('.trackPanelTab')];
tabValues.forEach((text) => { tabValues.forEach((text) => {
expect(tabs.some((tab) => tab.innerHTML === text)); expect(tabs.some((tab) => tab.innerHTML === text)).toBeTruthy();
}); });
}); });
}); });
......
...@@ -61,9 +61,8 @@ describe('<ZmenuContent />', () => { ...@@ -61,9 +61,8 @@ describe('<ZmenuContent />', () => {
const { container } = renderZmenuContent(); const { container } = renderZmenuContent();
const zmenuContentLine = defaultProps.content[0].lines[0]; const zmenuContentLine = defaultProps.content[0].lines[0];
const renderedContentBlocks = container.querySelectorAll( const renderedContentBlocks =
'.zmenuContentBlock' container.querySelectorAll('.zmenuContentBlock');
);
// check that the number of blocks of text is correct // check that the number of blocks of text is correct
expect(renderedContentBlocks.length).toBe(zmenuContentLine.length); expect(renderedContentBlocks.length).toBe(zmenuContentLine.length);
...@@ -76,14 +75,19 @@ describe('<ZmenuContent />', () => { ...@@ -76,14 +75,19 @@ describe('<ZmenuContent />', () => {
zmenuContentLine.forEach((block, blockIndex) => { zmenuContentLine.forEach((block, blockIndex) => {
block.forEach((blockItem, blockItemIndex) => { block.forEach((blockItem, blockItemIndex) => {
const renderedElement = renderedContentBlocks[ const renderedElement =
blockIndex renderedContentBlocks[blockIndex].querySelectorAll('span')[
].querySelectorAll('span')[blockItemIndex]; blockItemIndex
];
if (blockItem.markup.includes(Markup.LIGHT)) { if (blockItem.markup.includes(Markup.LIGHT)) {
expect(renderedElement.classList.contains('markupLight')); expect(
renderedElement.classList.contains('markupLight')
).toBeTruthy();
} }
if (blockItem.markup.includes(Markup.STRONG)) { if (blockItem.markup.includes(Markup.STRONG)) {
expect(renderedElement.classList.contains('markupStrong')); expect(
renderedElement.classList.contains('markupStrong')
).toBeTruthy();
} }
}); });
}); });
......
...@@ -54,7 +54,7 @@ describe('BadgedButton', () => { ...@@ -54,7 +54,7 @@ describe('BadgedButton', () => {
container container
.querySelector('.badgeDefault') .querySelector('.badgeDefault')
?.classList.contains(fakeClassName) ?.classList.contains(fakeClassName)
).toBeTruthy; ).toBeTruthy();
}); });
it('trims the longer strings to three characters', () => { it('trims the longer strings to three characters', () => {
......
...@@ -37,7 +37,9 @@ describe('fasta formatter', () => { ...@@ -37,7 +37,9 @@ describe('fasta formatter', () => {
const [firstLine, ...sequenceLines] = fastaFormattedSequence.split('\n'); const [firstLine, ...sequenceLines] = fastaFormattedSequence.split('\n');
expect(firstLine).toBe(`>${sequenceLabel}`); expect(firstLine).toBe(`>${sequenceLabel}`);
expect(sequenceLines.every((line) => line.length <= LINE_LENGTH)); expect(
sequenceLines.every((line) => line.length <= LINE_LENGTH)
).toBeTruthy();
expect(sequenceLines.join('')).toBe(rawSequence); expect(sequenceLines.join('')).toBe(rawSequence);
}); });
}); });
...@@ -117,25 +117,6 @@ describe('getCommaSeparatedNumber', () => { ...@@ -117,25 +117,6 @@ describe('getCommaSeparatedNumber', () => {
expect(Number(numberSplitByComma.join(''))).toBe(randomNumber); expect(Number(numberSplitByComma.join(''))).toBe(randomNumber);
}); });
it('returns -x,xxx for the input number -xxxx', () => {
const randomNumber = faker.datatype.number({ min: -9999, max: -1000 });
const formattedRandomNumber = getCommaSeparatedNumber(randomNumber);
const numberSplitByComma = formattedRandomNumber.split(',');
// Check if there are two elements in the array
expect(numberSplitByComma.length).toBe(2);
// Check if the length of the first element is 2
expect(numberSplitByComma[0].length).toBe(2);
// Check if the length of the second element is 3
expect(numberSplitByComma[1].length).toBe(3);
expect(Number(numberSplitByComma.join(''))).toBe(randomNumber);
});
it('returns x,xxx.x for the input number xxxx.x', () => { it('returns x,xxx.x for the input number xxxx.x', () => {
const randomNumber = const randomNumber =
faker.datatype.number({ min: 1000, max: 9999 }) + faker.datatype.number({ min: 1000, max: 9999 }) +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment