Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@mapbox/esbuild-jest
Advanced tools
@mapbox/esbuild-jest
NOTE: This is a fork of esbuild-jest with some incompatible differences.
Our Jest preset and transformer for compiling files with ESBuild and generating accurate coverage.
📦 npm install --save-dev @mapbox/esbuild-jest esbuild
esbuild-jest is not an officially supported Mapbox product, and is developed on a best-effort basis. Issues filed from third-party contributors may not be triaged in a timely manner.
In your Jest configuration file:
{
"transform": {
"^.+\\.(tsx?|jsx?)$": "@mapbox/esbuild-jest"
}
}
You can also specify ESBuild compatible options like so:
{
"transform": {
"^.+\\.(tsx?|jsx?|css)$": [
"@mapbox/esbuild-jest",
{
"loader": {
".css": "text"
}
}
]
}
}
If you'd like to follow Mapbox conventions, you can use our Jest preset.
In your Jest configuration file:
{
"preset": "@mapbox/esbuild-jest"
}
In this configuration, .js
, .jsx
, .ts
, and .tsx
files are transformed by ESBuild. .css
files are loaded as plaintext.
Coverage is also enabled with high (80%) thresholds.
Our Jest preset expects files to be laid out in a certain way:
src/
- source files for coverage in this directory.test/
- test files in this directory, with a suffix of either .test
or .spec
.
index.test.ts
@mapbox/esbuild-jest
may require code changes in two ways:
jest.mock()
are not hoisted to the top of the file.jest.spyOn
.There are multiple ways around this.
Stub the entire module in a separate file that is ESM imported before other files.
test_utils/myMock.ts
:
jest.mock('../../src/myFile', () => {
})
myFile.test.ts
:
// Important that these are first.
import './test_utils/myMock.ts';
import { myFunction } from '../src/myFile';
// ...
Use the following workaround below that "allows" a module to be mocked.
Sourced from: https://github.com/evanw/esbuild/issues/412#issuecomment-723047255
export interface HasSpyOn {
spyOn(): jest.SpyInstance;
}
export function enableSpyOn<T extends Function>(fn: T): T & HasSpyOn {
if ('process' in globalThis && globalThis.process.env.NODE_ENV === 'test') {
let name = fn.name,
obj = { [name]: fn };
(fn as any) = function (this: any) {
return obj[name].apply(this, arguments);
};
(fn as any).spyOn = () => jest.spyOn(obj, name);
}
return fn as any;
}
// file.ts
import { enableSpyOn } from 'helpers/enableSpyOn';
export const fn = enableSpyOn(function fn() {});
// file_test.ts
import { fn } from './file';
let spy = fn.spyOn();
esbuild-jest is provided under the terms of the MIT License
FAQs
Jest transformer and preset for transpiling using ESBuild.
The npm package @mapbox/esbuild-jest receives a total of 5 weekly downloads. As such, @mapbox/esbuild-jest popularity was classified as not popular.
We found that @mapbox/esbuild-jest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.