Skip to content

Commit

Permalink
refactor(test): Replace Jasmine with Jest (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode authored Dec 27, 2021
1 parent b478e79 commit d8d9740
Show file tree
Hide file tree
Showing 36 changed files with 2,060 additions and 534,913 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ on:
- 'v*.*.*'

jobs:
build:
release:
runs-on: ubuntu-latest
steps:
- name: Release
- name: 'Create Release'
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
1 change: 1 addition & 0 deletions .github/workflows/merge-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
steps:
- name: 'Checkout repository'
uses: actions/[email protected]

- name: 'Automerge dependency updates from Dependabot'
uses: ahmadnassri/[email protected]
# Guarantee that commit comes from Dependabot (don't blindly trust external GitHub Actions)
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ on:
- main

jobs:
build:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout repository
- name: 'Checkout repository'
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install, lint, and test

- name: 'Install, lint, and test'
run: |
yarn install
yarn lint
yarn test
if: |
contains(github.event.commits[0].message, '[skip ci]') == false &&
contains(github.event.commits[0].message, '[ci skip]') == false
- name: Upload coverage reports to Codecov
- name: 'Upload coverage reports to Codecov'
uses: codecov/[email protected]
with:
fail_ci_if_error: false
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.cache
.DS_Store
.idea/
.nyc_output/
.vscode/
.yarnclean
config.json
Expand Down
6 changes: 0 additions & 6 deletions jasmine.json

This file was deleted.

17 changes: 17 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"collectCoverage": false,
"collectCoverageFrom": ["**/*.{ts,tsx}", "!**/*.d.ts", "!**/index.ts", "!**/start*.ts"],
"coverageReporters": ["html", "lcov", "text"],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"preset": "ts-jest",
"setupFilesAfterEnv": [],
"testEnvironment": "node",
"testRegex": "\\.test\\.tsx?$"
}
15 changes: 0 additions & 15 deletions nyc.config.coverage.json

This file was deleted.

10 changes: 0 additions & 10 deletions nyc.config.json

This file was deleted.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"description": "Technical indicators to run technical analysis with JavaScript / TypeScript.",
"devDependencies": {
"@types/benchmark": "2.1.1",
"@types/jasmine": "3.10.2",
"@types/jest": "27.0.3",
"@types/node": "16.11.13",
"@typescript-eslint/eslint-plugin": "5.7.0",
"@typescript-eslint/parser": "5.7.0",
"@typescript-eslint/eslint-plugin": "5.8.1",
"@typescript-eslint/parser": "5.8.1",
"benchmark": "2.1.4",
"eslint": "8.4.1",
"eslint": "8.5.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-typescript-sort-keys": "2.1.0",
"generate-changelog": "1.8.0",
"husky": "4.3.8",
"jasmine": "3.10.0",
"lint-staged": "12.1.2",
"nyc": "15.1.0",
"jest": "27.4.5",
"lint-staged": "12.1.4",
"prettier": "2.5.1",
"pretty-quick": "3.1.2",
"pretty-quick": "3.1.3",
"rimraf": "3.0.2",
"ts-jest": "27.1.2",
"ts-node": "10.4.0",
"typescript": "4.5.4"
},
Expand Down Expand Up @@ -75,7 +75,7 @@
"scripts": {
"build": "tsc",
"changelog:commit": "git add CHANGELOG.md && git commit -m \"docs: updated CHANGELOG.md\"",
"clean": "rimraf .nyc_output coverage dist",
"clean": "rimraf coverage dist",
"dist": "yarn clean && yarn build",
"fix": "yarn fix:other && yarn fix:code",
"fix:code": "yarn lint:code --fix",
Expand All @@ -91,8 +91,8 @@
"release:minor": "generate-changelog -m -x \"chore,test\" && yarn changelog:commit && npm version minor",
"release:patch": "generate-changelog -p -x \"chore,test\" && yarn changelog:commit && npm version patch",
"start:benchmark": "ts-node ./src/start/startBenchmark.ts",
"test": "nyc --nycrc-path=nyc.config.coverage.json jasmine --config=jasmine.json",
"test:dev": "nyc --nycrc-path=nyc.config.json jasmine --config=jasmine.json",
"test": "yarn test:dev --coverage",
"test:dev": "jest ./src",
"test:types": "yarn lint:types"
},
"version": "3.4.0"
Expand Down
8 changes: 4 additions & 4 deletions src/ABANDS/AccelerationBands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('AccelerationBands', () => {
describe('getResult', () => {
it('returns upper, middle and lower bands', () => {
const accBands = new AccelerationBands(20, 4);
expect(accBands.isStable).toBeFalse();
expect(accBands.isStable).toBe(false);

const fasterAccBands = new FasterAccelerationBands(20, 4);
expect(fasterAccBands.isStable).toBeFalse();
expect(fasterAccBands.isStable).toBe(false);

// Test data from: https://github.com/QuantConnect/Lean/blob/master/Tests/TestData/spy_acceleration_bands_20_4.txt
const candles = [
Expand Down Expand Up @@ -56,8 +56,8 @@ describe('AccelerationBands', () => {
let fasterResult = fasterAccBands.getResult();

// See: https://github.com/QuantConnect/Lean/blob/master/Tests/TestData/spy_acceleration_bands_20_4.txt#L21
expect(accBands.isStable).toBeTrue();
expect(fasterAccBands.isStable).toBeTrue();
expect(accBands.isStable).toBe(true);
expect(fasterAccBands.isStable).toBe(true);

expect(result.lower.toFixed(4)).toBe('187.6891');
expect(fasterResult.lower.toFixed(4)).toBe('187.6891');
Expand Down
4 changes: 2 additions & 2 deletions src/AC/AC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ describe('AC', () => {

// Result verified with:
// https://github.com/jesse-ai/jesse/blob/53297462d48ebf43f9df46ab5005076d25073e5e/tests/test_indicators.py#L14
expect(ac.isStable).toBeTrue();
expect(fasterAC.isStable).toBeTrue();
expect(ac.isStable).toBe(true);
expect(fasterAC.isStable).toBe(true);

expect(ac.getResult().toFixed(2)).toBe('-21.97');
expect(fasterAC.getResult().toFixed(2)).toBe('-21.97');
Expand Down
8 changes: 4 additions & 4 deletions src/ADX/ADX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('ADX', () => {
}
}

expect(adx.isStable).toBeTrue();
expect(fasterADX.isStable).toBeTrue();
expect(adx.isStable).toBe(true);
expect(fasterADX.isStable).toBe(true);

expect(adx.getResult().toFixed(2)).toBe('67.36');
expect(fasterADX.getResult().toFixed(2)).toBe('67.36');
Expand All @@ -51,8 +51,8 @@ describe('ADX', () => {
expect(fasterADX.highest!.toFixed(2)).toBe('67.36');

// Verify uptrend detection (+DI > -DI):
expect(adx.pdi!.gt(adx.mdi!)).toBeTrue();
expect(fasterADX.pdi > fasterADX.mdi).toBeTrue();
expect(adx.pdi!.gt(adx.mdi!)).toBe(true);
expect(fasterADX.pdi > fasterADX.mdi).toBe(true);

expect(adx.pdi!.toFixed(2)).toBe('0.42');
expect(fasterADX.pdi!.toFixed(2)).toBe('0.42');
Expand Down
4 changes: 2 additions & 2 deletions src/ATR/ATR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('ATR', () => {
}
}

expect(atr.isStable).toBeTrue();
expect(fasterATR.isStable).toBeTrue();
expect(atr.isStable).toBe(true);
expect(fasterATR.isStable).toBe(true);

expect(atr.getResult().toFixed(2)).toBe('1.14');
expect(fasterATR.getResult().toFixed(2)).toBe('1.14');
Expand Down
2 changes: 1 addition & 1 deletion src/BBANDS/BollingerBands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('FasterBollingerBands', () => {
for (const price of prices) {
fasterBB.update(price);
}
expect(fasterBB.isStable).toBeTrue();
expect(fasterBB.isStable).toBe(true);
const actual = fasterBB.getResult();
expect(actual.lower.toFixed(2)).toBe('85.29');
expect(actual.middle.toFixed(2)).toBe('86.80');
Expand Down
14 changes: 7 additions & 7 deletions src/CG/CG.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe('CG', () => {
cg.update(20);
cg.update(30);
cg.update(40);
expect(cg.isStable).toBeFalse();
expect(cg.isStable).toBe(false);
cg.update(50);
expect(cg.isStable).toBeFalse();
expect(cg.isStable).toBe(false);
cg.update(60);
expect(cg.isStable).toBeTrue();
expect(cg.isStable).toBe(true);
});
});

Expand All @@ -45,18 +45,18 @@ describe('CG', () => {
}
let cgResult = cg.getResult();
let signalResult = cg.signal.getResult();
expect(cgResult.gt(signalResult)).toBeTrue();
expect(cgResult.gt(signalResult)).toBe(true);
[150, 110, 90, 130].forEach(price => {
cg.update(price);
fasterCG.update(price);
});

expect(cg.isStable).toBeTrue();
expect(fasterCG.isStable).toBeTrue();
expect(cg.isStable).toBe(true);
expect(fasterCG.isStable).toBe(true);

cgResult = cg.getResult();
signalResult = cg.signal.getResult();
expect(cgResult.gt(signalResult)).toBeFalse();
expect(cgResult.gt(signalResult)).toBe(false);

expect(cgResult.toFixed(4)).toBe('2.7059');
expect(fasterCG.getResult().toFixed(4)).toBe('2.7059');
Expand Down
26 changes: 18 additions & 8 deletions src/DEMA/DEMA.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import {Big} from 'big.js';
import {DEMA, FasterDEMA} from './DEMA';

import prices from '../test/fixtures/prices.json';
import results from '../test/fixtures/DEMA/results.json';
import {NotEnoughDataError} from '../error';

const dema10results = results.interval_10;
const dema10results = [
81, 62.157024793388416, 65.1412471825695, 49.61361928829999, 42.570707415663364, 34.597495090487996,
44.47997295246192, 58.6168391922143, 71.4979863711489, 48.963944850563, 60.095241192962106, 66.41965473810654,
69.77997604557987, 49.75572911767095, 61.08641574881719, 65.56112611350791, 54.65374623818491, 57.51231851211959,
51.73955057939423, 36.941596820151815, 27.434153499662216, 24.890025210750593, 33.14097982029734, 30.163817870645254,
40.330715478873344, 45.63811915119551, 36.045947422710505, 53.12735486322183, 64.78921092296176, 72.9995704035162,
83.22304838955624, 58.85287916072168, 62.841348382387075, 42.93804766689409, 36.82301007497254, 26.454331684513562,
46.374329400503385, 53.28360623846342, 38.891184741941984,
];

describe('DEMA', () => {
describe('getResult', () => {
it('calculates the DEMA with interval 10', () => {
const prices = [
81, 24, 75, 21, 34, 25, 72, 92, 99, 2, 86, 80, 76, 8, 87, 75, 32, 65, 41, 9, 13, 26, 56, 28, 65, 58, 17, 90, 87,
86, 99, 3, 70, 1, 27, 9, 92, 68, 9,
];

const dema = new DEMA(10);
const fasterDEMA = new FasterDEMA(10);

Expand All @@ -23,8 +33,8 @@ describe('DEMA', () => {
}
});

expect(dema.isStable).toBeTrue();
expect(fasterDEMA.isStable).toBeTrue();
expect(dema.isStable).toBe(true);
expect(fasterDEMA.isStable).toBe(true);

expect(dema.lowest!.toFixed(2)).toBe('24.89');
expect(fasterDEMA.lowest!.toFixed(2)).toBe('24.89');
Expand All @@ -48,10 +58,10 @@ describe('DEMA', () => {
describe('isStable', () => {
it('is stable when there are enough inputs to fill the interval', () => {
const dema = new DEMA(2);
expect(dema.isStable).toBeFalse();
expect(dema.isStable).toBe(false);
dema.update(1);
dema.update(2);
expect(dema.isStable).toBeTrue();
expect(dema.isStable).toBe(true);
expect(dema.lowest!.toFixed(2)).toBe('1.00');
expect(dema.highest!.toFixed(2)).toBe('1.89');
});
Expand Down
22 changes: 11 additions & 11 deletions src/DMA/DMA.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ describe('DMA', () => {
dma.update(100);
dma.update(30.71);
dma.update(30);
expect(dma.getResult().short.toFixed(8)).withContext('short').toBe('53.57000000');
expect(dma.getResult().long.toFixed(8)).withContext('long').toBe('43.26833333');
expect(dma.getResult().short.toFixed(8)).toBe('53.57000000');
expect(dma.getResult().long.toFixed(8)).toBe('43.26833333');
});

it('can be used with exponential moving averages', () => {
Expand All @@ -24,8 +24,8 @@ describe('DMA', () => {
dma.update(100);
dma.update(30.71);
dma.update(30);
expect(dma.getResult().short.toFixed(8)).withContext('short').toBe('38.92125000');
expect(dma.getResult().long.toFixed(8)).withContext('long').toBe('41.96735289');
expect(dma.getResult().short.toFixed(8)).toBe('38.92125000');
expect(dma.getResult().long.toFixed(8)).toBe('41.96735289');
});
});

Expand All @@ -35,21 +35,21 @@ describe('DMA', () => {
dma.update(40);
dma.update(30);
dma.update(20);
expect(dma.isStable).toBeFalse();
expect(dma.isStable).toBe(false);
dma.update(10);
dma.update(30);
expect(dma.isStable).toBeTrue();
expect(dma.isStable).toBe(true);
});

it('is dependant on the long interval (EMA)', () => {
const dma = new DMA(3, 5, EMA);
dma.update(40);
dma.update(30);
dma.update(20);
expect(dma.isStable).toBeFalse();
expect(dma.isStable).toBe(false);
dma.update(10);
dma.update(30);
expect(dma.isStable).toBeTrue();
expect(dma.isStable).toBe(true);
});
});

Expand All @@ -66,11 +66,11 @@ describe('DMA', () => {
}

const {short, long} = dma.getResult();
expect(short.gt(long)).toBeTrue();
expect(short.gt(long)).toBe(true);

const fasterResult = fasterDMA.getResult();
expect(fasterDMA.isStable).toBeTrue();
expect(fasterResult.short > fasterResult.long).toBeTrue();
expect(fasterDMA.isStable).toBe(true);
expect(fasterResult.short > fasterResult.long).toBe(true);
});
});
});
Loading

0 comments on commit d8d9740

Please sign in to comment.