Skip to content

Commit 18488fc

Browse files
authored
improve test coverage part 1/2 (#20)
* add coverage * reformat mjml properly in readme * add test for label * add getLabel test * add package.json keywords * convert all rendered html to json for testability purpose * add tests for getChartTitle method * add test for render method * change code coverage action * change jest coverage config
1 parent 32231d6 commit 18488fc

10 files changed

+1433
-266
lines changed

.github/workflows/test.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@ jobs:
1616
cache: "npm"
1717
- name: Install and Build
1818
run: npm ci
19-
- name: Test
20-
run: npm test
2119
- name: Prettier
2220
run: npm run prettier
21+
- name: Tests
22+
run: npm run test:coverage
23+
- name: Code Coverage
24+
uses: greatwizard/coverage-diff-action@v1
25+
with:
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
allowed-to-fail: false
28+
badge-enabled: true
29+
badge-threshold-green: 90
30+
badge-threshold-orange: 80
2331
- name: Generate Changelog
2432
run: git log --oneline $(git describe --tags --abbrev=0)..HEAD >> CHANGELOG.txt
33+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
2534
- name: Release
2635
uses: softprops/action-gh-release@v1
2736
if: ${{ startsWith(github.ref, 'refs/tags/') }}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
index.html
33
build
44
node_modules
5-
.parcel-cache
5+
.parcel-cache
6+
coverage

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
README.md
2+
coverage

.prettierrc

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
{
2-
"$schema": "https://json.schemastore.org/prettierrc",
3-
"semi": true,
4-
"trailingComma": "es5",
5-
"singleQuote": false,
6-
"useTabs": true,
7-
"tabWidth": 4,
8-
"printWidth": 100,
9-
"bracketSpacing": true
10-
}
1+
semi: true
2+
trailingComma: "es5"
3+
singleQuote: false
4+
useTabs: true
5+
tabWidth: 4
6+
printWidth: 100
7+
bracketSpacing: true

README.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
First you'll have to install `mjml-bar-chart` in your project.
66

7-
```
7+
```sh
88
npm i -S @freezystem/mjml-bar-chart
99
```
1010

@@ -20,7 +20,7 @@ Or import it and manually register the plugin.
2020

2121
with **ESM**:
2222

23-
```ecmascript 6
23+
```js
2424
import { registerComponent } from "mjml-core";
2525
import MjBarChart from "@freezystem/mjml-bar-chart";
2626

@@ -29,7 +29,7 @@ registerComponent(MjBarChart);
2929

3030
with **CJS**:
3131

32-
```ecmascript 6
32+
```js
3333
const { registerComponent } = require("mjml-core");
3434
const MjBarChart = require("@freezystem/mjml-bar-chart");
3535

@@ -40,19 +40,18 @@ You can now use the `mjml-bar-chart` component in your MJML templates:
4040

4141
```mjml
4242
<mjml>
43-
<mj-body>
44-
<mj-section>
45-
<mj-column>
46-
<mj-bar-chart
47-
title="Sum of Requests by Department"
48-
dataset-labels="January,February,March"
49-
datasets="[[33,14,27],[18,66,42],[7,15,21]]"
50-
groups="support,sales,tech"
51-
colors="#d8f3dc,#95d5b2,#52b788"
52-
/>
53-
</mj-column>
54-
</mj-section>
55-
</mj-body>
43+
<mj-body>
44+
<mj-section>
45+
<mj-column>
46+
<mj-bar-chart
47+
title="Sum of Requests by Department"
48+
dataset-labels="January,February,March"
49+
datasets="[[33,14,27],[18,66,42],[7,15,21]]"
50+
groups="support,sales,tech"
51+
colors="#d8f3dc,#95d5b2,#52b788"/>
52+
</mj-column>
53+
</mj-section>
54+
</mj-body>
5655
</mjml>
5756
```
5857

package-lock.json

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

package.json

+20-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
},
88
"version": "1.1.1",
99
"description": "A simple MJML component to make static bar charts",
10+
"keywords": [
11+
"mjml",
12+
"chart",
13+
"bar chart",
14+
"email"
15+
],
1016
"main": "./build/index.js",
1117
"module": "./build/esm/index.js",
1218
"types": "./build/types/index.d.ts",
@@ -24,6 +30,8 @@
2430
"build": "tsc -b tsconfig.json tsconfig.esm.json tsconfig.types.json",
2531
"postinstall": "npm run build",
2632
"test": "jest",
33+
"test:coverage": "jest --coverage",
34+
"test:snap": "jest --updateSnapshot",
2735
"deps": "npm-check -u",
2836
"postdeps": "npm audit fix",
2937
"preversion": "git reset && git switch main && git fetch -p && git pull",
@@ -37,7 +45,7 @@
3745
"homepage": "https://github.com/Freezystem/mjml-bar-chart",
3846
"license": "MIT",
3947
"devDependencies": {
40-
"@types/jest": "^29.5.10",
48+
"@types/jest": "^29.5.11",
4149
"@types/mjml": "^4.7.4",
4250
"@types/mjml-core": "^4.7.4",
4351
"@types/mjml-validator": "^4.13.4",
@@ -46,7 +54,7 @@
4654
"npm-check": "^6.0.1",
4755
"prettier": "^3.1.0",
4856
"ts-jest": "^29.1.1",
49-
"typescript": "^5.3.2"
57+
"typescript": "^5.3.3"
5058
},
5159
"dependencies": {
5260
"mjml": "^4.14.1",
@@ -59,10 +67,19 @@
5967
"coverageDirectory": "<rootDir>/coverage",
6068
"coverageReporters": [
6169
"text-summary",
62-
"cobertura"
70+
"json-summary"
6371
],
6472
"preset": "ts-jest",
6573
"testEnvironment": "node",
74+
"reporters": [
75+
[
76+
"github-actions",
77+
{
78+
"silent": false
79+
}
80+
],
81+
"summary"
82+
],
6683
"moduleFileExtensions": [
6784
"ts",
6885
"js"

0 commit comments

Comments
 (0)