Skip to content

Commit

Permalink
Unit tests (#171)
Browse files Browse the repository at this point in the history
Adding Jest and some unit tests to components.

Tests can be executed from the root of the project with:

```
yarn test
```

Or from `./timeline-chart`, where the test outputs are formatted in a
more readable way:

```
cd timeline-chart
yarn test --verbose --watch
```

Current coverage:

/timeline-chart/src: 16.3%
/timeline-chart/src/components: 23.4%
/timeline-chart/src/layer: 0%

Signed-off-by: Rodrigo Pinto <rodrigo.pinto@calian.ca>
  • Loading branch information
Rodrigoplp-work authored Jan 5, 2022
1 parent 5330875 commit 863606e
Show file tree
Hide file tree
Showing 12 changed files with 4,109 additions and 59 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# LC_COLLATE=C sort
bundle.js
coverage
lib
node_modules
bundle.js
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,26 @@ For detailed description of the timeline chart library and it's components see [
The following list of applications are currently making use of the timeline-chart library;
* [Theia Trace Extension](https://github.com/theia-ide/theia-trace-extension)
* [Example Timeline Application](https://github.com/theia-ide/theia-timeline-extension)

# Tests

Tests can be executed from the root of the project with:

```
yarn test
```

Or from `./timeline-chart`, where the tests outputs are formatted in a more readable way:

```
cd timeline-chart
yarn test --verbose --watch
```

## Test coverage

The following command prints a coverage report to the terminal. As of now it covers all typescript files of the project, including those that are not supposed to have tests.

```shell
yarn test --coverage --collectCoverageFrom='src/**/*.ts'
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "lerna run build",
"watch": "lerna run watch",
"start": "lerna run start",
"test": "echo 'Should run tests'",
"test": "lerna run test --",
"publish:latest": "lerna publish --registry=https://registry.npmjs.org/ --exact --no-git-tag-version --no-push",
"publish:next": "lerna publish --registry=https://registry.npmjs.org/ --exact --canary minor --preid=next.$(git rev-parse --short HEAD) --dist-tag=next --no-git-tag-version --no-push --yes"
},
Expand All @@ -28,7 +28,7 @@
"devDependencies": {
"@types/pixi.js": "^5.0.0",
"lerna": "4.0.0",
"typescript": "^3.2.2"
"typescript": "latest"
},
"workspaces": [
"timeline-chart",
Expand Down
26 changes: 26 additions & 0 deletions timeline-chart/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"globals": {
"ts-jest": {
"tsconfig": "tsconfig.json"
}
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testEnvironment": "jsdom",
"testPathIgnorePatterns": [
"/lib/"
],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFilesAfterEnv": [
"jest-canvas-mock"
]
}
13 changes: 12 additions & 1 deletion timeline-chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"build": "tsc",
"watch": "tsc --watch",
"prepare": "yarn run clean && yarn run build",
"clean": "rimraf lib"
"clean": "rimraf lib",
"test": "jest --config jest.config.json"
},
"dependencies": {
"@types/lodash.throttle": "^4.1.4",
Expand All @@ -15,5 +16,15 @@
"lodash.throttle": "^4.1.1",
"pixi.js-legacy": "^5.3.3",
"rimraf": "latest"
},
"devDependencies": {
"@types/enzyme": "^3.10.10",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^27.0.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"jest": "^27.4.3",
"jest-canvas-mock": "^2.3.1",
"ts-jest": "^27.0.7"
}
}
Loading

0 comments on commit 863606e

Please sign in to comment.