-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is breakpoints are not working or I'm the only one? #24
Comments
@RIP21 it works on vscode i havent tried in webstorm, heres a repository |
I can't get it to work on IntelliJ (which is the same thing as webstorm). I suspect sourcemaps since the tests run just viel. I thought it used to work. |
what version you are using? if you are not using jest.mock just use esbuild-jest@0.4.0 i only tried vscode for break point and it works fine for me vscode break point here |
After some experimenting, removing this line seems to partially fix debugging in IntelliJ (and should for Webstorm). Some of the mappings are wrong but it at least works inside test files.
I'm using a modified version of this package. Here's the full code I have working: const esbuild = require('esbuild');
const path = require('path');
/**
* Jest ESBuild is a jest transformer that uses esbuild to compile .ts and .tsx
* into Node.js compatible JavaScript.
*
* Originally copied from the MIT licensed
* https://github.com/aelbore/esbuild-jest/
* @param {string} sourceText
* @param {string} sourcePath
* @param {import('@jest/types').Config} _config
* @param {import('@jest/transform/build/types').TransformOptions} _options
* @return {import('@jest/transform/build/types').TransformedSource}
*/
const process = (sourceText, sourcePath, _config, _options) => {
const loader = path.extname(sourcePath).slice(1);
if (loader !== 'ts' && loader !== 'tsx' && loader !== 'js' && loader !== 'jsx') {
throw new Error(`Unsupported extension type '${loader}' for esbuild Jest transformer on file: ${sourcePath}`);
}
const esbuildOpts = {
format: 'cjs',
target: 'esnext',
loader: loader,
sourcemap: true,
sourcesContent: false,
sourcefile: sourcePath
};
const result = esbuild.transformSync(sourceText, esbuildOpts);
if (result.map) {
// Add inline source maps so debugging works.
result.code += '\n//# sourceMappingURL=data:application/json;base64,';
result.code += Buffer.from(result.map).toString('base64');
}
return result
};
module.exports = {process}; |
whats your jest config? did you set the sourcemap to true? setting the sourcesContent: null before works fine but let me verify that one |
Breakpoints work and mappings seem to have fixed themselves. That might have been changing
Good thought, included below. I'm using a modified version of this package so the sourcemap config option is included in my Esbuild version: jest-transform.js const esbuild = require('esbuild');
const path = require('path');
/**
* Jest ESBuild is a jest transformer that uses esbuild to compile .ts and .tsx
* into Node.js compatible JavaScript.
*
* This file is JavaScript using commonjs modules (require instead of import)
* because it's the compiler for TypeScript files when running with jest. We
* want this file to run directly under Node to avoid bootstrapping.
*
* Originally copied from the MIT licensed
* https://github.com/aelbore/esbuild-jest/
* @param {string} sourceText
* @param {string} sourcePath
* @param {import('@jest/types').Config} _config
* @param {import('@jest/transform/build/types').TransformOptions} _options
* @return {import('@jest/transform/build/types').TransformedSource}
*/
const process = (sourceText, sourcePath, _config, _options) => {
const loader = path.extname(sourcePath).slice(1);
if (loader !== 'ts' && loader !== 'tsx' && loader !== 'js' && loader !== 'jsx') {
throw new Error(`Unsupported extension type '${loader}' for esbuild Jest transformer on file: ${sourcePath}`);
}
const esbuildOpts = {
format: 'cjs',
target: 'esnext',
loader: loader,
sourcemap: 'both',
sourcesContent: true,
sourcefile: sourcePath
};
return esbuild.transformSync(sourceText, esbuildOpts)
};
module.exports = {process}; jest.config.js /** @type import('@jest/types/build/Config').InitialOptions */
module.exports = {
displayName: 'myapp',
errorOnDeprecated: true,
transform: {
'[.][jt]sx?$': "./testing/jest-transform-js.js",
'[.]css$': "./testing/jest-transform-css.js",
'[.]svg$': "./testing/jest-transform-svg.js",
},
setupFiles: ["./testing/jest-setup-polyfills.js"],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
rootDir: 'src',
testRegex: '_test[.]tsx?$',
// Place snapshots next to test files, like app_test.tsx.snap.
snapshotResolver: './testing/jest-snapshot-resolver.js',
}; |
@aelbore passing "both" to |
A small change that makes sure that the source map option is actually getting passed to esbuild transform as it's described in jest transform options. Although unsure 100% about the change as you have folks here `options` and `opts` in the same time and I'm not sure if it's a bug or not. And where is what. Related aelbore#24
Created a PR (from the Github UI don't blame me :D) |
I manually changed to |
I can confirm that with the setup above of @jschaf it all works until there is a |
Sorry for the spam... but here is the workaround for fellow WebStorm/IntelliJ users here.
index.js (you may name it jest.config.js) but in my case it's a module that I'm sharing through the repo.
And breakpoints are working... I still think there are some bugs of some sort in the code due to this |
It stopped work again tho... Surcrase is mega quick and is similar to Babel and works no problem with Jest via this plugin. It will require you to hoist |
Hey @RIP21 any chance to share your config for Sucrase? I was trying to configure it with no luck 😞 |
@PatrykMilewski sure mate! :) module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': require.resolve('@sucrase/jest-plugin'),
},
modulePaths: ['src'],
reporters: [require.resolve('jest-standard-reporter')],
coverageReporters: ['text-summary'],
collectCoverageFrom: ['src/**/*.{js,jsx,mjs,ts,tsx}'],
} It has {
"name": "@liveflow-io/config-jest",
"version": "0.0.1",
"description": "Jest config base",
"license": "MIT",
"main": "./index.js",
"dependencies": {
"@sucrase/jest-plugin": "~2.0.0",
"jest-standard-reporter": "~2.0.0"
},
"scripts": {
"build": ""
}
} |
@RIP21 Thanks! It works great! Not sure what was wrong with my config lol |
@PatrykMilewski proszę bardzo :P Miłego wieczoru :) |
The issue seems to be that the altered Lines 53 to 57 in daa5847
Should be: if (enableSourcemaps) {
map = {
...JSON.parse(result.map),
sourcesContent: undefined,
} Also using const sourcemaps = enableSourcemaps ? {
sourcemap: 'both',
sourcesContent: false,
sourcefile: filename
} : {
}; Also, when changing any of this, the Jest cache in your temp directory needs deleted between runs. |
@aelbore is there any chance to fix that? I would like to eventually use the same transpiler for both normal code and tests, as it's more consistent and safer. Right now I'm using Sucrase Jest plugin, as it's the only thing that I managed to configure to work with breakpoints. |
@ngbrown, unfortunately, these changes don't make breakpoints work for me (Webstorm). Are there any other changes needed? |
@ngbrown If you don't need decorators support, use @sucrase/jest-plugin jest plugin instead. It works great with Webstorm. |
@PatrykMilewski I am working with ESM only currently and with
|
@dan-lee I'm also using ESM, check out my minimal example here: https://github.com/PatrykMilewski/sucrase-test just bump the version of Sucrase plugin to the latest in package.json and it should work fine. |
Thanks all for the suggestions to use @sucrase/jest-plugin instead, that fixed webstorm breakpoints in my tests! |
Hey, I try to set a breakpoint in the test but it never stops.
I run in-band etc. I'm using WebStorm functionality for that. Is it working with VSCode maybe? Anyone can confirm? What command are you using to achieve that?
I'm running the latest esbuild and esbuild-jest
The text was updated successfully, but these errors were encountered: