@papillonarts/setup 0.40.0 → 0.42.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/build/jest/index.d.ts +1 -0
- package/build/jest/index.d.ts.map +1 -1
- package/build/jest/index.js +26 -1
- package/build/jest/setup.d.ts.map +1 -1
- package/build/jest/setup.js +82 -0
- package/build/jest/utility.d.ts +73 -0
- package/build/jest/utility.d.ts.map +1 -0
- package/build/jest/utility.js +166 -0
- package/package.json +2 -2
package/build/jest/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA"}
|
package/build/jest/index.js
CHANGED
|
@@ -3,17 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "createMockStore", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _utility.createMockStore;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "getJestSetup", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
9
15
|
return _config.getJestSetup;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "renderSnapshot", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _utility.renderSnapshot;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "renderSnapshotAsync", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _utility.renderSnapshotAsync;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
12
30
|
Object.defineProperty(exports, "runJestSetup", {
|
|
13
31
|
enumerable: true,
|
|
14
32
|
get: function get() {
|
|
15
33
|
return _setup.runJestSetup;
|
|
16
34
|
}
|
|
17
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "waitFor", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _utility.waitFor;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
18
42
|
var _config = require("./config");
|
|
19
|
-
var _setup = require("./setup");
|
|
43
|
+
var _setup = require("./setup");
|
|
44
|
+
var _utility = require("./utility");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/jest/setup.ts"],"names":[],"mappings":"AAGA,OAAO,uBAAuB,CAAA;AAG9B,wBAAgB,YAAY,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/jest/setup.ts"],"names":[],"mappings":"AAGA,OAAO,uBAAuB,CAAA;AAG9B,wBAAgB,YAAY,SAmG3B"}
|
package/build/jest/setup.js
CHANGED
|
@@ -11,6 +11,88 @@ var _snapshotDiff = require("snapshot-diff");
|
|
|
11
11
|
// https://github.com/jest-community/snapshot-diff
|
|
12
12
|
|
|
13
13
|
function runJestSetup() {
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes Date.prototype methods to output deterministic ISO-like UTC strings.
|
|
16
|
+
* This prevents snapshot churn across different environments/timezones.
|
|
17
|
+
*
|
|
18
|
+
* Format: yyyy-MM-ddTHH:mm:ssZ (24-hour, explicit UTC designator)
|
|
19
|
+
* Timezone: UTC (set via process.env.TZ)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* new Date('2020-07-05T19:04:15Z').toLocaleString() // "2020-07-05T19:04:15Z"
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Force deterministic date/time output in tests (avoids locale/timezone snapshot churn)
|
|
26
|
+
process.env.TZ = 'UTC';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Pads a number with leading zero if less than 10.
|
|
30
|
+
* @param {number} n - Number to pad
|
|
31
|
+
* @returns {string} Padded string
|
|
32
|
+
*/
|
|
33
|
+
function pad2(n) {
|
|
34
|
+
return n < 10 ? "0".concat(n) : "".concat(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Formats a date-time as "yyyy-MM-ddTHH:mm:ssZ" in UTC.
|
|
39
|
+
* @param {Date} date - Date to format
|
|
40
|
+
* @returns {string} Formatted ISO-like date-time string
|
|
41
|
+
*/
|
|
42
|
+
function formatAsISODateTime(date) {
|
|
43
|
+
var d = pad2(date.getUTCDate());
|
|
44
|
+
var m = pad2(date.getUTCMonth() + 1);
|
|
45
|
+
var y = date.getUTCFullYear();
|
|
46
|
+
var hh = pad2(date.getUTCHours());
|
|
47
|
+
var mm = pad2(date.getUTCMinutes());
|
|
48
|
+
var ss = pad2(date.getUTCSeconds());
|
|
49
|
+
return "".concat(y, "-").concat(m, "-").concat(d, "T").concat(hh, ":").concat(mm, ":").concat(ss, "Z");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Formats a date as "yyyy-MM-dd" in UTC.
|
|
54
|
+
* @param {Date} date - Date to format
|
|
55
|
+
* @returns {string} Formatted ISO-like date string
|
|
56
|
+
*/
|
|
57
|
+
function formatAsISODate(date) {
|
|
58
|
+
var d = pad2(date.getUTCDate());
|
|
59
|
+
var m = pad2(date.getUTCMonth() + 1);
|
|
60
|
+
var y = date.getUTCFullYear();
|
|
61
|
+
return "".concat(y, "-").concat(m, "-").concat(d);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Formats a time as "HH:mm:ssZ" in UTC.
|
|
66
|
+
* @param {Date} date - Date to format
|
|
67
|
+
* @returns {string} Formatted ISO-like time string
|
|
68
|
+
*/
|
|
69
|
+
function formatAsISOTime(date) {
|
|
70
|
+
var hh = pad2(date.getUTCHours());
|
|
71
|
+
var mm = pad2(date.getUTCMinutes());
|
|
72
|
+
var ss = pad2(date.getUTCSeconds());
|
|
73
|
+
return "".concat(hh, ":").concat(mm, ":").concat(ss, "Z");
|
|
74
|
+
}
|
|
75
|
+
var originalToLocaleString = Date.prototype.toLocaleString;
|
|
76
|
+
var originalToLocaleDateString = Date.prototype.toLocaleDateString;
|
|
77
|
+
var originalToLocaleTimeString = Date.prototype.toLocaleTimeString;
|
|
78
|
+
Date.prototype.toLocaleString = function toLocaleStringPatched(locale, options) {
|
|
79
|
+
if (!locale && !options) {
|
|
80
|
+
return formatAsISODateTime(this);
|
|
81
|
+
}
|
|
82
|
+
return originalToLocaleString.call(this, locale, options);
|
|
83
|
+
};
|
|
84
|
+
Date.prototype.toLocaleDateString = function toLocaleDateStringPatched(locale, options) {
|
|
85
|
+
if (!locale && !options) {
|
|
86
|
+
return formatAsISODate(this);
|
|
87
|
+
}
|
|
88
|
+
return originalToLocaleDateString.call(this, locale, options);
|
|
89
|
+
};
|
|
90
|
+
Date.prototype.toLocaleTimeString = function toLocaleTimeStringPatched(locale, options) {
|
|
91
|
+
if (!locale && !options) {
|
|
92
|
+
return formatAsISOTime(this);
|
|
93
|
+
}
|
|
94
|
+
return originalToLocaleTimeString.call(this, locale, options);
|
|
95
|
+
};
|
|
14
96
|
global.act = _react.act;
|
|
15
97
|
global.cleanup = _react.cleanup;
|
|
16
98
|
global.fireEvent = _react.fireEvent;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test utilities provided by @papillonarts/setup/jest.
|
|
3
|
+
*
|
|
4
|
+
* These utilities wrap common testing patterns used across packages,
|
|
5
|
+
* particularly for snapshot testing with React components.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Renders a component and matches it against a snapshot.
|
|
9
|
+
*
|
|
10
|
+
* @param component - JSX element to render
|
|
11
|
+
* @returns Snapshot matcher result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { renderSnapshot } from '@papillonarts/setup/jest'
|
|
16
|
+
* import { defaults } from './Component.feature'
|
|
17
|
+
*
|
|
18
|
+
* test('must match defaults()', () => {
|
|
19
|
+
* renderSnapshot(defaults())
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { ReactElement } from 'react';
|
|
24
|
+
export declare const renderSnapshot: (component: ReactElement) => any;
|
|
25
|
+
/**
|
|
26
|
+
* Renders an async component and matches it against a snapshot.
|
|
27
|
+
* Wraps the render in React's act() to ensure all updates are flushed.
|
|
28
|
+
*
|
|
29
|
+
* @param component - JSX element to render (can be a Promise)
|
|
30
|
+
* @returns Promise that resolves to snapshot matcher result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { renderSnapshotAsync } from '@papillonarts/setup/jest'
|
|
35
|
+
* import { async } from './Component.feature'
|
|
36
|
+
*
|
|
37
|
+
* test('must match async()', async () => {
|
|
38
|
+
* await renderSnapshotAsync(async())
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const renderSnapshotAsync: (component: ReactElement | Promise<ReactElement>) => Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a mock store with default configuration.
|
|
45
|
+
* Useful for testing Redux-connected components.
|
|
46
|
+
*
|
|
47
|
+
* @param initialState - Optional initial state for the store
|
|
48
|
+
* @returns Mocked Redux store
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { createMockStore } from '@papillonarts/setup/jest'
|
|
53
|
+
*
|
|
54
|
+
* const store = createMockStore({ context: { cars: [] } })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const createMockStore: (initialState?: {}) => {};
|
|
58
|
+
/**
|
|
59
|
+
* Waits for a condition to be true with timeout.
|
|
60
|
+
* Useful for testing async state updates.
|
|
61
|
+
*
|
|
62
|
+
* @param condition - Function that returns true when condition is met
|
|
63
|
+
* @param timeout - Maximum time to wait in milliseconds (default: 1000)
|
|
64
|
+
* @param interval - Check interval in milliseconds (default: 50)
|
|
65
|
+
* @returns Promise that resolves when condition is true
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* await waitFor(() => element.textContent === 'Loaded', 2000)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const waitFor: (condition: () => boolean, timeout?: number, interval?: number) => Promise<void>;
|
|
73
|
+
//# sourceMappingURL=utility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../../src/jest/utility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEzC,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,QAAqD,CAAA;AAE3G;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,GAAU,WAAW,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,iBACG,CAAA;AAE5F;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,iBAAiB,OAIhD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO,GAAU,WAAW,MAAM,OAAO,EAAE,gBAAc,EAAE,iBAAa,KAAG,OAAO,CAAC,IAAI,CASnG,CAAA"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.waitFor = exports.renderSnapshotAsync = exports.renderSnapshot = exports.createMockStore = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
/**
|
|
11
|
+
* Shared test utilities provided by @papillonarts/setup/jest.
|
|
12
|
+
*
|
|
13
|
+
* These utilities wrap common testing patterns used across packages,
|
|
14
|
+
* particularly for snapshot testing with React components.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Renders a component and matches it against a snapshot.
|
|
18
|
+
*
|
|
19
|
+
* @param component - JSX element to render
|
|
20
|
+
* @returns Snapshot matcher result
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { renderSnapshot } from '@papillonarts/setup/jest'
|
|
25
|
+
* import { defaults } from './Component.feature'
|
|
26
|
+
*
|
|
27
|
+
* test('must match defaults()', () => {
|
|
28
|
+
* renderSnapshot(defaults())
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
var renderSnapshot = exports.renderSnapshot = function renderSnapshot(component) {
|
|
34
|
+
return global.renderToJSON(component).toMatchSnapshot();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Renders an async component and matches it against a snapshot.
|
|
39
|
+
* Wraps the render in React's act() to ensure all updates are flushed.
|
|
40
|
+
*
|
|
41
|
+
* @param component - JSX element to render (can be a Promise)
|
|
42
|
+
* @returns Promise that resolves to snapshot matcher result
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { renderSnapshotAsync } from '@papillonarts/setup/jest'
|
|
47
|
+
* import { async } from './Component.feature'
|
|
48
|
+
*
|
|
49
|
+
* test('must match async()', async () => {
|
|
50
|
+
* await renderSnapshotAsync(async())
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
var renderSnapshotAsync = exports.renderSnapshotAsync = /*#__PURE__*/function () {
|
|
55
|
+
var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(component) {
|
|
56
|
+
return _regenerator["default"].wrap(function (_context2) {
|
|
57
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
_context2.next = 1;
|
|
60
|
+
return global.act(/*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
61
|
+
var _t;
|
|
62
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
63
|
+
while (1) switch (_context.prev = _context.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
_t = global;
|
|
66
|
+
_context.next = 1;
|
|
67
|
+
return component;
|
|
68
|
+
case 1:
|
|
69
|
+
return _context.abrupt("return", _t.renderToJSON.call(_t, _context.sent));
|
|
70
|
+
case 2:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _callee);
|
|
75
|
+
}))).toMatchSnapshot();
|
|
76
|
+
case 1:
|
|
77
|
+
_context2.next = 2;
|
|
78
|
+
return _context2.sent;
|
|
79
|
+
case 2:
|
|
80
|
+
return _context2.abrupt("return", _context2.sent);
|
|
81
|
+
case 3:
|
|
82
|
+
case "end":
|
|
83
|
+
return _context2.stop();
|
|
84
|
+
}
|
|
85
|
+
}, _callee2);
|
|
86
|
+
}));
|
|
87
|
+
return function renderSnapshotAsync(_x) {
|
|
88
|
+
return _ref.apply(this, arguments);
|
|
89
|
+
};
|
|
90
|
+
}();
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates a mock store with default configuration.
|
|
94
|
+
* Useful for testing Redux-connected components.
|
|
95
|
+
*
|
|
96
|
+
* @param initialState - Optional initial state for the store
|
|
97
|
+
* @returns Mocked Redux store
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { createMockStore } from '@papillonarts/setup/jest'
|
|
102
|
+
*
|
|
103
|
+
* const store = createMockStore({ context: { cars: [] } })
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
var createMockStore = exports.createMockStore = function createMockStore() {
|
|
107
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
108
|
+
// This is a placeholder - implement based on your store configuration
|
|
109
|
+
// You may need to import from redux-mock-store or similar
|
|
110
|
+
return initialState;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Waits for a condition to be true with timeout.
|
|
115
|
+
* Useful for testing async state updates.
|
|
116
|
+
*
|
|
117
|
+
* @param condition - Function that returns true when condition is met
|
|
118
|
+
* @param timeout - Maximum time to wait in milliseconds (default: 1000)
|
|
119
|
+
* @param interval - Check interval in milliseconds (default: 50)
|
|
120
|
+
* @returns Promise that resolves when condition is true
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* await waitFor(() => element.textContent === 'Loaded', 2000)
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
var waitFor = exports.waitFor = /*#__PURE__*/function () {
|
|
128
|
+
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(condition) {
|
|
129
|
+
var timeout,
|
|
130
|
+
interval,
|
|
131
|
+
startTime,
|
|
132
|
+
_args3 = arguments;
|
|
133
|
+
return _regenerator["default"].wrap(function (_context3) {
|
|
134
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
135
|
+
case 0:
|
|
136
|
+
timeout = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 1000;
|
|
137
|
+
interval = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : 50;
|
|
138
|
+
startTime = Date.now();
|
|
139
|
+
case 1:
|
|
140
|
+
if (condition()) {
|
|
141
|
+
_context3.next = 4;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
if (!(Date.now() - startTime > timeout)) {
|
|
145
|
+
_context3.next = 2;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
throw new Error("Timeout waiting for condition after ".concat(timeout, "ms"));
|
|
149
|
+
case 2:
|
|
150
|
+
_context3.next = 3;
|
|
151
|
+
return new Promise(function (resolve) {
|
|
152
|
+
return setTimeout(resolve, interval);
|
|
153
|
+
});
|
|
154
|
+
case 3:
|
|
155
|
+
_context3.next = 1;
|
|
156
|
+
break;
|
|
157
|
+
case 4:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context3.stop();
|
|
160
|
+
}
|
|
161
|
+
}, _callee3);
|
|
162
|
+
}));
|
|
163
|
+
return function waitFor(_x2) {
|
|
164
|
+
return _ref3.apply(this, arguments);
|
|
165
|
+
};
|
|
166
|
+
}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@papillonarts/setup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Papillon Arts Setup",
|
|
5
5
|
"homepage": "https://github.com/papillonarts/papillonarts/tree/master/packages/setup",
|
|
6
6
|
"repository": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"build-acceptance": "npm run build",
|
|
38
38
|
"build-release": "npm run build"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "4b8cd00e12214132f87b702855aa37dc506dbadd"
|
|
41
41
|
}
|