Skip to content

Commit

Permalink
fix tests for all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
onursumer committed Oct 20, 2021
1 parent e133380 commit 0bb71f9
Show file tree
Hide file tree
Showing 47 changed files with 461 additions and 3,240 deletions.
1 change: 1 addition & 0 deletions fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
27 changes: 27 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { InitialOptionsTsJest } from 'ts-jest/dist/types';

const config: InitialOptionsTsJest = {
preset: 'ts-jest/presets/js-with-ts',
moduleNameMapper: {
'\\.(css|sass|less|scss)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/fileMock.js',
'^containers(.*)$': '<rootDir>/src/containers$1',
'^components(.*)$': '<rootDir>/src/components$1',
'^config(.*)$': '<rootDir>/src/config$1',
'^utils(.*)$': '<rootDir>/src/utils$1',
'^styles(.*)$': '<rootDir>/src/styles$1',
'^pages(.*)$': '<rootDir>/src/pages$1',
'^shared(.*)$': '<rootDir>/src/shared$1',
'^test(.*)$': '<rootDir>/src/test$1',
},
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
},
setupFiles: ['<rootDir>/src/setupTests.ts', 'jest-canvas-mock'],
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/src/**/*.spec.tsx'],
};

export default config;
29 changes: 2 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
"word-wrap": "^1.2.3"
},
"devDependencies": {
"@testing-library/react": "^12.1.0",
"@types/cheerio": "^0.22.23",
"argparse": "^1.0.9",
"babel-plugin-rewire": "^1.0.0",
Expand All @@ -350,35 +351,9 @@
"request": "^2.88.0",
"sinon": "^4.1.3",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"swagger-js-codegen": "git+https://github.com/cBioPortal/swagger-js-codegen.git#0362f4a1e2d116ad6dffc36e4b57cdfbc93956cf",
"webpack-dev-server": "^4.1.0",
"yargs": "^6.6.0"
},
"jest": {
"preset": "ts-jest/presets/js-with-ts",
"moduleNameMapper": {
"\\.(css|sass|scss|png|svg)$": "identity-obj-proxy",
"^containers(.*)$": "<rootDir>/src/containers$1",
"^components(.*)$": "<rootDir>/src/components$1",
"^config(.*)$": "<rootDir>/src/config$1",
"^utils(.*)$": "<rootDir>/src/utils$1",
"^styles(.*)$": "<rootDir>/src/styles$1",
"^pages(.*)$": "<rootDir>/src/pages$1",
"^shared(.*)$": "<rootDir>/src/shared$1",
"^test(.*)$": "<rootDir>/src/test$1"
},
"globals": {
"ts-jest": {
"tsconfig": "<rootDir>/tsconfig.test.json"
}
},
"setupFiles": [
"<rootDir>/src/setupTests.ts",
"jest-canvas-mock"
],
"testMatch": [
"<rootDir>/src/**/*.spec.ts",
"<rootDir>/src/**/*.spec.tsx"
]
}
}
2 changes: 2 additions & 0 deletions packages/cbioportal-clinical-timeline/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../config/jest.config';
export default config;
6 changes: 1 addition & 5 deletions packages/cbioportal-clinical-timeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"tcm": "tcm -p src/**/*.module.scss",
"tcm:watch": "yarn run tcm --watch",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom",
"test:watch": "yarn run test --watch"
},
"peerDependencies": {
Expand All @@ -44,9 +44,5 @@
"react-bootstrap": "^0.31.5",
"react-overlays": "0.7.4",
"typescript": "4.0.3"
},
"devDependencies": {
"@testing-library/react": "^9.3.2",
"react-scripts-ts": "^3.1.0"
}
}
5 changes: 2 additions & 3 deletions packages/cbioportal-clinical-timeline/src/lib/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assert } from 'chai';
import * as _ from 'lodash';
import {
formatDate,
getAttributeValue,
Expand All @@ -9,7 +8,7 @@ import intersect from './intersect';
import { TimelineEvent } from '../types';

describe('getPointInTrimmedSpace', () => {
let ticks;
let ticks: any;

beforeEach(() => {
ticks = [
Expand Down Expand Up @@ -195,7 +194,7 @@ describe('getAttributeValue', () => {
],
startNumberOfDaysSinceDiagnosis: 13524,
},
};
} as any;

assert.equal(
getAttributeValue('CANCER_TYPE_DETAILED', event),
Expand Down
2 changes: 0 additions & 2 deletions packages/cbioportal-clinical-timeline/src/lib/intersect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as _ from 'lodash';

function normalizeInterval(start: number, end: number) {
return { start: Math.min(start, end), end: Math.max(start, end) };
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cbioportal-frontend-commons/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../config/jest.config';
export default config;
6 changes: 1 addition & 5 deletions packages/cbioportal-frontend-commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"tcm": "tcm -p src/**/*.module.scss",
"tcm:watch": "yarn run tcm --watch",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom",
"test:watch": "yarn run test --watch"
},
"peerDependencies": {
Expand Down Expand Up @@ -59,9 +59,5 @@
"typescript": "4.0.3",
"url": "^0.11.0",
"victory": "30.0.0"
},
"devDependencies": {
"@testing-library/react": "^9.3.2",
"react-scripts-ts": "^3.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import _ from 'lodash';
import * as React from 'react';
import classNames from 'classnames';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import autobind from 'autobind-decorator';
import * as _ from 'lodash';
import _ from 'lodash';
import { action, computed, makeObservable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from 'chai';
import * as _ from 'lodash';
import _ from 'lodash';
import {
ISimpleColumnVisibilityDef,
resolveColumnVisibility,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import _ from 'lodash';

export enum CanonicalMutationType {
MISSENSE = 'missense',
Expand Down
2 changes: 1 addition & 1 deletion packages/cbioportal-ts-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rollup": "rollup -c rollup.config.ts",
"rollup:watch": "rollup -c rollup.config.ts -w",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom --passWithNoTests",
"test:watch": "yarn run test -- --watch"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/cbioportal-utils/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../config/jest.config';
export default config;
6 changes: 1 addition & 5 deletions packages/cbioportal-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rollup": "rollup -c rollup.config.ts",
"rollup:watch": "rollup -c rollup.config.ts -w",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom",
"test:watch": "yarn run test -- --watch"
},
"dependencies": {
Expand All @@ -34,9 +34,5 @@
"oncokb-ts-api-client": "^1.1.7",
"superagent": "^3.8.3",
"typescript": "4.0.3"
},
"devDependencies": {
"@testing-library/react": "^9.3.2",
"react-scripts-ts": "^3.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/cbioportal-utils/src/civic/CivicUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import _ from 'lodash';

import CivicDataFetcher from './CivicDataFetcher';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import _ from 'lodash';
import { Hotspot } from 'genome-nexus-ts-api-client';

import { AggregatedHotspots, IHotspotIndex } from '../model/CancerHotspot';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert } from 'chai';
import * as _ from 'lodash';
import _ from 'lodash';

import { VariantAnnotation } from 'genome-nexus-ts-api-client';

Expand Down
8 changes: 4 additions & 4 deletions packages/cbioportal-utils/src/mutation/MutationUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ describe('MutationUtils', () => {
);

assert.equal(
mutationCountByProteinChange['66'].length,
mutationCountByProteinChange[66].length,
5,
'there should be 5 mutations at posititon 66'
);

assert.equal(
mutationCountByProteinChange['666'].length,
mutationCountByProteinChange[666].length,
2,
'there should be 2 mutations at posititon 666'
);

assert.deepEqual(
mutationCountByProteinChange['666'][0],
mutationCountByProteinChange[666][0],
{ proteinPosStart: 666, proteinChange: 'D666C' },
'first mutation at pos 666 should be D666C'
);
assert.deepEqual(
mutationCountByProteinChange['666'][1],
mutationCountByProteinChange[666][1],
{ proteinPosStart: 666, proteinChange: 'D666F' },
'second mutation at pos 666 should be D666F'
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cbioportal-utils/src/ptm/PtmUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash';
import _ from 'lodash';

import { PostTranslationalModification as DbPtm } from 'genome-nexus-ts-api-client';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/config/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
19 changes: 19 additions & 0 deletions packages/config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { InitialOptionsTsJest } from 'ts-jest/dist/types';

const config: InitialOptionsTsJest = {
preset: 'ts-jest/presets/js-with-ts',
moduleNameMapper: {
'\\.(css|sass|less|scss)$': 'identity-obj-proxy',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/../config/fileMock.js',
},
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.test.json',
},
},
setupFiles: ['jest-canvas-mock', '<rootDir>/../config/setupTests.ts'],
testMatch: ['<rootDir>/src/**/*.spec.ts', '<rootDir>/src/**/*.spec.tsx'],
};

export default config;
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// TODO update @types to fix the TS errors
//@ts-ignore
import { configure } from 'enzyme';
//@ts-ignore
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });
4 changes: 3 additions & 1 deletion packages/config/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"types": ["jest", "node"]
"types": ["jest", "node"],
"allowJs": true,
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion packages/genome-nexus-ts-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rollup": "rollup -c rollup.config.ts",
"rollup:watch": "rollup -c rollup.config.ts -w",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom --passWithNoTests",
"test:watch": "yarn run test -- --watch"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/oncokb-ts-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"rollup": "rollup -c rollup.config.ts",
"rollup:watch": "rollup -c rollup.config.ts -w",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom --passWithNoTests",
"test:watch": "yarn run test -- --watch"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-mutation-mapper/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import config from '../config/jest.config';
export default config;
6 changes: 1 addition & 5 deletions packages/react-mutation-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"tcm": "tcm -p src/**/*.module.scss",
"tcm:watch": "yarn run tcm --watch",
"prepare": "yarn run build",
"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test": "cross-env CI=1 jest --env=jsdom",
"test:watch": "yarn run test --watch"
},
"peerDependencies": {
Expand Down Expand Up @@ -58,9 +58,5 @@
"seamless-immutable": "^7.1.4",
"superagent": "^3.8.3",
"typescript": "4.0.3"
},
"devDependencies": {
"@testing-library/react": "^9.3.2",
"react-scripts-ts": "^3.1.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export function getExpectedCivicEntry() {
'PIK3CA E545K/E542K are the second most recurrent PIK3CA mutations in breast cancer, and are highly recurrent mutations in many other cancer types. E545K, and possibly the other mutations in the E545 region, may present patients with a poorer prognosis than patients with either patients with other PIK3CA variant or wild-type PIK3CA. There is also data to suggest that E545/542 mutations may confer resistance to EGFR inhibitors like cetuximab. While very prevalent, targeted therapies for variants in PIK3CA are still in early clinical trial phases.',
url:
'https://civicdb.org/events/genes/37/summary/variants/104/summary#variant',
evidence: { Prognostic: 1, Predictive: 14 },
evidenceCounts: { Prognostic: 1, Predictive: 14 },
evidences: [],
},
},
};
Expand All @@ -38,7 +39,8 @@ export function getExpectedCnaCivicEntry() {
description: '',
url:
'https://civicdb.org/events/genes/4767/summary/variants/591/summary#variant',
evidence: { Predictive: 1 },
evidenceCounts: { Predictive: 1 },
evidences: [],
},
},
};
Expand All @@ -61,11 +63,11 @@ describe('Civic with no data', () => {

describe('Civic with data with variants', () => {
it('displays the correct Civic icon', () => {
const props = {
const props: ICivicProps = {
civicEntry: getExpectedCivicEntry(),
civicStatus: 'complete',
hasCivicVariants: true,
} as ICivicProps;
} as any;

const component = render(<Civic {...props} />);
const civicIcon = component.container.getElementsByTagName('img');
Expand Down Expand Up @@ -95,11 +97,11 @@ describe('Civic with data with variants', () => {

describe('Civic with data with no variants', () => {
it('displays the correct Civic icon', () => {
const props = {
const props: ICivicProps = {
civicEntry: getExpectedCnaCivicEntry(),
civicStatus: 'complete',
hasCivicVariants: false,
} as ICivicProps;
} as any;

const component = render(<Civic {...props} />);
const civicIcon = component.container.getElementsByTagName('img');
Expand Down Expand Up @@ -129,7 +131,7 @@ describe('Civic with data with no variants', () => {

describe('Counts correctly', () => {
it('Gives 1 point per entry', () => {
const value = sortValue(getExpectedCnaCivicEntry());
const value = sortValue(getExpectedCnaCivicEntry() as any);

assert.equal(value, 1, 'Correctly gives 1 point for an entry');
});
Expand Down
Loading

0 comments on commit 0bb71f9

Please sign in to comment.