🎥 Make videos programmatically with React
add TESTING.md & add generate-badges script
Calvin Falter8ed4d2f7914f
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex da4b58b425..4674564622 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -40,38 +40,3 @@ running to keep the monorepos building and synchronized.As a testbed, you can use the `example` folder. Run `npm start` to trigger the preview and `npm run render` to trigger the render process.-### Running tests--There are tests in each package as well as end-to-end tests in the root of the monorepo. Run `npm test` in a package, or in the root to run all tests. Run `npx jest` to only run unit tests and skip linting.--### Mutation Testing--In case you want to check the quality of your test code while contributing, you can use mutation testing with the help of the [Stryker Mutator](https://stryker-mutator.io/).--#### Stryker Setup--To setup mutation testing in the core package, cd to the `packages/core`directory and then run `npm i @stryker-mutator/core @stryker-mutator/jest-runner`. Further, add a `stryker.conf.json` file in the same directory.--**Example stryker.conf.json:**-- {- "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",- "packageManager": "npm",- "reporters": [ "html", "clear-text", "progress" ],- "testRunner": "jest",- "mutate": [- // specify files to mutate!- "src/interpolate.ts",- "src/volume-prop.ts",- "src/config/codec.ts",- "src/config/image-format.ts"- ],- "coverageAnalysis": "off"- }--Under `"mutate"` you can specify the files you want stryker to mutate for you.-Then to run the mutation tests use `npx stryker run`.-In case you run into error on _Windows_ where Stryker and Jest won't run any test cases, try one of these [workarounds](https://github.com/stryker-mutator/stryker-js/issues/2122#issuecomment-605783668).-After running Stryker you can find the report under `packages/core/reports/mutation` and see how many mutants have been killed by your test cases and how many have survived.--Once you have checked your test code quality with the help of mutation testing, make sure to omit any Stryker related changes from your code before contributing.diff --git a/TESTING.md b/TESTING.mdnew file mode 100644index 0000000000..f9902689ed--- /dev/null+++ b/TESTING.md@@ -0,0 +1,45 @@+#Testing++### Core Coverage+++++++### Running tests++There are tests in each package as well as end-to-end tests in the root of the monorepo. Run `npm test` in a package, or in the root to run all tests. Run `npx jest` to only run unit tests and skip linting.++### Mutation Testing++In case you want to check the quality of your test code while contributing, you can use mutation testing with the help of the [Stryker Mutator](https://stryker-mutator.io/).++#### Stryker Setup++To setup mutation testing in the core package, cd to the `packages/core`directory and then run `npm i @stryker-mutator/core @stryker-mutator/jest-runner`. Further, add a `stryker.conf.json` file in the same directory.++**Example stryker.conf.json:**++ {+ "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",+ "packageManager": "npm",+ "reporters": [ "html", "clear-text", "progress" ],+ "testRunner": "jest",+ "mutate": [+ // specify files to mutate!+ "src/interpolate.ts",+ "src/volume-prop.ts",+ "src/config/codec.ts",+ "src/config/image-format.ts"+ ],+ "coverageAnalysis": "off"+ }++Under `"mutate"` you can specify the files you want stryker to mutate for you.+Then to run the mutation tests use `npx stryker run`.+In case you run into error on _Windows_ where Stryker and Jest won't run any test cases, try one of these [workarounds](https://github.com/stryker-mutator/stryker-js/issues/2122#issuecomment-605783668).+After running Stryker you can find the report under `packages/core/reports/mutation` and see how many mutants have been killed by your test cases and how many have survived.++Once you have checked your test code quality with the help of mutation testing, make sure to omit any Stryker related changes from your code before contributing.+diff --git a/packages/core/generate-badges.js b/packages/core/generate-badges.jsnew file mode 100644index 0000000000..80a9f5336d--- /dev/null+++ b/packages/core/generate-badges.js@@ -0,0 +1,51 @@+const {readFile, writeFile} = require('fs');++const COVERAGE_SUMMARY_PATH = './coverage/coverage-summary.json';+const OUTPUT_FILE = '../../TESTING.md';++const reportKeys = ['lines', 'statements', 'functions', 'branches'];++const getBadgeColor = (percentage) => {+ if (percentage < 70) return 'red';+ if (percentage < 85) return 'yellow';+ return 'brightgreen';+};++const getBadges = (report) => {+ const urls = {};+ reportKeys.forEach((key) => {+ const coverage = report.total[key].pct;+ urls[key] = `https://img.shields.io/badge/Coverage_${key}-${coverage}${encodeURI(+ '%'+ )}-${getBadgeColor(coverage)}.svg`;+ });+ return urls;+};++const replaceOldBadges = (oldFileAsString, newBadges) => {+ reportKeys.forEach((key) => {+ const regex = `!\\[${key}\\]\\([^\\)]*\\)`;+ oldFileAsString = oldFileAsString.replace(new RegExp(regex), ``);+ })+ return oldFileAsString+}++readFile(COVERAGE_SUMMARY_PATH, 'utf8', (errInput, resInput) => {+ if (errInput) {+ throw errInput;+ }++ const report = JSON.parse(resInput);+ const badges = getBadges(report);++ readFile(OUTPUT_FILE, 'utf8', (errOutput, resOutput) => {++ const newFile = replaceOldBadges(resOutput, badges);++ writeFile(OUTPUT_FILE, newFile, 'utf8', (writeError) => {+ if (writeError) {+ throw writeError;+ }+ });+ });+});diff --git a/packages/core/package.json b/packages/core/package.jsonindex 61ae0e3797..71e16e35ed 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -5,7 +5,7 @@"main": "dist/index.js","sideEffects": false,"scripts": {- "test": "eslint src --ext ts,tsx && jest && istanbul-badges-readme --silent",+ "test": "eslint src --ext ts,tsx && jest --coverage && node generate-badges.js","build": "tsc -d","watch": "tsc -w","prerelease": "cp ../../README.md .",