Skip to content

Commit

Permalink
fix: Add eslint-plugin-chai-friendly and update package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Jan 8, 2024
1 parent fc66f37 commit 44a5e34
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 6 deletions.
10 changes: 9 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@
"lint:fix": "eslint --fix src/**/*.js"
},
"eslintConfig": {
"plugins": [
"chai-friendly"
],
"extends": [
"react-app",
"plugin:storybook/recommended"
]
],
"rules": {
"no-unused-expressions": 0,
"chai-friendly/no-unused-expressions": ["error", { "allowShortCircuit": true }]
}
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -73,6 +80,7 @@
"coverage-badges-cli": "^1.2.5",
"eslint": "^8.54.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-chai-friendly": "^0.7.2",
"eslint-plugin-storybook": "^0.6.15",
"happy-dom": "^12.10.3",
"history": "^5.3.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/AppBar/AppBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import AppBar from './AppBar';
import { BrowserRouter as Router } from 'react-router-dom';
import { vi } from 'vitest';

describe('AppBar', () => {

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Button/Button.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import Button from './Button';
import { vi } from 'vitest';

describe('Button component', () => {

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Consent/Consent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fireEvent, render, waitFor } from '@testing-library/react';
import Consent from './Consent';
import { useConsent } from '../../API'
import { saveAs } from 'file-saver';
import { vi } from 'vitest';

global.Blob = vi.fn().mockImplementation((content, options) => ({
content,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Playback/MatchingPairs.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render } from '@testing-library/react';
import MatchingPairs from './MatchingPairs';
import { vi } from 'vitest';

vi.mock("@/components/PlayButton/PlayCard", () => ({
default: props => <div data-testid="play-card" {...props} />
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Question/_ButtonArray.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import ButtonArray from './_ButtonArray';
import { vi } from 'vitest';

const getProps = (overrides = {}) => ({
question: {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Score/Score.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import Score from './Score';
import makeDefaultScoreProps from '../../util/testUtils/makeDefaultScoreProps';
import { vi } from 'vitest';

vi.useFakeTimers();

Expand Down
1 change: 1 addition & 0 deletions frontend/src/hooks/useResultHandler.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { renderHook, act } from "@testing-library/react";
import useResultHandler from "./useResultHandler";
import { vi } from 'vitest';

import * as API from '../API.js';

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/util/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ audio.controls = "controls";
audio.src = SILENT_MP3;

// switch to cors anonymous for local development (needed for webaudio)
API_ROOT === 'http://localhost:8000' ? audio.crossOrigin = "anonymous" : audio.crossorigin = "use-credentials";
audio.crossOrigin = API_ROOT === 'http://localhost:8000' ? "anonymous" : "use-credentials";

audio.disableRemotePlayback = true;
audio.style.display = "none";
Expand All @@ -36,7 +36,7 @@ export let audioInitialized = false;
export const init = () => {
load(SILENT_MP3);
play();
audioInitialized = true;
audioInitialized = true;
};

// init audio after first user action on page
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/util/testUtils/makeDefaultScoreProps.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { vi } from 'vitest';

const makeDefaultProps = (overrides = {}) => ({
last_song: 'Test Song',
score: 10,
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/util/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ export const Timer = ({

// timer finished
if (time === duration) {
onFinish && onFinish();
return;
return onFinish ? onFinish() : void 0;
}

// callback after interval
if (time - lastTime > interval) {
lastTime = time;

// tick
onTick && onTick(time, delta);
if (onTick) {
onTick(time, delta);
}
}

lastTimestamp = timestamp;
Expand Down
10 changes: 10 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6819,6 +6819,7 @@ __metadata:
email-validator: "npm:^2.0.4"
eslint: "npm:^8.54.0"
eslint-config-react-app: "npm:^7.0.1"
eslint-plugin-chai-friendly: "npm:^0.7.2"
eslint-plugin-storybook: "npm:^0.6.15"
file-saver: "npm:^2.0.5"
happy-dom: "npm:^12.10.3"
Expand Down Expand Up @@ -9082,6 +9083,15 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-chai-friendly@npm:^0.7.2":
version: 0.7.2
resolution: "eslint-plugin-chai-friendly@npm:0.7.2"
peerDependencies:
eslint: ">=3.0.0"
checksum: 44742cbbb4d95880824e2034d749d9f71799ce96308eb1376c8defededfb0c90a96048717bbb5a7ccd409956a8ac28ea5deee720159f0b2be6aa1318ef656776
languageName: node
linkType: hard

"eslint-plugin-flowtype@npm:^8.0.3":
version: 8.0.3
resolution: "eslint-plugin-flowtype@npm:8.0.3"
Expand Down

0 comments on commit 44a5e34

Please sign in to comment.