@spothero/ui 16.2.0-beta.0 → 17.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,167 +0,0 @@
1
- /* eslint-disable no-console */
2
- const fs = require('fs');
3
- const chalk = require('chalk');
4
- const {merge} = require('lodash');
5
-
6
- /**
7
- * OPTIONS:
8
- * - tolerance: keeps the threshold below the measured coverage, allowing wiggle room. default: 0 tolerance
9
- * - roundDown: round down to the nearest integer. default: false
10
- * - configLocation: the location of the jest config, default: <rootDir>/jest.config.json
11
- */
12
- class ThresholdRatchet {
13
- #globalConfig;
14
- #options;
15
-
16
- constructor(globalConfig, options) {
17
- this.#globalConfig = globalConfig;
18
- this.#options = options;
19
- }
20
-
21
- #log = (message, type = 'info') => {
22
- let transformedMessage = message;
23
- const messageLength =
24
- transformedMessage % 2 === 0
25
- ? transformedMessage.length
26
- : transformedMessage.length + 1;
27
-
28
- let header = ' ThresholdRatchet ';
29
- const minStringLength = 80;
30
-
31
- if (messageLength < minStringLength) {
32
- transformedMessage = transformedMessage
33
- .padStart(minStringLength / 2 + message.length / 2, ' ')
34
- .padEnd(minStringLength, ' ');
35
- }
36
-
37
- header = header
38
- .padStart(transformedMessage.length / 2 + header.length / 2, '=')
39
- .padEnd(transformedMessage.length, '=');
40
-
41
- const footer = ''.padStart(transformedMessage.length, '=');
42
- const colorText = type === 'info' ? chalk.green : chalk.red;
43
- const colorBackground =
44
- type === 'info' ? chalk.bgGreen.black : chalk.bgRed.black;
45
-
46
- console.log(`\n${colorBackground(header)}`);
47
- console.log(`\n${colorText(transformedMessage)}\n`);
48
- console.log(`${colorBackground(footer)}\n`);
49
- };
50
-
51
- #getCoverageSummary = () => {
52
- const coverageDirectory = this.#globalConfig.coverageDirectory;
53
- const coverageSummary = JSON.parse(
54
- fs.readFileSync(
55
- `${coverageDirectory}/coverage-summary.json`,
56
- 'utf-8'
57
- )
58
- );
59
-
60
- return coverageSummary;
61
- };
62
-
63
- #generateNewThreshold = coverageSummary => {
64
- return Object.entries(coverageSummary.total).reduce(
65
- (acc, [type, {pct}]) => {
66
- const newThreshold = pct - (this.#options.tolerance || 5);
67
-
68
- const percent = this.#options.roundDown
69
- ? Math.floor(newThreshold)
70
- : newThreshold;
71
-
72
- acc[type] = percent;
73
-
74
- return acc;
75
- },
76
- {}
77
- );
78
- };
79
-
80
- #updateThreshold = newThreshold => {
81
- let configLocation =
82
- this.#options.configLocation || '<rootDir>/jest.config.json';
83
-
84
- configLocation = configLocation.replace(
85
- '<rootDir>',
86
- this.#globalConfig.rootDir
87
- );
88
-
89
- const configFile = JSON.parse(fs.readFileSync(configLocation, 'utf-8'));
90
-
91
- const newConfig = merge(configFile, {
92
- coverageThreshold: {
93
- global: newThreshold,
94
- },
95
- });
96
-
97
- fs.writeFileSync(
98
- configLocation,
99
- JSON.stringify(newConfig, null, 4),
100
- 'utf-8'
101
- );
102
-
103
- this.#log('Updated global threshold');
104
- };
105
-
106
- #hasDecreasedCoverage = newThreshold => {
107
- const current = this.#globalConfig.coverageThreshold;
108
-
109
- return Object.keys((current && current.global) || {}).some(
110
- key => current.global[key] > newThreshold[key]
111
- );
112
- };
113
-
114
- #hasIncreasedCoverage = newThreshold => {
115
- const current = this.#globalConfig.coverageThreshold;
116
-
117
- return current && current.global
118
- ? Object.keys(current.global).some(
119
- key => current.global[key] < newThreshold[key]
120
- )
121
- : true;
122
- };
123
-
124
- onRunComplete(context, {numFailedTests}) {
125
- if (this.#globalConfig.watch) {
126
- return;
127
- }
128
-
129
- if (!this.#globalConfig.coverageReporters.includes('json-summary')) {
130
- this.#log(
131
- 'ThresholdRatchet needs "json-summary" within "coverageReporters"',
132
- 'error'
133
- );
134
-
135
- return;
136
- }
137
-
138
- if (numFailedTests) {
139
- this.#log(
140
- 'ThresholdRatchet only runs when all tests have passed',
141
- 'error'
142
- );
143
-
144
- return;
145
- }
146
-
147
- const coverageSummary = this.#getCoverageSummary();
148
- const newThreshold = this.#generateNewThreshold(coverageSummary);
149
-
150
- if (this.#hasDecreasedCoverage(newThreshold)) {
151
- this.#log(
152
- 'Coverage has decreased! Please resolve before running tests again.',
153
- 'error'
154
- );
155
-
156
- return;
157
- }
158
-
159
- if (this.#hasIncreasedCoverage(newThreshold)) {
160
- this.#updateThreshold(newThreshold);
161
- } else {
162
- this.#log('Coverage has not changed');
163
- }
164
- }
165
- }
166
-
167
- module.exports = ThresholdRatchet;
package/babel.config.js DELETED
@@ -1 +0,0 @@
1
- module.exports = {presets: ['@babel/preset-env']};
package/dex.config.js DELETED
@@ -1,45 +0,0 @@
1
- const path = require('path');
2
-
3
- const targetEntry = process.env.TARGET_ENTRY;
4
-
5
- module.exports = {
6
- client: {
7
- plugins: [],
8
- },
9
- production: {
10
- client: {
11
- entry: [`./src/components/index.js`],
12
- output: {
13
- filename: 'index.js',
14
- path: path.resolve(__dirname, targetEntry),
15
- library: {
16
- name: '@spothero/ui',
17
- type: 'umd',
18
- },
19
- globalObject: 'this',
20
- },
21
- externals: {
22
- react: {
23
- root: 'React',
24
- commonjs2: 'react',
25
- commonjs: 'react',
26
- amd: 'react',
27
- },
28
- 'react-dom': {
29
- root: 'ReactDOM',
30
- commonjs2: 'react-dom',
31
- commonjs: 'react-dom',
32
- amd: 'react-dom',
33
- },
34
- lodash: {
35
- commonjs2: 'lodash',
36
- commonjs: 'lodash',
37
- amd: 'lodash',
38
- root: '_',
39
- },
40
- 'prop-types': 'prop-types',
41
- '@chakra-ui/react': '@chakra-ui/react',
42
- },
43
- },
44
- },
45
- };
package/jest.config.json DELETED
@@ -1,64 +0,0 @@
1
- {
2
- "rootDir": "./",
3
- "clearMocks": true,
4
- "resetMocks": true,
5
- "moduleDirectories": [
6
- "node_modules",
7
- "<rootDir>/src",
8
- "<rootDir>/__tests__",
9
- "<rootDir>"
10
- ],
11
- "moduleFileExtensions": [
12
- "js",
13
- "jsx",
14
- "json"
15
- ],
16
- "setupFiles": [
17
- "jest-date-mock"
18
- ],
19
- "setupFilesAfterEnv": [
20
- "jest-extended",
21
- "jest-chain",
22
- "@testing-library/jest-dom/extend-expect"
23
- ],
24
- "transform": {
25
- "^.+\\.(js|jsx)$": "babel-jest"
26
- },
27
- "testMatch": [
28
- "**/?(*)+(spec|test).js?(x)"
29
- ],
30
- "watchPlugins": [
31
- "jest-watch-typeahead/filename",
32
- "jest-watch-typeahead/testname"
33
- ],
34
- "coverageDirectory": "coverage",
35
- "collectCoverageFrom": [
36
- "<rootDir>/src/js/**/*.{js,jsx}"
37
- ],
38
- "coverageReporters": [
39
- "json",
40
- "lcov",
41
- "text-summary",
42
- "json-summary"
43
- ],
44
- "reporters": [
45
- "default",
46
- [
47
- "<rootDir>/__tests__/threshold-ratchet.js",
48
- {
49
- "tolerance": 5,
50
- "roundDown": true,
51
- "configLocation": "<rootDir>/jest.config.json"
52
- }
53
- ]
54
- ],
55
- "coverageThreshold": {
56
- "global": {
57
- "lines": null,
58
- "statements": null,
59
- "functions": null,
60
- "branches": null,
61
- "branchesTrue": null
62
- }
63
- }
64
- }
@@ -1,5 +0,0 @@
1
- {
2
- "index.html": "index.html",
3
- "index.js.license.txt": "index.js.LICENSE.txt",
4
- "main.js": "index.js"
5
- }
package/v2/index.html DELETED
@@ -1 +0,0 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><script defer="defer" src="/index.js"></script></head><body><div id="root"></div></body></html>