Skip to content

Commit e3997e7

Browse files
committed
test: added code coverage
test: linted
1 parent 461c719 commit e3997e7

File tree

7 files changed

+4185
-2582
lines changed

7 files changed

+4185
-2582
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ dist/
4747

4848
# Tests
4949
coverage/
50-
cypress/react-testing-pages/src/components/lottie-react.js
50+
cypress/react-testing-pages/src/components/lottie-react.js
51+
.nyc_output

babel.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { CODE_COVERAGE } = process.env;
2+
const plugins = [];
3+
if (CODE_COVERAGE === 'true') plugins.push('istanbul');
4+
5+
module.exports = function(api) {
6+
api.cache(true);
7+
8+
return {
9+
presets: [
10+
'@babel/preset-typescript',
11+
[
12+
'@babel/preset-env',
13+
{
14+
targets: {
15+
edge: '17',
16+
firefox: '60',
17+
chrome: '67',
18+
safari: '11.1',
19+
},
20+
},
21+
],
22+
],
23+
plugins,
24+
};
25+
};

cypress/plugins/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@
1919
module.exports = (on, config) => {
2020
// `on` is used to hook into various events Cypress emits
2121
// `config` is the resolved Cypress config
22+
require('@cypress/code-coverage/task')(on, config)
23+
// include any other plugin code...
24+
25+
// It's IMPORTANT to return the config object
26+
// with any changed environment variables
27+
return config
2228
}

cypress/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
// Import commands.js using ES2015 syntax:
1717
import './commands'
18+
import '@cypress/code-coverage/support'
1819

1920
// Alternatively you can use CommonJS syntax:
2021
// require('./commands')

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
],
1111
"devDependencies": {
1212
"@babel/core": "^7.9.6",
13+
"@babel/preset-env": "^7.16.11",
1314
"@commitlint/cli": "^12.1.1",
1415
"@commitlint/config-conventional": "^12.1.1",
16+
"@cypress/code-coverage": "^3.9.12",
17+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
18+
"@rollup/plugin-babel": "^5.3.1",
1519
"@rollup/plugin-commonjs": "^11.1.0",
1620
"@rollup/plugin-node-resolve": "^7.1.3",
1721
"@rollup/plugin-strip": "^1.3.2",
@@ -35,6 +39,7 @@
3539
"@typescript-eslint/eslint-plugin": "^2.24.0",
3640
"@typescript-eslint/parser": "^2.24.0",
3741
"babel-loader": "^8.1.0",
42+
"babel-plugin-istanbul": "^6.1.1",
3843
"css-loader": "^3.5.3",
3944
"csstype": "^2.6.10",
4045
"cypress": "^9.5.1",
@@ -61,9 +66,11 @@
6166
"rollup-plugin-terser": "^5.3.0",
6267
"rollup-plugin-typescript2": "^0.27.0",
6368
"semantic-release": "^17.4.2",
69+
"source-map-support": "^0.5.21",
6470
"style-loader": "^1.2.1",
6571
"ts-jest": "^26.0.0",
6672
"ts-loader": "^7.0.4",
73+
"ts-node": "^10.7.0",
6774
"typescript": "^3.5.3",
6875
"typings-for-css-modules-loader": "^1.7.0",
6976
"webpack": "^4.43.0"
@@ -80,9 +87,9 @@
8087
"build-with-coverage": "CODE_COVERAGE=true rollup -c",
8188
"prepublishOnly": "yarn build",
8289
"build-tests": "yarn run build-with-coverage && cp ./dist/lottie-react.js ./cypress/react-testing-pages/src/components/",
83-
"run-tests": "while ! nc -z localhost 8080 ; do sleep 1 ; done && yarn run start-cypress",
90+
"run-tests": "while ! nc -z localhost 8080 ; do sleep 1 ; done && yarn run start-cypress && npx nyc report --reporter=text-summary",
8491
"postrun-tests": "kill $(lsof -t -i:8080)",
85-
"start-and-run-tests": "yarn run build-tests && yarn run serve-app && yarn run-tests;",
92+
"start-and-run-tests": "yarn run build-tests && yarn run serve-app && yarn run-tests",
8693
"serve-app": "cd ./cypress/react-testing-pages && yarn && yarn run start &",
8794
"start-cypress": "yarn run cypress run",
8895
"lint": "tsc --noEmit && eslint . --ext .ts,.tsx,.js",
@@ -122,5 +129,9 @@
122129
"src/**/*.{js,jsx,ts,tsx,json}": [
123130
"eslint . --ext .ts,.tsx,.js --fix"
124131
]
132+
},
133+
"nyc": {
134+
"extends": "@istanbuljs/nyc-config-typescript",
135+
"all": true
125136
}
126137
}

rollup.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import babel from '@rollup/plugin-babel';
12
import commonjs from '@rollup/plugin-commonjs';
23
import resolve from '@rollup/plugin-node-resolve';
34
import strip from '@rollup/plugin-strip';
@@ -29,7 +30,6 @@ export default {
2930
name,
3031
},
3132
],
32-
3333
plugins: [
3434
// Remove debugger statements and console.log calls
3535
isProduction && strip(),
@@ -43,6 +43,11 @@ export default {
4343
// Convert commonjs modules to ES modules
4444
commonjs(),
4545

46+
babel({
47+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
48+
exclude: ['./node_modules/**'],
49+
}),
50+
4651
// Use Typescript to transpile code
4752
// typescript({ lib: ['es5', 'es6', 'dom'], target: 'es5' }),
4853
typescript({ tsconfig: './tsconfig.json' }),

0 commit comments

Comments
 (0)