Skip to content

Commit 075e2aa

Browse files
committed
Refactor function to class, add tests
1 parent aea4fd1 commit 075e2aa

File tree

10 files changed

+2269
-98
lines changed

10 files changed

+2269
-98
lines changed

.eslintrc.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ module.exports = {
22
env: {
33
browser: true,
44
},
5-
plugins: ['prettier', 'unicorn'],
6-
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:unicorn/recommended'],
5+
plugins: ['prettier', 'unicorn', 'jest'],
6+
extends: [
7+
'eslint:recommended',
8+
'plugin:prettier/recommended',
9+
'plugin:unicorn/recommended',
10+
'plugin:jest/recommended',
11+
],
712

813
overrides: [
914
{
10-
files: ['.eslintrc.js'],
15+
files: ['.eslintrc.js', 'jest.config.js', 'jest.setup.js'],
1116
env: {
1217
browser: false,
1318
node: true,
@@ -16,5 +21,11 @@ module.exports = {
1621
'unicorn/prefer-module': 'off',
1722
},
1823
},
24+
{
25+
files: ['tests/**/*'],
26+
env: {
27+
jest: true,
28+
},
29+
},
1930
],
2031
};

.github/workflows/ci.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@ jobs:
2121
version: ${{ env.PNPM_VERSION }}
2222
- uses: actions/setup-node@v2
2323
with:
24-
node-version: 14.x
24+
node-version: 16.x
2525
cache: pnpm
2626
- run: pnpm install
2727
- run: pnpm run lint
28+
29+
test:
30+
name: Testing
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: pnpm/action-setup@v2.0.1
35+
with:
36+
version: ${{ env.PNPM_VERSION }}
37+
- uses: actions/setup-node@v2
38+
with:
39+
node-version: 16.x
40+
cache: pnpm
41+
- run: pnpm install
42+
- run: pnpm run test

jest.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const { defaults } = require('jest-config');
7+
const crypto = require('crypto');
8+
const { TextEncoder } = require('util');
9+
10+
module.exports = {
11+
clearMocks: true,
12+
collectCoverage: false,
13+
globals: {
14+
...defaults.globals,
15+
crypto: {
16+
subtle: {
17+
digest: crypto.webcrypto.subtle.digest,
18+
},
19+
},
20+
TextEncoder,
21+
},
22+
moduleFileExtensions: ['mjs', 'js', 'json'],
23+
preset: 'rollup-jest',
24+
setupFiles: ['./jest.setup.js'],
25+
testEnvironment: 'jsdom',
26+
testPathIgnorePatterns: ['/node_modules/'],
27+
testRegex: '((\\.|/)(test|spec))\\.(mjs?|js?|tsx?|ts?)$',
28+
transformIgnorePatterns: ['\\.pnp\\.[^\\/]+$'],
29+
};

jest.setup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const jestFetchMock = require('jest-fetch-mock');
2+
3+
jestFetchMock.enableMocks();

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"version": "0.1.0",
44
"description": "JavaScript package to send TelemetryDeck signals",
55
"main": "dist/telemetrydeck.js",
6-
"module": "src/telemetrydeck.js",
6+
"module": "src/telemetrydeck.mjs",
77
"scripts": {
88
"build": "rollup -c",
99
"changelog": "lerna-changelog",
1010
"lint": "eslint . --cache",
1111
"lint:fix": "eslint . --fix",
1212
"release": "release-it",
13-
"test": "echo \"Error: no test specified yet\" && exit 1"
13+
"test": "jest",
14+
"test:watch": "jest --watch"
1415
},
1516
"repository": {
1617
"type": "git",
@@ -35,13 +36,18 @@
3536
"@rollup/plugin-json": "^4.1.0",
3637
"eslint": "^8.6.0",
3738
"eslint-config-prettier": "^8.3.0",
39+
"eslint-plugin-jest": "^25.3.4",
3840
"eslint-plugin-prettier": "^4.0.0",
3941
"eslint-plugin-unicorn": "^40.0.0",
42+
"jest": "^27.4.7",
43+
"jest-fetch-mock": "^3.0.3",
4044
"lerna-changelog": "^2.2.0",
4145
"prettier": "^2.5.1",
4246
"release-it": "^14.12.1",
4347
"release-it-lerna-changelog": "^4.0.1",
4448
"rollup": "^2.63.0",
45-
"rollup-plugin-terser": "^7.0.2"
49+
"rollup-jest": "^1.1.3",
50+
"rollup-plugin-terser": "^7.0.2",
51+
"typescript": "^4.5.4"
4652
}
4753
}

0 commit comments

Comments
 (0)