jest-worker
Advanced tools
Comparing version 30.0.0-alpha.5 to 30.0.0-alpha.6
@@ -8,4 +8,2 @@ /** | ||
/// <reference types="node" /> | ||
import {ForkOptions} from 'child_process'; | ||
@@ -12,0 +10,0 @@ import {ResourceLimits} from 'worker_threads'; |
@@ -24,3 +24,3 @@ /*! | ||
var _types = __webpack_require__("./src/types.ts"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -405,3 +405,3 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
var _BaseWorkerPool = _interopRequireDefault(__webpack_require__("./src/base/BaseWorkerPool.ts")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -450,3 +450,3 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
var _types = __webpack_require__("./src/types.ts"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -684,3 +684,4 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
var _WorkerAbstract = _interopRequireDefault(__webpack_require__("./src/workers/WorkerAbstract.ts")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _safeMessageTransferring = __webpack_require__("./src/workers/safeMessageTransferring.ts"); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -864,3 +865,3 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
case _types.PARENT_MESSAGE_OK: | ||
this._onProcessEnd(null, response[1]); | ||
this._onProcessEnd(null, (0, _safeMessageTransferring.unpackMessage)(response[1])); | ||
break; | ||
@@ -890,3 +891,3 @@ case _types.PARENT_MESSAGE_CLIENT_ERROR: | ||
case _types.PARENT_MESSAGE_CUSTOM: | ||
this._onCustomMessage(response[1]); | ||
this._onCustomMessage((0, _safeMessageTransferring.unpackMessage)(response[1])); | ||
break; | ||
@@ -1119,3 +1120,4 @@ case _types.PARENT_MESSAGE_MEM_USAGE: | ||
var _WorkerAbstract = _interopRequireDefault(__webpack_require__("./src/workers/WorkerAbstract.ts")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _safeMessageTransferring = __webpack_require__("./src/workers/safeMessageTransferring.ts"); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -1232,3 +1234,3 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
case _types.PARENT_MESSAGE_OK: | ||
this._onProcessEnd(null, response[1]); | ||
this._onProcessEnd(null, (0, _safeMessageTransferring.unpackMessage)(response[1])); | ||
break; | ||
@@ -1261,3 +1263,3 @@ case _types.PARENT_MESSAGE_CLIENT_ERROR: | ||
case _types.PARENT_MESSAGE_CUSTOM: | ||
this._onCustomMessage(response[1]); | ||
this._onCustomMessage((0, _safeMessageTransferring.unpackMessage)(response[1])); | ||
break; | ||
@@ -1554,2 +1556,32 @@ case _types.PARENT_MESSAGE_MEM_USAGE: | ||
/***/ "./src/workers/isDataCloneError.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.isDataCloneError = isDataCloneError; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// https://webidl.spec.whatwg.org/#datacloneerror | ||
const DATA_CLONE_ERROR_CODE = 25; | ||
/** | ||
* Unfortunately, [`util.types.isNativeError(value)`](https://nodejs.org/api/util.html#utiltypesisnativeerrorvalue) | ||
* return `false` for `DataCloneError` error. | ||
* For this reason, try to detect it in this way | ||
*/ | ||
function isDataCloneError(error) { | ||
return error != null && typeof error === 'object' && 'name' in error && error.name === 'DataCloneError' && 'message' in error && typeof error.message === 'string' && 'code' in error && error.code === DATA_CLONE_ERROR_CODE; | ||
} | ||
/***/ }), | ||
/***/ "./src/workers/messageParent.ts": | ||
@@ -1564,2 +1596,9 @@ /***/ ((__unused_webpack_module, exports, __webpack_require__) => { | ||
exports["default"] = messageParent; | ||
function _nodeUtil() { | ||
const data = require("node:util"); | ||
_nodeUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _worker_threads() { | ||
@@ -1573,2 +1612,4 @@ const data = require("worker_threads"); | ||
var _types = __webpack_require__("./src/types.ts"); | ||
var _isDataCloneError = __webpack_require__("./src/workers/isDataCloneError.ts"); | ||
var _safeMessageTransferring = __webpack_require__("./src/workers/safeMessageTransferring.ts"); | ||
/** | ||
@@ -1583,5 +1624,27 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
if (!_worker_threads().isMainThread && _worker_threads().parentPort != null) { | ||
_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_CUSTOM, message]); | ||
try { | ||
_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_CUSTOM, message]); | ||
} catch (error) { | ||
// Try to handle https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal | ||
// for `symbols` and `functions` | ||
if ((0, _isDataCloneError.isDataCloneError)(error)) { | ||
_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_CUSTOM, (0, _safeMessageTransferring.packMessage)(message)]); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} else if (typeof parentProcess.send === 'function') { | ||
parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]); | ||
try { | ||
parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, message]); | ||
} catch (error) { | ||
if (_nodeUtil().types.isNativeError(error) && | ||
// if .send is a function, it's a serialization issue | ||
!error.message.includes('.send is not a function')) { | ||
// Apply specific serialization only in error cases | ||
// to avoid affecting performance in regular cases. | ||
parentProcess.send([_types.PARENT_MESSAGE_CUSTOM, (0, _safeMessageTransferring.packMessage)(message)]); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} else { | ||
@@ -1592,2 +1655,52 @@ throw new TypeError('"messageParent" can only be used inside a worker'); | ||
/***/ }), | ||
/***/ "./src/workers/safeMessageTransferring.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.packMessage = packMessage; | ||
exports.unpackMessage = unpackMessage; | ||
function _structuredClone() { | ||
const data = require("@ungap/structured-clone"); | ||
_structuredClone = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
function packMessage(message) { | ||
return { | ||
__STRUCTURED_CLONE_SERIALIZED__: true, | ||
/** | ||
* Use the `json: true` option to avoid errors | ||
* caused by `function` or `symbol` types. | ||
* It's not ideal to lose `function` and `symbol` types, | ||
* but reliability is more important. | ||
*/ | ||
data: (0, _structuredClone().serialize)(message, { | ||
json: true | ||
}) | ||
}; | ||
} | ||
function isTransferringContainer(message) { | ||
return message != null && typeof message === 'object' && '__STRUCTURED_CLONE_SERIALIZED__' in message && 'data' in message; | ||
} | ||
function unpackMessage(message) { | ||
if (isTransferringContainer(message)) { | ||
return (0, _structuredClone().deserialize)(message.data); | ||
} | ||
return message; | ||
} | ||
/***/ }) | ||
@@ -1623,3 +1736,3 @@ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports). | ||
(() => { | ||
@@ -1677,3 +1790,3 @@ var exports = __webpack_exports__; | ||
var _messageParent = _interopRequireDefault(__webpack_require__("./src/workers/messageParent.ts")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
/** | ||
@@ -1680,0 +1793,0 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. |
@@ -65,2 +65,52 @@ /*! | ||
/***/ }), | ||
/***/ "./src/workers/safeMessageTransferring.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.packMessage = packMessage; | ||
exports.unpackMessage = unpackMessage; | ||
function _structuredClone() { | ||
const data = require("@ungap/structured-clone"); | ||
_structuredClone = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
function packMessage(message) { | ||
return { | ||
__STRUCTURED_CLONE_SERIALIZED__: true, | ||
/** | ||
* Use the `json: true` option to avoid errors | ||
* caused by `function` or `symbol` types. | ||
* It's not ideal to lose `function` and `symbol` types, | ||
* but reliability is more important. | ||
*/ | ||
data: (0, _structuredClone().serialize)(message, { | ||
json: true | ||
}) | ||
}; | ||
} | ||
function isTransferringContainer(message) { | ||
return message != null && typeof message === 'object' && '__STRUCTURED_CLONE_SERIALIZED__' in message && 'data' in message; | ||
} | ||
function unpackMessage(message) { | ||
if (isTransferringContainer(message)) { | ||
return (0, _structuredClone().deserialize)(message.data); | ||
} | ||
return message; | ||
} | ||
/***/ }) | ||
@@ -96,6 +146,11 @@ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
function _nodeUtil() { | ||
const data = require("node:util"); | ||
_nodeUtil = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jestUtil() { | ||
@@ -109,2 +164,3 @@ const data = require("jest-util"); | ||
var _types = __webpack_require__("./src/types.ts"); | ||
var _safeMessageTransferring = __webpack_require__("./src/workers/safeMessageTransferring.ts"); | ||
/** | ||
@@ -173,3 +229,15 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
} | ||
process.send([_types.PARENT_MESSAGE_OK, result]); | ||
try { | ||
process.send([_types.PARENT_MESSAGE_OK, result]); | ||
} catch (error) { | ||
if (_nodeUtil().types.isNativeError(error) && | ||
// if .send is a function, it's a serialization issue | ||
!error.message.includes('.send is not a function')) { | ||
// Apply specific serialization only in error cases | ||
// to avoid affecting performance in regular cases. | ||
process.send([_types.PARENT_MESSAGE_OK, (0, _safeMessageTransferring.packMessage)(result)]); | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} | ||
@@ -244,6 +312,4 @@ function reportClientError(error) { | ||
} | ||
})(); | ||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; |
@@ -65,2 +65,82 @@ /*! | ||
/***/ }), | ||
/***/ "./src/workers/isDataCloneError.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.isDataCloneError = isDataCloneError; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// https://webidl.spec.whatwg.org/#datacloneerror | ||
const DATA_CLONE_ERROR_CODE = 25; | ||
/** | ||
* Unfortunately, [`util.types.isNativeError(value)`](https://nodejs.org/api/util.html#utiltypesisnativeerrorvalue) | ||
* return `false` for `DataCloneError` error. | ||
* For this reason, try to detect it in this way | ||
*/ | ||
function isDataCloneError(error) { | ||
return error != null && typeof error === 'object' && 'name' in error && error.name === 'DataCloneError' && 'message' in error && typeof error.message === 'string' && 'code' in error && error.code === DATA_CLONE_ERROR_CODE; | ||
} | ||
/***/ }), | ||
/***/ "./src/workers/safeMessageTransferring.ts": | ||
/***/ ((__unused_webpack_module, exports) => { | ||
Object.defineProperty(exports, "__esModule", ({ | ||
value: true | ||
})); | ||
exports.packMessage = packMessage; | ||
exports.unpackMessage = unpackMessage; | ||
function _structuredClone() { | ||
const data = require("@ungap/structured-clone"); | ||
_structuredClone = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
function packMessage(message) { | ||
return { | ||
__STRUCTURED_CLONE_SERIALIZED__: true, | ||
/** | ||
* Use the `json: true` option to avoid errors | ||
* caused by `function` or `symbol` types. | ||
* It's not ideal to lose `function` and `symbol` types, | ||
* but reliability is more important. | ||
*/ | ||
data: (0, _structuredClone().serialize)(message, { | ||
json: true | ||
}) | ||
}; | ||
} | ||
function isTransferringContainer(message) { | ||
return message != null && typeof message === 'object' && '__STRUCTURED_CLONE_SERIALIZED__' in message && 'data' in message; | ||
} | ||
function unpackMessage(message) { | ||
if (isTransferringContainer(message)) { | ||
return (0, _structuredClone().deserialize)(message.data); | ||
} | ||
return message; | ||
} | ||
/***/ }) | ||
@@ -96,4 +176,2 @@ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
@@ -116,2 +194,4 @@ | ||
var _types = __webpack_require__("./src/types.ts"); | ||
var _isDataCloneError = __webpack_require__("./src/workers/isDataCloneError.ts"); | ||
var _safeMessageTransferring = __webpack_require__("./src/workers/safeMessageTransferring.ts"); | ||
/** | ||
@@ -191,6 +271,16 @@ * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
} catch (error) { | ||
// Handling it here to avoid unhandled `DataCloneError` rejection | ||
let resolvedError = error; | ||
// Try to handle https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal | ||
// for `symbols` and `functions` | ||
if ((0, _isDataCloneError.isDataCloneError)(error)) { | ||
try { | ||
_worker_threads().parentPort.postMessage([_types.PARENT_MESSAGE_OK, (0, _safeMessageTransferring.packMessage)(result)]); | ||
return; | ||
} catch (secondTryError) { | ||
resolvedError = secondTryError; | ||
} | ||
} | ||
// Handling it here to avoid unhandled rejection | ||
// which is hard to distinguish on the parent side | ||
// (such error doesn't have any message or stack trace) | ||
reportClientError(error); | ||
reportClientError(resolvedError); | ||
} | ||
@@ -259,6 +349,4 @@ } | ||
} | ||
})(); | ||
module.exports = __webpack_exports__; | ||
/******/ })() | ||
; |
{ | ||
"name": "jest-worker", | ||
"version": "30.0.0-alpha.5", | ||
"version": "30.0.0-alpha.6", | ||
"repository": { | ||
@@ -23,3 +23,4 @@ "type": "git", | ||
"@types/node": "*", | ||
"jest-util": "30.0.0-alpha.5", | ||
"@ungap/structured-clone": "^1.2.0", | ||
"jest-util": "30.0.0-alpha.6", | ||
"merge-stream": "^2.0.0", | ||
@@ -32,4 +33,5 @@ "supports-color": "^8.0.0" | ||
"@types/supports-color": "^8.1.0", | ||
"@types/ungap__structured-clone": "^1.2.0", | ||
"get-stream": "^6.0.0", | ||
"jest-leak-detector": "30.0.0-alpha.5", | ||
"jest-leak-detector": "30.0.0-alpha.6", | ||
"worker-farm": "^1.6.0" | ||
@@ -43,3 +45,3 @@ }, | ||
}, | ||
"gitHead": "fa24a3bdd6682978d76799265016fb9d5bff135e" | ||
"gitHead": "ba74b7de1b9cca88daf33f9d1b46bfe2b7f485a5" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108694
2707
5
7
+ Added@jest/pattern@30.0.0-alpha.6(transitive)
+ Added@jest/schemas@30.0.0-alpha.6(transitive)
+ Added@jest/types@30.0.0-alpha.6(transitive)
+ Added@sinclair/typebox@0.33.9(transitive)
+ Added@ungap/structured-clone@1.2.0(transitive)
+ Addedjest-regex-util@30.0.0-alpha.6(transitive)
+ Addedjest-util@30.0.0-alpha.6(transitive)
- Removed@jest/pattern@30.0.0-alpha.5(transitive)
- Removed@jest/schemas@30.0.0-alpha.5(transitive)
- Removed@jest/types@30.0.0-alpha.5(transitive)
- Removed@sinclair/typebox@0.32.35(transitive)
- Removedjest-regex-util@30.0.0-alpha.5(transitive)
- Removedjest-util@30.0.0-alpha.5(transitive)
Updatedjest-util@30.0.0-alpha.6