Skip to content

Commit 1cbcc8b

Browse files
committed
Add unit tests for data parsing
The specified Arduino plotter protocol is quite flexible, which means there multiple possible data formats which might be supplied by a user, all of which must be supported. In order to be able to continue the development of the project with confidence that no regressions will be introduced, good test coverage of the data formats is essential. Tests are added here. A GitHub Actions workflow will automatically run the tests after every relevant change as well as periodically to catch breakage that might result from external changes.
1 parent eac6d39 commit 1cbcc8b

File tree

6 files changed

+295
-17
lines changed

6 files changed

+295
-17
lines changed
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test TypeScript
2+
3+
env:
4+
# See: https://github.com/actions/setup-node/#readme
5+
NODE_VERSION: 10.x
6+
7+
on:
8+
push:
9+
paths:
10+
- ".github/workflows/test-typescript-npm.ya?ml"
11+
- ".github/.?codecov.ya?ml"
12+
- "dev/.?codecov.ya?ml"
13+
- ".?codecov.ya?ml"
14+
- "jest.config.js"
15+
- "package.json"
16+
- "package-lock.json"
17+
- "tsconfig.json"
18+
- "**.js"
19+
- "**.jsx"
20+
- "**.ts"
21+
- "**.tsx"
22+
pull_request:
23+
paths:
24+
- ".github/workflows/test-typescript-npm.ya?ml"
25+
- "jest.config.js"
26+
- "package.json"
27+
- "package-lock.json"
28+
- "tsconfig.json"
29+
- "**.js"
30+
- "**.jsx"
31+
- "**.ts"
32+
- "**.tsx"
33+
schedule:
34+
# Run periodically to catch breakage caused by external changes.
35+
- cron: "0 13 * * WED"
36+
workflow_dispatch:
37+
repository_dispatch:
38+
39+
jobs:
40+
test:
41+
runs-on: ${{ matrix.operating-system }}
42+
43+
strategy:
44+
fail-fast: false
45+
46+
matrix:
47+
operating-system:
48+
- macos-latest
49+
- ubuntu-latest
50+
# The version of node-gyp used by this project (7.1.2) requires an older version of Visual Studio that is not
51+
# available in the latest Windows GitHub Actions runner.
52+
- windows-2019
53+
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v3
57+
58+
- name: Setup Node.js
59+
uses: actions/setup-node@v3
60+
with:
61+
node-version: ${{ env.NODE_VERSION }}
62+
63+
- name: Install dependencies
64+
run: npm install
65+
66+
- name: Run tests
67+
run: npm run-script test
68+
69+
- name: Send unit test coverage to Codecov
70+
if: runner.os == 'Linux'
71+
uses: codecov/codecov-action@v3
72+
with:
73+
fail_ci_if_error: ${{ github.repository == 'arduino/arduino-serial-plotter-webapp' }}

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Serial Plotter WebApp
22

3+
[![Test TypeScript status](https://github.com/arduino/arduino-serial-plotter-webapp/actions/workflows/test-typescript-npm.yml/badge.svg)](https://github.com/arduino/arduino-serial-plotter-webapp/actions/workflows/test-typescript-npm.yml)
4+
35
This is a SPA that receives data points over WebSocket and prints graphs. The purpose is to provide a visual and live representation of data printed to the Serial Port.
46

57
The application is designed to be as agnostic as possible regarding how and where it runs. For this reason, it accepts different settings when it's launched in order to configure the look&feel and the connection parameters.
@@ -162,6 +164,7 @@ These are sent to the middleware to be stored and propagated to other clients.
162164
## Development
163165
164166
- `npm i` to install dependencies
167+
- `npm test` to run automated tests
165168
- `npm start` to run the application in development mode @ [http://localhost:3000](http://localhost:3000)
166169
167170
## Deployment

jest.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
collectCoverage: true,
8+
coverageDirectory: "coverage",
9+
coverageReporters: ["lcov"],
10+
preset: "ts-jest",
11+
testEnvironment: "node",
12+
};

package-lock.json

+63-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start": "react-scripts start",
88
"build": "react-scripts build",
9-
"test": "react-scripts test",
9+
"test": "jest",
1010
"eject": "react-scripts eject"
1111
},
1212
"files": [
@@ -49,6 +49,7 @@
4949
"chartjs-plugin-streaming": "^2.0.0",
5050
"eslint-config-prettier": "^8.3.0",
5151
"eslint-plugin-prettier": "^4.0.0",
52+
"jest": "^26.6.0",
5253
"luxon": "^2.1.0",
5354
"node-sass": "^6.0.1",
5455
"prettier": "^2.4.1",
@@ -60,6 +61,7 @@
6061
"react-scripts": "4.0.3",
6162
"react-select": "^5.1.0",
6263
"react-switch": "^6.0.0",
64+
"ts-jest": "^26.5.6",
6365
"typescript": "^4.4.3",
6466
"web-vitals": "^1.1.2",
6567
"worker-loader": "^3.0.8"

0 commit comments

Comments
 (0)