@ornikar/jest-config-react 9.4.1 → 9.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
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.6.0](https://github.com/ornikar/shared-configs/compare/@ornikar/jest-config-react@9.5.1...@ornikar/jest-config-react@9.6.0) (2022-04-01)
7
+
8
+
9
+ ### Features
10
+
11
+ * **jest-config-react:** improve svg transformer [no issue] ([#688](https://github.com/ornikar/shared-configs/issues/688)) ([d353d0e](https://github.com/ornikar/shared-configs/commit/d353d0e5151a3e0b790fc5805bc73bf9350efd68))
12
+
13
+
14
+
15
+
16
+
17
+ ## [9.5.1](https://github.com/ornikar/shared-configs/compare/@ornikar/jest-config-react@9.5.0...@ornikar/jest-config-react@9.5.1) (2022-03-29)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **jest-config-react:** add missing escape dot in raw.svg transform ([41491df](https://github.com/ornikar/shared-configs/commit/41491dfe6fab643fe47a35634e6abad32f11a2d1))
23
+
24
+
25
+
26
+
27
+
28
+ # [9.5.0](https://github.com/ornikar/shared-configs/compare/@ornikar/jest-config-react@9.4.1...@ornikar/jest-config-react@9.5.0) (2022-03-29)
29
+
30
+
31
+ ### Features
32
+
33
+ * **jest-config-react:** use jest-svg-transformer ARCH-1506 ([#678](https://github.com/ornikar/shared-configs/issues/678)) ([0507f23](https://github.com/ornikar/shared-configs/commit/0507f23eb3938a1320e457c847dbc576316e3e7f))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [9.4.1](https://github.com/ornikar/shared-configs/compare/@ornikar/jest-config-react@9.4.0...@ornikar/jest-config-react@9.4.1) (2022-03-14)
7
40
 
8
41
  **Note:** Version bump only for package @ornikar/jest-config-react
package/jest-preset.js CHANGED
@@ -18,14 +18,17 @@ module.exports = {
18
18
  require.resolve('./test-setup'),
19
19
  baseJestPreset.setupFiles[baseJestPreset.setupFiles.length - 1],
20
20
  ],
21
- transform: useCraco
22
- ? {
23
- '\\.svg$': require.resolve('./fileTransform'),
24
- }
25
- : {
26
- '\\.svg$': require.resolve('./fileTransform'),
27
- '^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
28
- },
21
+ transform: {
22
+ '\\.raw\\.svg$': require.resolve('./transformers/asset-name-transformer'),
23
+ // legacy support, use { ReactComponent } from .svg instead.
24
+ '\\.inline\\.svg$': require.resolve('./transformers/svg-transformer-inline.js'),
25
+ '\\.svg$': require.resolve('./transformers/svg-transformer.js'),
26
+ ...(useCraco
27
+ ? {}
28
+ : {
29
+ '^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
30
+ }),
31
+ },
29
32
  transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$', '^.+\\.css$'],
30
33
  moduleNameMapper: {
31
34
  '\\.css$': 'identity-obj-proxy',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ornikar/jest-config-react",
3
- "version": "9.4.1",
3
+ "version": "9.6.0",
4
4
  "description": "✅⚛️ jest config for react",
5
5
  "repository": "ornikar/shared-configs",
6
6
  "main": "jest-preset.js",
@@ -29,5 +29,5 @@
29
29
  "react": "17.0.2",
30
30
  "react-dom": "17.0.2"
31
31
  },
32
- "gitHead": "e8854060fac2ebe723af742f806c3c1cc1253748"
32
+ "gitHead": "da7e24d3f68f523b77aca25578d444d101f4dae7"
33
33
  }
@@ -3,8 +3,8 @@
3
3
  const path = require('path');
4
4
 
5
5
  module.exports = {
6
- process(src, filename) {
7
- const assetFilename = JSON.stringify(path.basename(filename));
6
+ process(src, filePath) {
7
+ const assetFilename = JSON.stringify(path.basename(filePath));
8
8
  return `module.exports = ${assetFilename};`;
9
9
  },
10
10
  };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ exports.process = function process(src, filePath) {
6
+ const assetFilename = JSON.stringify(path.basename(filePath));
7
+ return `
8
+ const { jsx } = require('react/jsx-runtime');
9
+ function JestSvgComponent(props) {
10
+ return jsx(
11
+ 'svg',
12
+ Object.assign({}, props, {'data-file-name': ${assetFilename}})
13
+ );
14
+ }
15
+ module.exports = JestSvgComponent;
16
+ `;
17
+ };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const { process } = require('./svg-transformer-inline');
5
+
6
+ exports.process = (src, filePath) => {
7
+ const assetFilename = JSON.stringify(path.basename(filePath));
8
+ const content = process(src, filePath);
9
+ return content.replace(
10
+ /module.exports = (.*);/,
11
+ `module.exports = new Proxy({}, {
12
+ get: function getter(target, key) {
13
+ if (key === '__esModule') {
14
+ return true;
15
+ }
16
+ if (key === 'default') {
17
+ return ${assetFilename};
18
+ }
19
+ if (key === 'ReactComponent') {
20
+ return $1;
21
+ }
22
+ throw new Error('Invalid key for svg-transformer jest mock: ' + key);
23
+ }
24
+ });`,
25
+ );
26
+ };