├── .gitignore
├── examples
├── names-ts
│ ├── names.ts
│ ├── index.ts
│ └── index.spec.ts
├── ts-jsconfig-paths
│ ├── libs
│ │ └── calculator.ts
│ └── app
│ │ ├── index.ts
│ │ └── index.spec.ts
├── react-js
│ ├── App.js
│ └── main.js
├── react-jsx
│ ├── App.jsx
│ └── main.jsx
└── react-ts
│ ├── App.tsx
│ └── index.tsx
├── src
├── options.ts
├── utils.ts
├── transformer.ts
└── index.ts
├── jest.config.js
├── tsconfig.json
├── tests
├── react-ts.spec.tsx
├── react-jsx.spec.jsx
├── react-ts-mock.spec.tsx
├── react-js.spec.js
└── index.spec.ts
├── aria.config.ts
├── tools
└── build.ts
├── README.md
├── .github
└── workflows
│ └── ci.yml
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .envrc
4 | default.nix
--------------------------------------------------------------------------------
/examples/names-ts/names.ts:
--------------------------------------------------------------------------------
1 | const names = [
2 | "John", "Jane"
3 | ]
4 |
5 | export default names
--------------------------------------------------------------------------------
/examples/names-ts/index.ts:
--------------------------------------------------------------------------------
1 | import names from './names'
2 |
3 | export function display() {
4 | return names
5 | }
--------------------------------------------------------------------------------
/examples/ts-jsconfig-paths/libs/calculator.ts:
--------------------------------------------------------------------------------
1 | export function add(left: number, right: number) {
2 | return left + right
3 | }
--------------------------------------------------------------------------------
/examples/react-js/App.js:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 |
3 | export default function App() {
4 | return
hello world!
5 | }
--------------------------------------------------------------------------------
/examples/react-jsx/App.jsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 |
3 | export default function App() {
4 | return hello world!
5 | }
--------------------------------------------------------------------------------
/examples/react-ts/App.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react'
2 |
3 | export default function App() {
4 | return hello world!
5 | }
--------------------------------------------------------------------------------
/examples/ts-jsconfig-paths/app/index.ts:
--------------------------------------------------------------------------------
1 | import { add } from 'calculator'
2 |
3 | export default function displaySum() {
4 | return add(10, 20)
5 | }
6 |
--------------------------------------------------------------------------------
/examples/ts-jsconfig-paths/app/index.spec.ts:
--------------------------------------------------------------------------------
1 |
2 | import { expect, it } from '@jest/globals'
3 | import displaySum from './index'
4 |
5 | it('shoudl display the sum', () => {
6 | expect(displaySum()).toEqual(30)
7 | })
--------------------------------------------------------------------------------
/examples/react-js/main.js:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { StrictMode } from "react"
3 | import { render } from "react-dom"
4 |
5 | import App from "./App"
6 |
7 | render(
8 |
9 |
10 | ,
11 | document.getElementById("app")
12 | )
13 |
--------------------------------------------------------------------------------
/examples/react-jsx/main.jsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { StrictMode } from "react"
3 | import { render } from "react-dom"
4 |
5 | import App from "./App"
6 |
7 | render(
8 |
9 |
10 | ,
11 | document.getElementById("app")
12 | )
13 |
--------------------------------------------------------------------------------
/examples/react-ts/index.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react"
2 | import { StrictMode } from "react"
3 | import { render } from "react-dom"
4 |
5 | import App from "./app"
6 |
7 | render(
8 |
9 |
10 | ,
11 | document.getElementById("app")
12 | )
13 |
--------------------------------------------------------------------------------
/src/options.ts:
--------------------------------------------------------------------------------
1 | import { Loader } from 'esbuild'
2 |
3 | export interface Options {
4 | jsxFactory?: string
5 | jsxFragment?: string
6 | sourcemap?: boolean | 'inline' | 'external'
7 | loaders?: {
8 | [ext: string]: Loader
9 | },
10 | target?: string
11 | format?: string
12 | }
--------------------------------------------------------------------------------
/examples/names-ts/index.spec.ts:
--------------------------------------------------------------------------------
1 | import { expect } from "@jest/globals"
2 |
3 | import { display } from './index'
4 |
5 | jest.mock('./index', () => {
6 | return {
7 | display() {
8 | return [ 'Joe' ]
9 | }
10 | }
11 | })
12 |
13 | test('should parse with [jest.mock]', () => {
14 | expect(display()).toEqual([ 'Joe' ])
15 | })
--------------------------------------------------------------------------------
/src/utils.ts:
--------------------------------------------------------------------------------
1 | import path from 'path'
2 |
3 | export const loaders = ["js", "jsx", "ts", "tsx", "json"]
4 |
5 | export const getExt = (str: string) => {
6 | const basename = path.basename(str);
7 | const firstDot = basename.indexOf('.');
8 | const lastDot = basename.lastIndexOf('.');
9 | const extname = path.extname(basename).replace(/(\.[a-z0-9]+).*/i, '$1');
10 |
11 | if (firstDot === lastDot) return extname
12 |
13 | return basename.slice(firstDot, lastDot) + extname
14 | }
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | const hq = require('alias-hq')
2 |
3 | module.exports = {
4 | transform: {
5 | "\\.[jt]sx?$": [ 'esbuild-jest', {
6 | loaders: {
7 | '.spec.js': 'jsx',
8 | '.js': 'jsx'
9 | }
10 | }
11 | ]
12 | },
13 | /// This will resolve any tsconfig.compilerOptions.paths
14 | moduleNameMapper: hq.get('jest'),
15 | testPathIgnorePatterns: ['/node_modules/', '/dist/', '/types/' ],
16 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
17 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "target": "es2018",
5 | "module": "commonjs",
6 | "outDir": "dist",
7 | "moduleResolution": "node",
8 | "resolveJsonModule": true,
9 | "importHelpers": true,
10 | "esModuleInterop": true,
11 | "jsx": "react",
12 | "lib" :[
13 | "dom",
14 | "es2015",
15 | "es2017",
16 | "es2018",
17 | "es2019"
18 | ],
19 | "paths": {
20 | "calculator": [ "./examples/ts-jsconfig-paths/libs/calculator.ts" ]
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/tests/react-ts.spec.tsx:
--------------------------------------------------------------------------------
1 | import { afterEach, beforeEach, expect, it } from "@jest/globals"
2 | import * as React from "react";
3 | import { render } from "react-dom"
4 |
5 | import App from '../examples/react-ts/App'
6 |
7 | let element: HTMLElement
8 |
9 | beforeEach(() => {
10 | element = document.createElement("div");
11 | document.body.appendChild(element);
12 | })
13 |
14 | afterEach(() => {
15 | element.remove();
16 | });
17 |
18 | it("should render", () => {
19 | render(, element);
20 | expect(element.innerHTML).toMatchInlineSnapshot(`"hello world!
"`)
21 | });
22 |
--------------------------------------------------------------------------------
/tests/react-jsx.spec.jsx:
--------------------------------------------------------------------------------
1 | import { afterEach, beforeEach, expect, it } from "@jest/globals"
2 | import * as React from "react"
3 | import { render } from "react-dom"
4 |
5 | import App from '../examples/react-jsx/App'
6 |
7 |
8 | let element
9 |
10 | beforeEach(() => {
11 | element = document.createElement("div");
12 | document.body.appendChild(element);
13 | })
14 |
15 | afterEach(() => {
16 | element.remove();
17 | });
18 |
19 | it("should render [react-jsx]", () => {
20 | render(, element);
21 | expect(element.innerHTML).toMatchInlineSnapshot(`"hello world!
"`)
22 | })
23 |
--------------------------------------------------------------------------------
/aria.config.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs'
2 | import { symlinkDir } from 'aria-build'
3 |
4 | export default {
5 | plugins: [
6 | {
7 | name: 'copy',
8 | buildEnd: async () => {
9 | await fs.promises.mkdir('dist', { recursive: true })
10 | const pkg = require('./package.json')
11 | delete pkg.scripts
12 | delete pkg.devDependencies
13 | await Promise.all([
14 | fs.promises.writeFile('./dist/package.json', JSON.stringify(pkg, null, 2)),
15 | fs.promises.copyFile('./README.md', './dist/README.md')
16 | ])
17 | }
18 | },
19 | {
20 | name: 'link',
21 | buildEnd: () => symlinkDir('./dist', './node_modules/esbuild-jest')
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/tests/react-ts-mock.spec.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react";
2 | import { render } from "react-dom";
3 | import { afterEach, beforeEach, expect, it, jest } from "@jest/globals";
4 |
5 | import App from '../examples/react-ts/App'
6 |
7 | jest.mock("../examples/react-ts/App", () => {
8 | return function () {
9 | return boo world
;
10 | };
11 | });
12 |
13 | let element: HTMLElement
14 |
15 | beforeEach(() => {
16 | element = document.createElement("div");
17 | document.body.appendChild(element);
18 | })
19 |
20 | afterEach(() => {
21 | element.remove()
22 | })
23 |
24 | it("should render with jest.mock", () => {
25 | render(, element)
26 | expect(element.innerHTML).toMatchInlineSnapshot(`"boo world
"`);
27 | });
28 |
--------------------------------------------------------------------------------
/src/transformer.ts:
--------------------------------------------------------------------------------
1 | import { TransformOptions } from '@jest/transform'
2 | import { Config } from '@jest/types'
3 |
4 | import babelJest from 'babel-jest'
5 |
6 | const { process } = babelJest.createTransformer({
7 | plugins: [ "@babel/plugin-transform-modules-commonjs" ],
8 | parserOpts: {
9 | plugins: ["jsx", "typescript"],
10 | }
11 | })
12 |
13 | export interface BabelTransformOptions {
14 | sourceText: string
15 | sourcePath: string
16 | config: Config.ProjectConfig
17 | options?: TransformOptions
18 | }
19 |
20 | export function babelTransform(opts: BabelTransformOptions) {
21 | const { sourceText, sourcePath, config, options } = opts
22 | const babelResult = process(sourceText, sourcePath, config, options) as { code: string }
23 | return babelResult.code
24 | }
--------------------------------------------------------------------------------
/tests/react-js.spec.js:
--------------------------------------------------------------------------------
1 | import { afterEach, beforeEach, expect, it } from "@jest/globals"
2 | import * as React from "react"
3 | import { render } from "react-dom"
4 |
5 | import App from '../examples/react-js/App'
6 |
7 | /*
8 | * Should loader in jest.config.js
9 | * this will tell the esbuild that .js file has jsx syntax
10 | * transform: {
11 | * "\\.[jt]sx?$": [ 'esbuild-jest', {
12 | * loaders: {
13 | * '.js': 'jsx'
14 | * }
15 | * }
16 | * ]
17 | * }
18 | */
19 |
20 | let element
21 |
22 | beforeEach(() => {
23 | element = document.createElement("div");
24 | document.body.appendChild(element);
25 | })
26 |
27 | afterEach(() => {
28 | element.remove();
29 | });
30 |
31 | it("should render [react-js]", () => {
32 | render(, element);
33 | expect(element.innerHTML).toMatchInlineSnapshot(`"hello world!
"`)
34 | })
35 |
--------------------------------------------------------------------------------
/tools/build.ts:
--------------------------------------------------------------------------------
1 | import { TSRollupConfig, clean, bundle } from 'aria-build'
2 | import { builtinModules } from 'module'
3 |
4 | import plugins from '../aria.config'
5 |
6 | (async function() {
7 | const pkg = require('../package.json')
8 |
9 | const external = [
10 | ...builtinModules,
11 | ...Object.keys(pkg.dependencies),
12 | ...Object.keys(pkg.devDependencies)
13 | ]
14 |
15 | const config: TSRollupConfig[] = [
16 | {
17 | input: './src/index.ts',
18 | external,
19 | plugins: plugins.plugins,
20 | output: [
21 | {
22 | file: './dist/esbuild-jest.js',
23 | format: 'cjs',
24 | exports: 'auto'
25 | },
26 | {
27 | file: './dist/esbuild-jest.es.js',
28 | format: 'es',
29 | exports: 'auto'
30 | }
31 | ],
32 | tsconfig: {
33 | compilerOptions: {
34 | declaration: true
35 | }
36 | }
37 | },
38 | {
39 | input: './src/transformer.ts',
40 | external,
41 | output: [
42 | {
43 | file: './dist/transformer.js',
44 | format: 'cjs',
45 | exports: 'auto'
46 | }
47 | ]
48 | }
49 | ]
50 |
51 | await clean('dist')
52 | await bundle({ config, swc: true, write: true })
53 | })()
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # esbuild-jest
2 |
3 | ### A Jest transformer using esbuild
4 | With this transformer you can use and transform (ts, js, tsx and jsx) files
5 |
6 | [](https://www.npmjs.com/package/esbuild-jest)
7 | 
8 |
9 | ## Install
10 |
11 | ```bash
12 | npm install --save-dev esbuild-jest esbuild
13 | ```
14 |
15 | #### Setting up Jest config file
16 |
17 | esbuild-jest transformer should be used in your Jest config file like this:
18 |
19 | ```js
20 | {
21 | "transform": {
22 | "^.+\\.tsx?$": "esbuild-jest"
23 | }
24 | }
25 | ```
26 |
27 | #### Setting up Jest config file with transformOptions
28 | ```typescript
29 | export interface Options {
30 | jsxFactory?: string
31 | jsxFragment?: string
32 | sourcemap?: boolean | 'inline' | 'external'
33 | loaders?: {
34 | [ext: string]: Loader
35 | },
36 | target?: string
37 | format?: string
38 | }
39 | ```
40 |
41 | ```js
42 | {
43 | "transform": {
44 | "^.+\\.tsx?$": [
45 | "esbuild-jest",
46 | {
47 | sourcemap: true,
48 | loaders: {
49 | '.spec.ts': 'tsx'
50 | }
51 | }
52 | ]
53 | }
54 | }
55 | ```
56 |
57 | > Note: if you are using tsconfig.json and jsconfig.json with "paths", Please look `alias-hq` and there documentation https://github.com/davestewart/alias-hq/blob/master/docs/integrations.md
58 |
59 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: esbuild-jest
2 |
3 | on: [push]
4 |
5 | jobs:
6 | ubuntu-latest:
7 | runs-on: ubuntu-latest
8 |
9 | strategy:
10 | matrix:
11 | node-version: [12.x, 14.x, 15.x]
12 |
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: Use Node.js ${{ matrix.node-version }}
16 | uses: actions/setup-node@v1
17 | with:
18 | node-version: ${{ matrix.node-version }}
19 | - run: yarn
20 | - run: yarn build
21 | - run: yarn test
22 | env:
23 | CI: true
24 | windows-latest:
25 | runs-on: windows-latest
26 |
27 | strategy:
28 | matrix:
29 | node-version: [12.x, 14.x, 15.x]
30 |
31 | steps:
32 | - uses: actions/checkout@v2
33 | - name: Use Node.js ${{ matrix.node-version }}
34 | uses: actions/setup-node@v1
35 | with:
36 | node-version: ${{ matrix.node-version }}
37 | - run: yarn
38 | - run: yarn build
39 | - run: yarn test
40 | env:
41 | CI: true
42 | macos-latest:
43 | runs-on: macos-latest
44 |
45 | strategy:
46 | matrix:
47 | node-version: [12.x, 14.x, 15.x]
48 |
49 | steps:
50 | - uses: actions/checkout@v2
51 | - name: Use Node.js ${{ matrix.node-version }}
52 | uses: actions/setup-node@v1
53 | with:
54 | node-version: ${{ matrix.node-version }}
55 | - run: yarn
56 | - run: yarn build
57 | - run: yarn test
58 | env:
59 | CI: true
60 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "esbuild-jest",
3 | "version": "0.5.0",
4 | "description": "Jest plugin to use esbuild for transformation",
5 | "main": "esbuild-jest.js",
6 | "module": "esbuild-jest.es.js",
7 | "typings": "esbuild-jest.d.ts",
8 | "scripts": {
9 | "postinstall": "yarn build",
10 | "build": "ts-node ./tools/build.ts",
11 | "test": "jest --clearCache && jest --detectOpenHandles"
12 | },
13 | "repository": {
14 | "type": "git",
15 | "url": "git+https://github.com/aelbore/esbuild-jest.git"
16 | },
17 | "keywords": [
18 | "esbuild",
19 | "jest",
20 | "test"
21 | ],
22 | "author": "Arjay Elbore ",
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/aelbore/esbuild-jest/issues"
26 | },
27 | "homepage": "https://github.com/aelbore/esbuild-jest#readme",
28 | "peerDependencies": {
29 | "esbuild": ">=0.9.3"
30 | },
31 | "devDependencies": {
32 | "@babel/preset-typescript": "^7.13.0",
33 | "@swc/core": "^1.2.50",
34 | "@types/jest": "^26.0.21",
35 | "@types/mock-fs": "^4.13.0",
36 | "@types/node": "^14.14.35",
37 | "@types/react": "^17.0.3",
38 | "@types/react-dom": "^17.0.2",
39 | "alias-hq": "^5.1.6",
40 | "aria-build": "^0.7.3",
41 | "aria-fs": "^0.7.3",
42 | "esbuild": "^0.8.49",
43 | "jest": "^26.6.3",
44 | "jest-config": "^26.6.3",
45 | "prettier": "^2.2.1",
46 | "react": "^17.0.1",
47 | "react-dom": "^17.0.1",
48 | "tslib": "^2.1.0",
49 | "typescript": "^4.2.3"
50 | },
51 | "dependencies": {
52 | "@babel/core": "^7.13.10",
53 | "@babel/plugin-transform-modules-commonjs": "^7.13.8",
54 | "babel-jest": "^26.6.3"
55 | },
56 | "babel": {
57 | "presets": [
58 | "@babel/preset-typescript"
59 | ]
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import { extname } from 'path'
2 |
3 | import { Config } from '@jest/types'
4 | import { TransformOptions as JestTransformOptions, Transformer } from '@jest/transform'
5 | import { Format, Loader, TransformOptions, transformSync } from 'esbuild'
6 |
7 | import { Options } from './options'
8 | import { getExt, loaders } from './utils'
9 |
10 | const createTransformer = (options?: Options) => ({
11 | process(content: string,
12 | filename: string,
13 | config: Config.ProjectConfig,
14 | opts?: JestTransformOptions
15 | ) {
16 | const sources = { code: content }
17 | const ext = getExt(filename), extName = extname(filename).slice(1)
18 |
19 | const enableSourcemaps = options?.sourcemap || false
20 | const loader = (options?.loaders && options?.loaders[ext]
21 | ? options.loaders[ext]
22 | : loaders.includes(extName) ? extName: 'text'
23 | ) as Loader
24 | const sourcemaps: Partial = enableSourcemaps
25 | ? { sourcemap: true, sourcesContent: false, sourcefile: filename }
26 | : {}
27 |
28 | /// this logic or code from
29 | /// https://github.com/threepointone/esjest-transform/blob/main/src/index.js
30 | /// this will support the jest.mock
31 | /// https://github.com/aelbore/esbuild-jest/issues/12
32 | /// TODO: transform the jest.mock to a function using babel traverse/parse then hoist it
33 | if (sources.code.indexOf("ock(") >= 0 || opts?.instrument) {
34 | const source = require('./transformer').babelTransform({
35 | sourceText: content,
36 | sourcePath: filename,
37 | config,
38 | options: opts
39 | })
40 | sources.code = source
41 | }
42 |
43 | const result = transformSync(sources.code, {
44 | loader,
45 | format: options?.format as Format || 'cjs',
46 | target: options?.target || 'es2018',
47 | ...(options?.jsxFactory ? { jsxFactory: options.jsxFactory }: {}),
48 | ...(options?.jsxFragment ? { jsxFragment: options.jsxFragment }: {}),
49 | ...sourcemaps
50 | })
51 |
52 | let { map, code } = result;
53 | if (enableSourcemaps) {
54 | map = {
55 | ...JSON.parse(result.map),
56 | sourcesContent: null,
57 | }
58 |
59 | // Append the inline sourcemap manually to ensure the "sourcesContent"
60 | // is null. Otherwise, breakpoints won't pause within the actual source.
61 | code = code + '\n//# sourceMappingURL=data:application/json;base64,' + Buffer.from(JSON.stringify(map)).toString('base64')
62 | } else {
63 | map = null
64 | }
65 |
66 | return { code, map }
67 | }
68 | })
69 |
70 | const transformer: Pick = {
71 | canInstrument: true,
72 | createTransformer
73 | }
74 |
75 | export * from './options'
76 |
77 | export default transformer
--------------------------------------------------------------------------------
/tests/index.spec.ts:
--------------------------------------------------------------------------------
1 | import fs from 'fs'
2 | import path from 'path'
3 |
4 | import { expect } from '@jest/globals'
5 | import { defaults } from 'jest-config'
6 |
7 | import { display } from '../examples/names-ts/index'
8 |
9 | /// using @babel/preset-typescript
10 | /// i was able to us directly the typescript code without bundle the code
11 | import transformer, { Options } from '../src/index'
12 |
13 | const process = (sourcePath: string, options?: Options) => {
14 | const content = fs.readFileSync(sourcePath, 'utf-8')
15 |
16 | const Transformer = transformer.createTransformer({
17 | format: 'esm',
18 | sourcemap: true,
19 | ...(options || {})
20 | })
21 |
22 | const config = { ...defaults, cwd: path.resolve() } as any
23 | const output = Transformer.process(content, sourcePath, config) as { code: string, map: string }
24 |
25 | return { ...output }
26 | }
27 |
28 | test('ts file', () => {
29 | const names = display()
30 | expect(names.includes('Jane')).toBeTruthy()
31 | })
32 |
33 | test('should have sourcemap with [jest.mock]', () => {
34 | const output = process('./examples/names-ts/index.spec.ts')
35 |
36 | expect(output.code).toMatchInlineSnapshot(`
37 | "\\"use strict\\";
38 | _getJestObj().mock(\\"./index\\", () => {
39 | return {
40 | display() {
41 | return [\\"Joe\\"];
42 | }
43 | };
44 | });
45 | var _globals = require(\\"@jest/globals\\");
46 | var _index = require(\\"./index\\");
47 | function _getJestObj() {
48 | const {
49 | jest
50 | } = require(\\"@jest/globals\\");
51 | _getJestObj = () => jest;
52 | return jest;
53 | }
54 | test(\\"should parse with [jest.mock]\\", () => {
55 | (0, _globals.expect)((0, _index.display)()).toEqual([\\"Joe\\"]);
56 | });
57 |
58 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnNwZWMudHMiXSwibWFwcGluZ3MiOiI7QUFJQSxjQUFLLEtBQUssV0FBVztBQUNuQixTQUFPO0lBQ0w7QUFDRSxhQUFPLENBQUU7Ozs7QUFQZixJQUFBLFdBQUEsUUFBQTtBQUVBLElBQUEsU0FBQSxRQUFBOzs7Ozs7OztBQVVBLEtBQUssaUNBQWlDO0FBQ3BDLEVBQUEsSUFBQSxTQUFBLFFBQU8sSUFBQSxPQUFBLFlBQVcsUUFBUSxDQUFFOzsiLCJuYW1lcyI6W10sInNvdXJjZXNDb250ZW50IjpudWxsfQ=="
59 | `)
60 |
61 | expect(output.map).toEqual( {
62 | version: 3,
63 | sources: [ 'index.spec.ts' ],
64 | mappings: ';AAIA,cAAK,KAAK,WAAW;AACnB,SAAO;IACL;AACE,aAAO,CAAE;;;;AAPf,IAAA,WAAA,QAAA;AAEA,IAAA,SAAA,QAAA;;;;;;;;AAUA,KAAK,iCAAiC;AACpC,EAAA,IAAA,SAAA,QAAO,IAAA,OAAA,YAAW,QAAQ,CAAE;;',
65 | names: [],
66 | sourcesContent: null
67 | })
68 | })
69 |
70 | test('should have sourcemap without [jest.mock]', () => {
71 | const output = process('./examples/names-ts/index.ts')
72 |
73 | expect(output.code).toMatchInlineSnapshot(`
74 | "import names from \\"./names\\";
75 | function display() {
76 | return names;
77 | }
78 | export {
79 | display
80 | };
81 |
82 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4vZXhhbXBsZXMvbmFtZXMtdHMvaW5kZXgudHMiXSwibWFwcGluZ3MiOiJBQUFBO0FBRU87QUFDTCxTQUFPO0FBQUE7IiwibmFtZXMiOltdLCJzb3VyY2VzQ29udGVudCI6bnVsbH0="
83 | `)
84 |
85 | expect(output.map).toEqual({
86 | version: 3,
87 | sources: [ './examples/names-ts/index.ts' ],
88 | mappings: 'AAAA;AAEO;AACL,SAAO;AAAA;',
89 | names: [],
90 | sourcesContent: null
91 | })
92 | })
93 |
94 | test('should not have sourcemap [default]', () => {
95 | const output = process('./examples/names-ts/index.ts', { sourcemap: false })
96 | expect(output.map).toBeNull()
97 | })
--------------------------------------------------------------------------------