@commercetools-frontend/jest-preset-mc-app 21.3.0 → 21.6.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @commercetools-frontend/jest-preset-mc-app
2
2
 
3
+ ## 21.6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2555](https://github.com/commercetools/merchant-center-application-kit/pull/2555) [`0b7a3743`](https://github.com/commercetools/merchant-center-application-kit/commit/0b7a3743207172ace7f2b6893b9c7d61c351967b) Thanks [@renovate](https://github.com/apps/renovate)! - chore(deps): update all dependencies
8
+
9
+ * [#2590](https://github.com/commercetools/merchant-center-application-kit/pull/2590) [`7c6415d1`](https://github.com/commercetools/merchant-center-application-kit/commit/7c6415d1b4f5f17d8ea0421b07051e6d2f7265c1) Thanks [@emmenko](https://github.com/emmenko)! - Use proper [Intl polyfills](https://formatjs.io/docs/polyfills).
10
+
11
+ - [#2614](https://github.com/commercetools/merchant-center-application-kit/pull/2614) [`7c74f7f6`](https://github.com/commercetools/merchant-center-application-kit/commit/7c74f7f6a9df8478abfc3c6a55844573a9d026f2) Thanks [@emmenko](https://github.com/emmenko)! - Fix missing globals `TextEncoder` and `TextDecoder` when using `jsdom`.
12
+
13
+ ## 21.3.4
14
+
15
+ ### Patch Changes
16
+
17
+ - [#2546](https://github.com/commercetools/merchant-center-application-kit/pull/2546) [`dc76e5a9`](https://github.com/commercetools/merchant-center-application-kit/commit/dc76e5a9a7f875dadf2ed5a11c48a1ddff7b431c) Thanks [@renovate](https://github.com/apps/renovate)! - Upgrade dependencies
18
+
19
+ - Updated dependencies [[`dc76e5a9`](https://github.com/commercetools/merchant-center-application-kit/commit/dc76e5a9a7f875dadf2ed5a11c48a1ddff7b431c)]:
20
+ - @commercetools-frontend/babel-preset-mc-app@21.3.4
21
+
22
+ ## 21.3.2
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [[`cc7c19d0`](https://github.com/commercetools/merchant-center-application-kit/commit/cc7c19d06e25002e0d35c072b6f9388dd61f87cb)]:
27
+ - @commercetools-frontend/babel-preset-mc-app@21.3.2
28
+
3
29
  ## 21.3.0
4
30
 
5
31
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/jest-preset-mc-app",
3
- "version": "21.3.0",
3
+ "version": "21.6.0",
4
4
  "description": "Jest preset used by a MC application",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -17,26 +17,30 @@
17
17
  "main": "./jest-preset.js",
18
18
  "module": "./jest-preset.js",
19
19
  "dependencies": {
20
- "@commercetools-frontend/babel-preset-mc-app": "21.3.0",
20
+ "@commercetools-frontend/babel-preset-mc-app": "21.3.4",
21
+ "@formatjs/intl-getcanonicallocales": "^1.9.2",
22
+ "@formatjs/intl-listformat": "^6.5.3",
23
+ "@formatjs/intl-locale": "^2.4.47",
24
+ "@formatjs/intl-numberformat": "^7.4.3",
25
+ "@formatjs/intl-pluralrules": "^4.3.3",
21
26
  "@sheerun/mutationobserver-shim": "0.3.3",
22
- "@testing-library/jest-dom": "5.16.3",
27
+ "@testing-library/jest-dom": "5.16.4",
23
28
  "babel-jest": "27.5.1",
24
29
  "colors": "1.4.0",
25
30
  "cosmiconfig": "7.0.1",
26
31
  "identity-obj-proxy": "3.0.0",
27
32
  "intl": "1.2.5",
28
- "jest-localstorage-mock": "2.4.19",
33
+ "jest-localstorage-mock": "2.4.21",
29
34
  "jest-mock": "^27.5.1",
30
35
  "jest-silent-reporter": "0.5.0",
31
36
  "jest-transform-graphql": "2.1.0",
32
- "jest-watch-typeahead": "1.0.0",
33
- "make-plural": "7.1.0",
37
+ "jest-watch-typeahead": "1.1.0",
34
38
  "raf": "3.4.1",
35
39
  "setimmediate": "1.0.5",
36
40
  "unfetch": "4.2.0"
37
41
  },
38
42
  "devDependencies": {
39
- "@testing-library/react": "12.1.4",
43
+ "@testing-library/react": "12.1.5",
40
44
  "jest": "27.5.1"
41
45
  }
42
46
  }
@@ -1,7 +1,25 @@
1
1
  require('setimmediate');
2
2
  require('unfetch/polyfill');
3
3
  require('@testing-library/jest-dom/extend-expect');
4
- require('./polyfills/intl');
4
+ // Intl polyfills: https://formatjs.io/docs/polyfills
5
+ require('@formatjs/intl-getcanonicallocales');
6
+ require('@formatjs/intl-listformat');
7
+ require('@formatjs/intl-locale');
8
+ require('@formatjs/intl-numberformat');
9
+ require('@formatjs/intl-pluralrules');
10
+ // Intl polyfills locale data
11
+ require('@formatjs/intl-listformat/locale-data/en');
12
+ require('@formatjs/intl-listformat/locale-data/de');
13
+ require('@formatjs/intl-listformat/locale-data/es');
14
+ require('@formatjs/intl-listformat/locale-data/fr');
15
+ require('@formatjs/intl-numberformat/locale-data/en');
16
+ require('@formatjs/intl-numberformat/locale-data/de');
17
+ require('@formatjs/intl-numberformat/locale-data/es');
18
+ require('@formatjs/intl-numberformat/locale-data/fr');
19
+ require('@formatjs/intl-pluralrules/locale-data/en');
20
+ require('@formatjs/intl-pluralrules/locale-data/de');
21
+ require('@formatjs/intl-pluralrules/locale-data/es');
22
+ require('@formatjs/intl-pluralrules/locale-data/fr');
5
23
 
6
24
  const { configure: configureRtl } = require('@testing-library/react');
7
25
  const loadConfig = require('./load-config');
package/setup-tests.js CHANGED
@@ -1,4 +1,4 @@
1
- const { Headers } = require('node-fetch');
1
+ const util = require('util');
2
2
  const colors = require('colors/safe');
3
3
  const MutationObserver = require('@sheerun/mutationobserver-shim');
4
4
  const loadConfig = require('./load-config');
@@ -11,7 +11,19 @@ global.window.app = {
11
11
  };
12
12
 
13
13
  window.MutationObserver = MutationObserver;
14
- global.Headers = global.Headers || Headers;
14
+ global.Headers = global.Headers || require('node-fetch').Headers;
15
+
16
+ // Fix missing globals when `jsdom` is used in a test environment.
17
+ // See https://github.com/jsdom/jsdom/issues/2524#issuecomment-1108991178.
18
+ // Also https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom.
19
+ Object.defineProperty(window, 'TextEncoder', {
20
+ writable: true,
21
+ value: util.TextEncoder,
22
+ });
23
+ Object.defineProperty(window, 'TextDecoder', {
24
+ writable: true,
25
+ value: util.TextDecoder,
26
+ });
15
27
 
16
28
  let additionalSilencedWarnings = [];
17
29
  let additionalNonThrowingWarnings = [];
@@ -1,141 +0,0 @@
1
- /**
2
- * NOTE: this is a copy of https://github.com/eemeli/intl-pluralrules
3
- * as the package is shipped with ES6 code.
4
- */
5
- const pluralRules = require('make-plural/plurals');
6
- const pluralCategories = require('make-plural/pluralCategories');
7
-
8
- // does not check for duplicate subtags
9
- const isStructurallyValidLanguageTag = (locale) =>
10
- locale.split('-').every((subtag) => /[a-z0-9]+/i.test(subtag));
11
-
12
- const canonicalizeLocaleList = (locales) => {
13
- if (!locales) return [];
14
- if (!Array.isArray(locales)) locales = [locales];
15
- const res = {};
16
- for (let i = 0; i < locales.length; ++i) {
17
- let tag = locales[i];
18
- if (tag && typeof tag === 'object') tag = String(tag);
19
- if (typeof tag !== 'string') {
20
- // Requiring tag to be a String or Object means that the Number value
21
- // NaN will not be interpreted as the language tag "nan", which stands
22
- // for Min Nan Chinese.
23
- const msg = `Locales should be strings, ${JSON.stringify(tag)} isn't.`;
24
- throw new TypeError(msg);
25
- }
26
- if (tag.startsWith('*')) continue;
27
- if (!isStructurallyValidLanguageTag(tag)) {
28
- const strTag = JSON.stringify(tag);
29
- const msg = `The locale ${strTag} is not a structurally valid BCP 47 language tag.`;
30
- throw new RangeError(msg);
31
- }
32
- res[tag] = true;
33
- }
34
- return Object.keys(res);
35
- };
36
-
37
- const defaultLocale = () =>
38
- (typeof navigator !== 'undefined' &&
39
- navigator &&
40
- (navigator.userLanguage || navigator.language)) ||
41
- 'en-US';
42
-
43
- const findLocale = (locale) => {
44
- do {
45
- if (pluralRules[locale]) return locale;
46
- locale = locale.replace(/-?[^-]*$/, '');
47
- } while (locale);
48
- return null;
49
- };
50
-
51
- const resolveLocale = (locales) => {
52
- const canonicalLocales = canonicalizeLocaleList(locales);
53
- for (let i = 0; i < canonicalLocales.length; ++i) {
54
- const lc = findLocale(canonicalLocales[i]);
55
- if (lc) return lc;
56
- }
57
- return findLocale(defaultLocale());
58
- };
59
-
60
- const getType = (type) => {
61
- if (!type) return 'cardinal';
62
- if (type === 'cardinal' || type === 'ordinal') return type;
63
- throw new RangeError('Not a valid plural type: ' + JSON.stringify(type));
64
- };
65
-
66
- class PluralRules {
67
- static supportedLocalesOf(locales) {
68
- return canonicalizeLocaleList(locales).filter(findLocale);
69
- }
70
-
71
- constructor(locales, opt = {}) {
72
- this._locale = resolveLocale(locales);
73
- this._type = getType(opt.type);
74
- if (typeof Intl === 'object' && Intl.NumberFormat) {
75
- // make-plural expects latin digits with . decimal separator
76
- this._nf = new Intl.NumberFormat('en', opt);
77
- } else {
78
- const {
79
- minimumIntegerDigits: minID,
80
- minimumFractionDigits: minFD,
81
- maximumFractionDigits: maxFD,
82
- minimumSignificantDigits: minSD,
83
- maximumSignificantDigits: maxSD,
84
- } = opt;
85
- this._minID = typeof minID === 'number' ? minID : 1;
86
- this._minFD = typeof minFD === 'number' ? minFD : 0;
87
- this._maxFD =
88
- typeof maxFD === 'number' ? maxFD : Math.max(this._minFD, 3);
89
- if (typeof minSD === 'number' || typeof maxSD === 'number') {
90
- this._minSD = typeof minSD === 'number' ? minSD : 1;
91
- this._maxSD = typeof maxSD === 'number' ? maxSD : 21;
92
- }
93
- }
94
- }
95
-
96
- resolvedOptions() {
97
- const nfOpt = this._nf && this._nf.resolvedOptions();
98
- const opt = {
99
- locale: this._locale,
100
- minimumIntegerDigits: nfOpt ? nfOpt.minimumIntegerDigits : this._minID,
101
- minimumFractionDigits: nfOpt ? nfOpt.minimumFractionDigits : this._minFD,
102
- maximumFractionDigits: nfOpt ? nfOpt.maximumFractionDigits : this._maxFD,
103
- pluralCategories: pluralCategories[this._locale][this._type],
104
- type: this._type,
105
- };
106
- if (nfOpt && typeof nfOpt.minimumSignificantDigits === 'number') {
107
- opt.minimumSignificantDigits = nfOpt.minimumSignificantDigits;
108
- opt.maximumSignificantDigits = nfOpt.maximumSignificantDigits;
109
- } else if (typeof this._minSD === 'number') {
110
- opt.minimumSignificantDigits = this._minSD;
111
- opt.maximumSignificantDigits = this._maxSD;
112
- }
113
- return opt;
114
- }
115
-
116
- _format(n) {
117
- if (this._nf) return this._nf.format(n);
118
- if (this._minSD) {
119
- const raw = String(n);
120
- let prec = 0;
121
- for (let i = 0; i < raw.length; ++i) {
122
- const c = raw[i];
123
- if (c >= '0' && c <= '9') ++prec;
124
- }
125
- if (prec < this._minSD) return n.toPrecision(this._minSD);
126
- if (prec > this._maxSD) return n.toPrecision(this._maxSD);
127
- return raw;
128
- }
129
- if (this._minFD > 0) return n.toFixed(this._minFD);
130
- if (this._maxFD === 0) return n.toFixed(0);
131
- return String(n);
132
- }
133
-
134
- select(number) {
135
- if (typeof number !== 'number') number = Number(number);
136
- if (!isFinite(number)) return 'other';
137
- const fmt = this._format(Math.abs(number));
138
- return pluralRules[this._locale](fmt, this._type === 'ordinal');
139
- }
140
- }
141
- module.exports = PluralRules;
package/polyfills/intl.js DELETED
@@ -1,8 +0,0 @@
1
- // Polyfill `Intl` for NodeJS, as `react-intl` (v3) relies on the `intl-locales-supported`
2
- // package, which checks if the locale is supported by the following constructors.
3
- // In the browser everything is fine, however in NodeJS environment we need to polyfill it.
4
- // https://github.com/formatjs/formatjs/tree/master/packages/intl-messageformat#modern-intl-dependency
5
- global.Intl = require('intl');
6
- global.Intl.PluralRules = require('./intl-pluralrules');
7
- // Work-around for the issue https://github.com/andyearnshaw/Intl.js/issues/256
8
- global.Intl.__disableRegExpRestore();