@commercetools-frontend/jest-preset-mc-app 21.3.4 → 21.8.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,41 @@
1
1
  # @commercetools-frontend/jest-preset-mc-app
2
2
 
3
+ ## 21.8.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2661](https://github.com/commercetools/merchant-center-application-kit/pull/2661) [`43a9df21`](https://github.com/commercetools/merchant-center-application-kit/commit/43a9df2193000b49a0299c02d5218c50d71567ed) Thanks [@emmenko](https://github.com/emmenko)! - Drop the copyright year from the license files
8
+
9
+ - Updated dependencies [[`43a9df21`](https://github.com/commercetools/merchant-center-application-kit/commit/43a9df2193000b49a0299c02d5218c50d71567ed)]:
10
+ - @commercetools-frontend/babel-preset-mc-app@21.8.0
11
+
12
+ ## 21.7.0
13
+
14
+ ### Patch Changes
15
+
16
+ - [#2627](https://github.com/commercetools/merchant-center-application-kit/pull/2627) [`5a8c301d`](https://github.com/commercetools/merchant-center-application-kit/commit/5a8c301d5627df1e8bb6dcf8870575c6ca32c0a7) Thanks [@emmenko](https://github.com/emmenko)! - Add proper entry point for Jest preset for `typescript`.
17
+
18
+ ```diff
19
+ -const jestPresetForTypeScript = require('@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript');
20
+
21
+ module.exports = {
22
+ - ...jestPresetForTypeScript,
23
+ + preset: '@commercetools-frontend/jest-preset-mc-app/typescript'
24
+ };
25
+ ```
26
+
27
+ The import `@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript` still works for backwards compatibility.
28
+
29
+ ## 21.6.0
30
+
31
+ ### Patch Changes
32
+
33
+ - [#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
34
+
35
+ * [#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).
36
+
37
+ - [#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`.
38
+
3
39
  ## 21.3.4
4
40
 
5
41
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 commercetools GmbH
3
+ Copyright (c) commercetools GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <a href="https://www.npmjs.com/package/@commercetools-frontend/jest-preset-mc-app"><img src="https://badgen.net/npm/v/@commercetools-frontend/jest-preset-mc-app" alt="Latest release (latest dist-tag)" /></a> <a href="https://www.npmjs.com/package/@commercetools-frontend/jest-preset-mc-app"><img src="https://badgen.net/npm/v/@commercetools-frontend/jest-preset-mc-app/next" alt="Latest release (next dist-tag)" /></a> <a href="https://bundlephobia.com/result?p=@commercetools-frontend/jest-preset-mc-app"><img src="https://badgen.net/bundlephobia/minzip/@commercetools-frontend/jest-preset-mc-app" alt="Minified + GZipped size" /></a> <a href="https://github.com/commercetools/merchant-center-application-kit/blob/main/LICENSE"><img src="https://badgen.net/github/license/commercetools/merchant-center-application-kit" alt="GitHub license" /></a>
5
5
  </p>
6
6
 
7
- Jest preset used by a MC application.
7
+ Jest preset used by a Custom Application.
8
8
 
9
9
  ## Install
10
10
 
@@ -12,6 +12,14 @@ Jest preset used by a MC application.
12
12
  $ npm install --save @commercetools-frontend/jest-preset-mc-app
13
13
  ```
14
14
 
15
+ ## Usage
16
+
17
+ ```js
18
+ module.exports = {
19
+ preset: '@commercetools-frontend/jest-preset-mc-app',
20
+ };
21
+ ```
22
+
15
23
  ## Custom config
16
24
 
17
25
  You can pass a custom config using one of the [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) format options. The config module name to use is `jest-preset-mc-app`.
@@ -33,15 +41,13 @@ Supported options are:
33
41
 
34
42
  ## TypeScript support
35
43
 
36
- If you need to use the Jest preset with additional TypeScript support, you need to import `@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript.js` in your Jest config.
44
+ If you need to use the Jest preset with additional TypeScript support, you need to point to the `@commercetools-frontend/jest-preset-mc-app/typescript` preset in your Jest config.
37
45
 
38
46
  For example:
39
47
 
40
48
  ```js
41
- const jestPresetForTypeScript = require('@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript');
42
-
43
49
  module.exports = {
44
- ...jestPresetForTypeScript,
50
+ preset: '@commercetools-frontend/jest-preset-mc-app/typescript',
45
51
  };
46
52
  ```
47
53
 
@@ -82,7 +88,7 @@ module.exports = {
82
88
  };
83
89
  ```
84
90
 
85
- Similarly, you can use the `@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript` instead of the `@commercetools-frontend/jest-preset-mc-app`.
91
+ Similarly, you can use the `@commercetools-frontend/jest-preset-mc-app/typescript` instead of the `@commercetools-frontend/jest-preset-mc-app`.
86
92
 
87
93
  ### Enzyme 17
88
94
 
@@ -117,4 +123,4 @@ module.exports = {
117
123
  };
118
124
  ```
119
125
 
120
- Similarly, you can use the `@commercetools-frontend/jest-preset-mc-app/jest-preset-for-typescript` instead of the `@commercetools-frontend/jest-preset-mc-app`.
126
+ Similarly, you can use the `@commercetools-frontend/jest-preset-mc-app/typescript` instead of the `@commercetools-frontend/jest-preset-mc-app`.
@@ -1,7 +1,2 @@
1
- const defaultPreset = require('./jest-preset');
2
-
3
- module.exports = {
4
- ...defaultPreset,
5
- moduleFileExtensions: ['ts', 'tsx', ...defaultPreset.moduleFileExtensions],
6
- testRegex: '\\.spec\\.[j|t]sx?$',
7
- };
1
+ // Alias entry point, for backwards compatibility.
2
+ module.exports = require('./typescript');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/jest-preset-mc-app",
3
- "version": "21.3.4",
3
+ "version": "21.8.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,7 +17,12 @@
17
17
  "main": "./jest-preset.js",
18
18
  "module": "./jest-preset.js",
19
19
  "dependencies": {
20
- "@commercetools-frontend/babel-preset-mc-app": "21.3.4",
20
+ "@commercetools-frontend/babel-preset-mc-app": "21.8.0",
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
27
  "@testing-library/jest-dom": "5.16.4",
23
28
  "babel-jest": "27.5.1",
@@ -29,8 +34,7 @@
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"
@@ -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 = [];
@@ -0,0 +1 @@
1
+ module.exports = require('./jest-preset');
@@ -0,0 +1,7 @@
1
+ const defaultPreset = require('../jest-preset');
2
+
3
+ module.exports = {
4
+ ...defaultPreset,
5
+ moduleFileExtensions: ['ts', 'tsx', ...defaultPreset.moduleFileExtensions],
6
+ testRegex: '\\.spec\\.[j|t]sx?$',
7
+ };
@@ -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();