Socket
Socket
Sign inDemoInstall

@swc/jest

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swc/jest - npm Package Compare versions

Comparing version 0.2.20 to 0.2.21

42

index.js

@@ -32,2 +32,13 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

@@ -52,9 +63,15 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {

function createTransformer(swcTransformOpts) {
var _a, _b;
var computedSwcOptions = buildSwcTransformOpts(swcTransformOpts);
var cacheKeyFunction = (0, create_cache_key_function_1.default)([], [JSON.stringify(computedSwcOptions)]);
var _c = (_b = (_a = swcTransformOpts === null || swcTransformOpts === void 0 ? void 0 : swcTransformOpts.experimental) === null || _a === void 0 ? void 0 : _a.customCoverageInstrumentation) !== null && _b !== void 0 ? _b : {}, canInstrument = _c.enabled, instrumentOptions = __rest(_c, ["enabled"]);
return {
canInstrument: !!canInstrument,
process: function (src, filename, jestOptions) {
// Determine if we actually instrument codes if jest runs with --coverage
insertInstrumentationOptions(jestOptions, !!canInstrument, computedSwcOptions, instrumentOptions);
return (0, core_1.transformSync)(src, __assign(__assign({}, computedSwcOptions), { module: __assign(__assign({}, computedSwcOptions.module), { type: (jestOptions.supportsStaticESM ? 'es6' : 'commonjs') }), filename: filename }));
},
processAsync: function (src, filename) {
processAsync: function (src, filename, jestOptions) {
insertInstrumentationOptions(jestOptions, !!canInstrument, computedSwcOptions, instrumentOptions);
return (0, core_1.transform)(src, __assign(__assign({}, computedSwcOptions), { module: __assign(__assign({}, computedSwcOptions.module), {

@@ -99,3 +116,4 @@ // async transform is always ESM

var _a;
var computedSwcOptions = swcOptions || getOptionsFromSwrc();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var _b = swcOptions || getOptionsFromSwrc(), experimental = _b.experimental, computedSwcOptions = __rest(_b, ["experimental"]);
if (!((_a = computedSwcOptions.jsc) === null || _a === void 0 ? void 0 : _a.target)) {

@@ -112,2 +130,22 @@ set(computedSwcOptions, 'jsc.target',

}
function insertInstrumentationOptions(jestOptions, canInstrument, swcTransformOpts, instrumentOptions) {
var _a, _b, _c, _d;
var shouldInstrument = jestOptions.instrument && canInstrument;
if (!shouldInstrument) {
return swcTransformOpts;
}
if ((_c = (_b = (_a = swcTransformOpts === null || swcTransformOpts === void 0 ? void 0 : swcTransformOpts.jsc) === null || _a === void 0 ? void 0 : _a.experimental) === null || _b === void 0 ? void 0 : _b.plugins) === null || _c === void 0 ? void 0 : _c.some(function (x) { return x[0] === 'swc-plugin-coverage-instrument'; })) {
return;
}
if (!swcTransformOpts.jsc) {
swcTransformOpts.jsc = {};
}
if (!swcTransformOpts.jsc.experimental) {
swcTransformOpts.jsc.experimental = {};
}
if (!Array.isArray(!swcTransformOpts.jsc.experimental.plugins)) {
swcTransformOpts.jsc.experimental.plugins = [];
}
(_d = swcTransformOpts.jsc.experimental.plugins) === null || _d === void 0 ? void 0 : _d.push(['swc-plugin-coverage-instrument', instrumentOptions !== null && instrumentOptions !== void 0 ? instrumentOptions : {}]);
}
function set(obj, path, value) {

@@ -114,0 +152,0 @@ var o = obj;

7

package.json
{
"name": "@swc/jest",
"version": "0.2.20",
"version": "0.2.21",
"description": "swc integration for jest",

@@ -32,3 +32,3 @@ "main": "index.js",

"@jest/transform": "^27.5.1",
"@swc/core": "^1.2.85",
"@swc/core": "^1.2.177",
"@types/node": "^16.11.12",

@@ -46,3 +46,6 @@ "@typescript-eslint/eslint-plugin": "^5.6.0",

"index.js"
],
"workspaces": [
"examples/react"
]
}
# @swc/jest
[swc][] binding for the jest
[SWC][] binding for Jest.

@@ -26,3 +26,3 @@ ## Installation

It will load swc configuration from `.swcrc` in default. You also can custom it:
It will load the SWC configuration from `.swcrc` by default. You also can customize it:

@@ -36,3 +36,3 @@ ```js

transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, /* custom configuration in jest */ }],
'^.+\\.(t|j)sx?$': ['@swc/jest', { ...config, /* custom configuration in Jest */ }],
},

@@ -44,7 +44,7 @@ }

### Q: Jest use CommonJS in default. But I want to use ESM.
### Q: Jest uses CommonJS by default. But I want to use ESM.
A: Setup Jest following this [Guide](https://jestjs.io/docs/ecmascript-modules).
For JavaScript, it need to configure `package.json`:
For JavaScript, edit `package.json` as follows:

@@ -58,3 +58,3 @@ ```json

For TypeScript, it need some configuration in `jest.config.js`:
For TypeScript, edit `jest.config.js` as follows:

@@ -90,3 +90,3 @@ ```js

You can customize this by setting an explicit version in your config:
You can customize this by setting an explicit version in `jest.config.js`:

@@ -112,2 +112,2 @@ ```js

[swc]: https://swc.rs
[SWC]: https://swc.rs
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc