@ornikar/jest-config-react-native 1.0.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/.eslintrc.json +4 -0
- package/CHANGELOG.md +11 -0
- package/README.md +3 -0
- package/__mocks__/@storybook/addon-actions.js +5 -0
- package/__mocks__/@storybook/react-native.jsx +93 -0
- package/jest-preset.js +29 -0
- package/package.json +32 -0
package/.eslintrc.json
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.0.0 (2021-10-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add jest-config-react-native package ([#527](https://github.com/ornikar/shared-configs/issues/527)) ([d35126e](https://github.com/ornikar/shared-configs/commit/d35126e2fd43eb728129b096db54094370bfd8b5))
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-env jest */
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const { render } = require('@testing-library/react-native');
|
|
6
|
+
const React = require('react');
|
|
7
|
+
|
|
8
|
+
const decorateStory = (storyFn, decorators) =>
|
|
9
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
10
|
+
decorators.reduce(
|
|
11
|
+
(decorated, decorator) =>
|
|
12
|
+
(context = {}) =>
|
|
13
|
+
decorator(
|
|
14
|
+
(p = {}) =>
|
|
15
|
+
decorated(
|
|
16
|
+
// MUTATION !
|
|
17
|
+
Object.assign(
|
|
18
|
+
context,
|
|
19
|
+
p,
|
|
20
|
+
{
|
|
21
|
+
parameters: Object.assign(context.parameters || {}, p.parameters),
|
|
22
|
+
},
|
|
23
|
+
{ options: Object.assign(context.options || {}, p.options) },
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
context,
|
|
27
|
+
),
|
|
28
|
+
storyFn,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
exports.decorateStory = decorateStory;
|
|
32
|
+
|
|
33
|
+
const globalDecorators = [];
|
|
34
|
+
|
|
35
|
+
// Mocked version of `import { addDecorator } from '@storybook/react-native'`.
|
|
36
|
+
exports.addDecorator = (decorator) => {
|
|
37
|
+
globalDecorators.push(decorator);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Mocked version of `import { action } from '@storybook/react-native'`.
|
|
41
|
+
exports.action = (actionName) => jest.fn();
|
|
42
|
+
|
|
43
|
+
// Mocked version of: `import { storiesOf } from '@storybook/react-native'`
|
|
44
|
+
exports.storiesOf = (groupName) => {
|
|
45
|
+
const localDecorators = [];
|
|
46
|
+
const localParameters = {};
|
|
47
|
+
|
|
48
|
+
// Mocked API to generate tests from & snapshot stories.
|
|
49
|
+
const api = {
|
|
50
|
+
add(storyName, story, storyParameters = {}) {
|
|
51
|
+
const parameters = { ...localParameters, ...storyParameters };
|
|
52
|
+
const context = { name: storyName, parameters };
|
|
53
|
+
const { jest } = parameters;
|
|
54
|
+
const { ignore, ignoreDecorators, createBeforeAfterEachCallbacks } = jest || {};
|
|
55
|
+
|
|
56
|
+
if (ignore) {
|
|
57
|
+
test.skip(storyName, () => {});
|
|
58
|
+
return api;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe(groupName, () => {
|
|
62
|
+
if (createBeforeAfterEachCallbacks) {
|
|
63
|
+
const { before, after } = createBeforeAfterEachCallbacks();
|
|
64
|
+
if (before) beforeEach(before);
|
|
65
|
+
if (after) afterEach(after);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
it(storyName, () => {
|
|
69
|
+
const WrappingComponent = ignoreDecorators
|
|
70
|
+
? undefined
|
|
71
|
+
: ({ children }) => decorateStory(() => children, [...localDecorators, ...globalDecorators])(context);
|
|
72
|
+
|
|
73
|
+
const component = render(React.createElement(WrappingComponent, { children: story(context) }));
|
|
74
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return api;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
addParameters(parameters) {
|
|
82
|
+
Object.assign(localParameters, parameters);
|
|
83
|
+
return api;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
addDecorator(decorator) {
|
|
87
|
+
localDecorators.push(decorator);
|
|
88
|
+
return api;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return api;
|
|
93
|
+
};
|
package/jest-preset.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jestPreset = require('@ornikar/jest-config/jest-preset');
|
|
4
|
+
const expoPreset = require('jest-expo/jest-preset');
|
|
5
|
+
const mergeWith = require('lodash.mergewith');
|
|
6
|
+
|
|
7
|
+
function customizer(objValue, srcValue) {
|
|
8
|
+
if (Array.isArray(objValue)) {
|
|
9
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
10
|
+
return objValue.concat(srcValue);
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const basePreset = mergeWith(expoPreset, jestPreset, customizer);
|
|
16
|
+
|
|
17
|
+
module.exports = mergeWith(
|
|
18
|
+
basePreset,
|
|
19
|
+
{
|
|
20
|
+
testMatch: ['<rootDir>/src/**/stories.{ts,tsx}', '<rootDir>/src/**/*.stories.{ts,tsx}'],
|
|
21
|
+
moduleNameMapper: {
|
|
22
|
+
'\\.css': '<rootDir>/src/__mocks__/styleMock.ts',
|
|
23
|
+
'^@storybook/addon-actions$': require.resolve('./__mocks__/@storybook/addon-actions.js'),
|
|
24
|
+
'@storybook/react-native$': require.resolve('./__mocks__/@storybook/react-native.jsx'),
|
|
25
|
+
'^@storybook/react-native$': require.resolve('./__mocks__/@storybook/react-native.jsx'),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
customizer,
|
|
29
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ornikar/jest-config-react-native",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "jest config",
|
|
5
|
+
"repository": "ornikar/shared-configs",
|
|
6
|
+
"main": "jest-preset.js",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=12.13.0"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@testing-library/react-hooks": "^7.0.0",
|
|
16
|
+
"@testing-library/react-native": "^7.2.0",
|
|
17
|
+
"jest-expo": "^41.0.0",
|
|
18
|
+
"react": "^16.13.0",
|
|
19
|
+
"react-dom": "^16.13.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ornikar/jest-config": "^5.5.0",
|
|
23
|
+
"lodash.mergewith": "4.6.2"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@testing-library/react-hooks": "7.0.1",
|
|
27
|
+
"@testing-library/react-native": "7.2.0",
|
|
28
|
+
"jest-expo": "41.0.0",
|
|
29
|
+
"react": "16.13.1"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "3e392cda6169eaadf64ecddb885c3913c1c34c8f"
|
|
32
|
+
}
|