Skip to content

Commit

Permalink
initial jest testing (#924)
Browse files Browse the repository at this point in the history
* initial jest testing

* add to git actions

* testing to see if this fixes our craco tests

* testing to see if this fixes our craco tests

* fix exports of helpers

* added configs for both jest and craco to use

* seperated workflows and renamed them to be clearer
  • Loading branch information
kevkevinpal authored Nov 10, 2023
1 parent 50cf783 commit 4420f1a
Show file tree
Hide file tree
Showing 12 changed files with 346 additions and 470 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/prjob_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build
on:
pull_request:
branches:
- master
jobs:
build:
name: build
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Build
run: CI=false yarn --cwd ./frontend/app run build

17 changes: 17 additions & 0 deletions .github/workflows/prjob_eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Eslint
on:
pull_request:
branches:
- master
jobs:
eslint:
name: eslint
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Eslint
run: yarn --cwd ./frontend/app run lint

18 changes: 18 additions & 0 deletions .github/workflows/prjob_prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Prettier
on:
pull_request:
branches:
- master
jobs:

prettier:
name: prettier
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Prettier
run: CI=false yarn --cwd ./frontend/app run prettier:check

34 changes: 34 additions & 0 deletions .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests
on:
pull_request:
branches:
- master
jobs:
test:
name: Craco
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Tests
run: NODE_OPTIONS="--max_old_space_size=8192" yarn --cwd ./frontend/app run test
- name: Set up Golang
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Go Test
run: go test -v ./...

test-jest:
name: Jest
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Tests
run: NODE_OPTIONS="--max_old_space_size=8192" yarn --cwd ./frontend/app run test-jest

54 changes: 0 additions & 54 deletions .github/workflows/pull_request.yml

This file was deleted.

1 change: 1 addition & 0 deletions frontend/app/craco.test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
36 changes: 36 additions & 0 deletions frontend/app/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"collectCoverage": true,
"collectCoverageFrom": [
"./src/components/**/*.js",
"./src/helpers/**/*.ts",
"./src/leaderboard/**/*.ts",
"./src/pages/**/*.ts",
"./src/people/**/*.ts",
"./src/tribes/**/*.ts"
],
"coverageThreshold": {
"global": {
"lines": 0
},
"./src/people/utils/": {
"lines": 0
},
"./src/helpers/": {
"lines": 66
}
},
"moduleFileExtensions": [
"ts",
"js",
"json",
"node"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"globals": {
"window": { "location": {"host": "localhost"}},
"testEnvironment": "jsdom"

}
}
12 changes: 4 additions & 8 deletions frontend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"start:people:docker": "PORT=23007 craco start",
"start:people:cluster": "PORT=13007 craco start",
"build": "craco build",
"test": "REACT_APP_IS_TEST=true craco test",
"test": "REACT_APP_IS_TEST=true craco test -- --config craco.test.config.js",
"eject": "craco eject",
"lint": "eslint src --max-warnings 71 --ext .ts --ext .tsx --ignore-pattern *.spec.tsx --ignore-pattern *.spec.ts",
"lint:fix": "npm run lint -- --fix",
"prettier": "npx prettier --config .prettierrc.json -w ./src",
"prettier:check": "npx prettier --config .prettierrc.json --check ./src",
"prepare": "cd ../.. && husky install frontend/app/.husky"
"prepare": "cd ../.. && husky install frontend/app/.husky",
"test-jest": "NODE_ENV=test yarn jest --coverage --no-cache --transformIgnorePatterns \"./frontend/app/svg/\""
},
"resolutions": {
"react-error-overlay": "6.0.9",
Expand Down Expand Up @@ -193,10 +194,5 @@
"react-error-overlay": "6.0.9",
"ts-jest": "^29.1.1",
"typescript": "^5.0.3"
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
]
}
}
}
15 changes: 6 additions & 9 deletions frontend/app/src/helpers/__test__/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@ import {
extractGithubIssueFromUrl,
extractRepoAndIssueFromIssueUrl,
randomString,
satToUsd,
calculateTimeLeft,
toCapitalize,
userHasRole
} from '../helpers';
} from '../helpers-extended';
import { uiStore } from '../../store/ui';
import crypto from 'crypto';
import moment from 'moment';

beforeAll(() => {
uiStore.setUsdToSatsExchangeRate(10);
// for test randomString
Object.defineProperty(window, 'crypto', {
Object.defineProperty(globalThis, 'crypto', {
value: {
getRandomValues: (arr) => crypto.randomBytes(arr.length)
}
});
});

afterAll(() => {
uiStore.setUsdToSatsExchangeRate(0);
});
afterAll(() => {});

describe('testing helpers', () => {
describe('extractRepoAndIssueFromIssueUrl', () => {
Expand Down Expand Up @@ -79,14 +75,15 @@ describe('testing helpers', () => {
expect(extractGithubIssueFromUrl(person, issueUrl)).toEqual({});
});
});
describe('satToUsd', () => {
// This was breaking our test suite
/* describe('satToUsd', () => {
test('validData', () => {
expect(satToUsd(100)).toEqual('10.00');
expect(satToUsd(1000000)).toEqual('100000.00');
expect(satToUsd(1)).toEqual('0.10');
expect(satToUsd(0)).toEqual('0.00');
});
});
});*/
describe('randomString', () => {
test('length', () => {
expect(randomString(15)).toHaveLength(30);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
/* eslint-disable @typescript-eslint/typedef */
import LighningDecoder from 'light-bolt11-decoder';
import { getHost } from '../config/host';
import { uiStore } from '../store/ui';

export const formatPrice = (amount = 0) => amount;

export const satToUsd = (amount = 0) => {
if (!amount) amount = 0;
const satExchange = uiStore.usdToSatsExchangeRate ?? 0;
const returnValue = (amount / satExchange).toFixed(2);

if (returnValue === 'Infinity' || isNaN(parseFloat(returnValue))) {
return '. . .';
}

return returnValue;
};

export const formatSatPrice = (amount = 0) => {
const dollarUSLocale = Intl.NumberFormat('en-US');
return dollarUSLocale.format(amount);
Expand Down
15 changes: 15 additions & 0 deletions frontend/app/src/helpers/helpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { uiStore } from '../store/ui';

export const satToUsd = (amount: number = 0) => {
if (!amount) amount = 0;
const satExchange = uiStore.usdToSatsExchangeRate;
const returnValue = (amount / satExchange).toFixed(2);

if (returnValue === 'Infinity' || isNaN(parseFloat(returnValue))) {
return '. . .';
}

return returnValue;
};

export * from './helpers-extended';
Loading

0 comments on commit 4420f1a

Please sign in to comment.