Closed ramaghanta closed 8 months ago
Just to add, npm test works fine in the console with "jest --coverage=false"
We tried setting up a sample project based on your diagnostics report and it's working for us. Can you please see if our sample works for you by cloning it, installing dependencies with npm install
and then starting Wallaby?
We're using the same version of node, so there's no reason it shouldn't work.
If it works, can you please compare our sample project to your project? It may identify why Wallaby is not working for you.
If that doesn't help, can you please either update our repo with your configuration, or else provide a sample repo that has your problem (i.e. works from the jest CLI but not with Wallaby)?
Adding extensionsToTreatAsEsm: [ '.ts' ],
to the jest.config.js seems to trigger the problem on the sample project (https://github.com/wallabyjs/wallaby-3333) .
I'm not getting that problem. My jest.config.js
now looks like this:
export default {
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{ isolatedModules: true, diagnostics: false, useESM: true },
],
},
extensionsToTreatAsEsm: ['.ts'],
};
Am I missing something in the configuration? Could you also please share your Wallaby Diagnostics report? I'd like to confirm that we're using the same version of node.js
.
Yup your jest.config.js
matches mine with that 3333 project.
Here is my debug - using node 20.11.1 - however the same thing happens with 21.6.1 and I assume other versions.
{
editorVersion: 'WebStorm 2023.3.3',
pluginVersion: '1.0.284',
editorType: 'IntelliJ',
osVersion: 'darwin 23.3.0',
nodeVersion: 'v20.11.1',
coreVersion: '1.0.1525',
checksum: 'ZDE0YzdkNzk2YTM3MzM3MWU2YzI3OTA3OWFmZDkyZjYsMTczMTcxNTIwMDAwMCww',
config: {
diagnostics: {
jest: {
config: {
configs: [
{
automock: false,
cache: true,
cacheDirectory: '/private/var/folders/w7/q_97lqz56r55v79plhdf7zx80000gn/T/jest_dx',
clearMocks: false,
collectCoverageFrom: [],
coverageDirectory: '<homeDir>/git/wallaby-3333/coverage',
coveragePathIgnorePatterns: [ '/node_modules/' ],
cwd: '<homeDir>/git/wallaby-3333',
dependencyExtractor: undefined,
detectLeaks: false,
detectOpenHandles: false,
displayName: undefined,
errorOnDeprecated: false,
extensionsToTreatAsEsm: [ '.ts' ],
fakeTimers: { enableGlobally: false },
filter: undefined,
forceCoverageMatch: [],
globalSetup: undefined,
globalTeardown: undefined,
globals: {},
haste: { computeSha1: false, enableSymlinks: false, forceNodeFilesystemAPI: true, throwOnModuleCollision: false },
id: '6eb0bb5bc4e8d189d6d5492e7c6505ff',
injectGlobals: true,
moduleDirectories: [ 'node_modules' ],
moduleFileExtensions: [
'js', 'mjs',
'cjs', 'jsx',
'ts', 'tsx',
'json', 'node'
],
moduleNameMapper: [],
modulePathIgnorePatterns: [],
modulePaths: undefined,
openHandlesTimeout: 1000,
prettierPath: 'prettier',
resetMocks: false,
resetModules: false,
resolver: undefined,
restoreMocks: false,
rootDir: '<homeDir>/git/wallaby-3333',
roots: [ '<homeDir>/git/wallaby-3333' ],
runner: '<homeDir>/git/wallaby-3333/node_modules/jest-runner/build/index.js',
runtime: undefined,
sandboxInjectedGlobals: [],
setupFiles: [],
setupFilesAfterEnv: [],
skipFilter: false,
skipNodeResolution: undefined,
slowTestThreshold: 5,
snapshotFormat: { escapeString: false, printBasicPrototype: false },
snapshotResolver: undefined,
snapshotSerializers: [],
testEnvironment: '<homeDir>/git/wallaby-3333/node_modules/jest-environment-node/build/index.js',
testEnvironmentOptions: {},
testLocationInResults: false,
testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ],
testPathIgnorePatterns: [ '/node_modules/' ],
testRegex: [],
testRunner: '<homeDir>/git/wallaby-3333/node_modules/jest-circus/runner.js',
transform: [ [ '^.+\\.tsx?$', '<homeDir>/git/wallaby-3333/node_modules/ts-jest/dist/index.js', { isolatedModules: true, diagnostics: false, useESM: true } ] ],
transformIgnorePatterns: [ '/node_modules/', '\\.pnp\\.[^\\/]+$' ],
unmockedModulePathPatterns: undefined,
watchPathIgnorePatterns: []
}
],
globalConfig: {
bail: 0,
changedFilesWithAncestor: false,
changedSince: undefined,
ci: false,
collectCoverage: false,
collectCoverageFrom: [],
coverageDirectory: '<homeDir>/git/wallaby-3333/coverage',
coverageProvider: 'babel',
coverageReporters: [ 'json', 'text', 'lcov', 'clover' ],
coverageThreshold: undefined,
detectLeaks: false,
detectOpenHandles: false,
errorOnDeprecated: false,
expand: false,
filter: undefined,
findRelatedTests: false,
forceExit: false,
globalSetup: undefined,
globalTeardown: undefined,
json: false,
lastCommit: false,
listTests: false,
logHeapUsage: false,
maxConcurrency: 5,
maxWorkers: 9,
noSCM: undefined,
noStackTrace: false,
nonFlagArgs: undefined,
notify: false,
notifyMode: 'failure-change',
onlyChanged: false,
onlyFailures: false,
openHandlesTimeout: 1000,
outputFile: undefined,
passWithNoTests: false,
projects: [],
randomize: undefined,
replname: undefined,
reporters: undefined,
rootDir: '<homeDir>/git/wallaby-3333',
runInBand: undefined,
runTestsByPath: false,
seed: 798721966,
shard: undefined,
showSeed: undefined,
silent: undefined,
skipFilter: false,
snapshotFormat: { escapeString: false, printBasicPrototype: false },
testFailureExitCode: 1,
testNamePattern: undefined,
testPathPattern: '',
testResultsProcessor: undefined,
testSequencer: '<homeDir>/git/wallaby-3333/node_modules/@jest/test-sequencer/build/index.js',
testTimeout: undefined,
updateSnapshot: 'new',
useStderr: false,
verbose: undefined,
watch: false,
watchAll: false,
watchPlugins: undefined,
watchman: true,
workerIdleMemoryLimit: undefined,
workerThreads: false
},
hasDeprecationWarnings: false,
wallaby: {
roots: [],
watchPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', '/private/var/folders/w7/q_97lqz56r55v79plhdf7zx80000gn/T/jest_dx', '\\./coverage' ],
testPathIgnorePatterns: [ '/node_modules/', '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/', '/private/var/folders/w7/q_97lqz56r55v79plhdf7zx80000gn/T/jest_dx', '\\./coverage' ],
testMatch: [ '**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)' ],
testRegex: []
}
}
}
},
testFramework: { version: 'jest@24.8.0', configurator: 'jest@24.8.0', reporter: 'jest@24.8.0', starter: 'jest@24.8.0', autoDetected: true },
filesWithCoverageCalculated: [],
filesWithNoCoverageCalculated: [],
globalSetup: false,
dot: true,
files: [
{ pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true, file: true, test: true },
{
pattern: '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/',
regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//,
ignore: true,
trigger: true,
load: true,
file: true,
test: true
},
{
pattern: '/private/var/folders/w7/q_97lqz56r55v79plhdf7zx80000gn/T/jest_dx',
regexp: /\/private\/var\/folders\/w7\/q_97lqz56r55v79plhdf7zx80000gn\/T\/jest_dx/,
ignore: true,
trigger: true,
load: true,
file: true,
test: true
},
{ pattern: '\\./coverage', regexp: /\.\/coverage/, ignore: true, trigger: true, load: true, file: true, test: true },
{ pattern: '**/**', ignore: false, trigger: true, load: true, order: 1 },
{ pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: true, trigger: true, load: true, file: true },
{ pattern: '**/?(*.)+(spec|test).[tj]s?(x)', ignore: true, trigger: true, load: true, file: true }
],
captureConsoleLog: true,
tests: [
{ pattern: '/node_modules/', regexp: /\/node_modules\//, ignore: true, trigger: true, load: true, test: true, file: false },
{
pattern: '\\./dist/|\\./build/|\\./coverage/|\\./git/|/\\..+/',
regexp: /\.\/dist\/|\.\/build\/|\.\/coverage\/|\.\/git\/|\/\..+\//,
ignore: true,
trigger: true,
load: true,
test: true,
file: false
},
{
pattern: '/private/var/folders/w7/q_97lqz56r55v79plhdf7zx80000gn/T/jest_dx',
regexp: /\/private\/var\/folders\/w7\/q_97lqz56r55v79plhdf7zx80000gn\/T\/jest_dx/,
ignore: true,
trigger: true,
load: true,
test: true,
file: false
},
{ pattern: '\\./coverage', regexp: /\.\/coverage/, ignore: true, trigger: true, load: true, test: true, file: false },
{ pattern: '**/__tests__/**/*.[jt]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 2 },
{ pattern: '**/?(*.)+(spec|test).[tj]s?(x)', ignore: false, trigger: true, load: true, test: true, order: 3 }
],
runAllTestsInAffectedTestFile: false,
updateNoMoreThanOneSnapshotPerTestFileRun: false,
compilers: {},
logLimits: { inline: { depth: 5, elements: 5000 }, values: { default: { stringLength: 200 }, autoExpand: { elements: 5000, stringLength: 8192, depth: 10 } } },
preprocessors: {},
maxConsoleMessagesPerTest: 100,
autoConsoleLog: true,
delays: { run: 0, edit: 100, update: 0 },
workers: { initial: 0, regular: 0, recycle: false },
teardown: undefined,
hints: {
ignoreCoverage: '__REGEXP /ignore coverage|istanbul ignore|c8 ignore/',
ignoreCoverageForFile: '__REGEXP /ignore file coverage/',
commentAutoLog: '?',
testFileSelection: { include: '__REGEXP /file\\.only/', exclude: '__REGEXP /file\\.skip/' }
},
automaticTestFileSelection: true,
runSelectedTestsOnly: false,
mapConsoleMessagesStackTrace: false,
extensions: {},
env: { type: 'node', params: {}, runner: '<homeDir>/.nvm/versions/node/v20.11.1/bin/node', viewportSize: { width: 800, height: 600 }, options: { width: 800, height: 600 }, bundle: true },
reportUnhandledPromises: true,
slowTestThreshold: 75,
lowCoverageThreshold: 80,
runAllTestsWhenNoAffectedTests: false,
configCode: 'auto.detect#-278026206'
},
packageJSON: {
dependencies: {
'@checkdigit/hash': '^2.0.2',
'@checkdigit/time': '^2.0.0',
'@checkdigit/typescript-config': '^6.0.0',
'@jest/globals': '^29.7.0',
'aws-sdk': '^2.1559.0',
moment: '^2.30.1',
rimraf: '^5.0.5',
'ts-node': '^10.9.2'
},
devDependencies: { '@checkdigit/jest-config': '^6.0.0', '@types/jest': '^29.5.12', jest: '^29.7.0', 'ts-jest': '^29.1.2', typescript: '^5.3.3' }
},
fs: { numberOfFiles: 7 },
debug: [
'2024-02-16T02:05:42.358Z project waiting for initial run signal\n',
'2024-02-16T02:05:42.363Z config Attempting automatic configuration for angular\n',
'2024-02-16T02:05:42.363Z angular/cli config Angular CLI not found.\n',
'2024-02-16T02:05:42.363Z config Finished attempting automatic configuration for angular (0ms)\n',
'2024-02-16T02:05:42.363Z config Attempting automatic configuration for jest\n',
'2024-02-16T02:05:42.397Z jest/config Detected Jest.\n',
'2024-02-16T02:05:42.397Z jest/config Configured Jest.\n',
'2024-02-16T02:05:42.397Z config Finished attempting automatic configuration for jest (34ms)\n',
'2024-02-16T02:05:42.398Z project Wallaby Node version: v20.11.1\n',
'2024-02-16T02:05:42.398Z project Wallaby config: <homeDir>/git/wallaby-3333/auto.detect\n',
'2024-02-16T02:05:42.421Z fs File system starting\n',
'2024-02-16T02:05:42.436Z fs File system scan completed\n',
'2024-02-16T02:05:42.439Z project File cache: <homeDir>/Library/Caches/JetBrains/WebStorm2023.3/wallaby/projects/4f1ceabcaa04e990\n',
'2024-02-16T02:05:42.442Z uiService Listening port 51236\n',
'2024-02-16T02:05:42.443Z project package.json file change detected, invalidating local cache\n',
'2024-02-16T02:05:42.446Z workers Parallelism for initial run: 8, for regular run: 4\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #0\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #1\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #2\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #3\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #4\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #5\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #6\n',
'2024-02-16T02:05:42.446Z workers Starting run worker instance #7\n',
'2024-02-16T02:05:42.447Z workers Web server is listening at 55083\n',
'2024-02-16T02:05:42.447Z project File cache requires some updates, waiting required files from IDE\n',
'2024-02-16T02:05:42.464Z project Stopping process pool\n',
'2024-02-16T02:05:42.467Z project Test run started; run priority: 3\n',
'2024-02-16T02:05:42.468Z project Running all tests\n',
'2024-02-16T02:05:42.468Z workers Starting test run, priority: 3\n',
'2024-02-16T02:05:42.468Z nodeRunner Starting sandbox [worker #0, session #3bmyr]\n',
'2024-02-16T02:05:42.468Z nodeRunner Preparing sandbox [worker #0, session #3bmyr]\n',
'2024-02-16T02:05:42.543Z workers Started run worker instance (delayed) #0\n',
'2024-02-16T02:05:42.543Z nodeRunner Prepared sandbox [worker #0, session #3bmyr]\n',
'2024-02-16T02:05:42.543Z workers [worker #0, session #3bmyr] Running tests in sandbox\n',
'2024-02-16T02:05:42.544Z workers Started run worker instance (delayed) #2\n',
'2024-02-16T02:05:42.545Z workers Started run worker instance (delayed) #1\n',
'2024-02-16T02:05:42.546Z workers Started run worker instance (delayed) #4\n',
'2024-02-16T02:05:42.549Z workers Started run worker instance (delayed) #6\n',
'2024-02-16T02:05:42.550Z workers Started run worker instance (delayed) #3\n',
'2024-02-16T02:05:42.552Z workers Started run worker instance (delayed) #7\n',
'2024-02-16T02:05:42.557Z workers Started run worker instance (delayed) #5\n',
"2024-02-16T02:05:42.676Z workers 'Scheduling Jest Test Run (3bmyr): 2024-02-16T02:05:42.673Z'\n",
'2024-02-16T02:05:42.959Z workers Sandbox (active) [3bmyr] error: Failed to instrument src/a.sample.spec.ts\n' +
" 1 | import { describe, it } from '@jest/globals';\n" +
"> 2 | import schema from './schema.json' with { type: 'json' };\n" +
' | ^ SyntaxError: Unexpected token (2:35)\n' +
" 3 | describe('test', () => {\n" +
" 4 | it('test', () => {\n" +
' 5 | console.log(schema);\n' +
' at ScriptTransformer.transformSourceAsync (./node_modules/@jest/transform/build/ScriptTransformer.js:599:19)\n' +
' at ScriptTransformer._transformAndBuildScriptAsync (./node_modules/@jest/transform/build/ScriptTransformer.js:639:35)\n' +
' at ScriptTransformer.transformAsync (./node_modules/@jest/transform/build/ScriptTransformer.js:703:14)\n' +
' at Runtime.transformFileAsync (./node_modules/jest-runtime/build/index.js:1484:29)\n' +
' at Runtime.loadEsmModule (./node_modules/jest-runtime/build/index.js:493:31)\n' +
' at Runtime.unstable_importModule (./node_modules/jest-runtime/build/index.js:721:20)\n' +
' at jestAdapter (./node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:75:5)\n' +
' at runTestInternal (./node_modules/jest-runner/build/runTest.js:367:16)\n' +
' at runTest (./node_modules/jest-runner/build/runTest.js:444:34)\n',
'2024-02-16T02:05:42.959Z workers [3bmyr] Run 0 test(s), skipped 0 test(s)\n',
"2024-02-16T02:05:42.960Z workers 'Jest Test Run Complete (3bmyr): 2024-02-16T02:05:42.960Z'\n",
'2024-02-16T02:05:42.960Z workers [3bmyr] Sandbox is responsive, closing it\n',
'2024-02-16T02:05:42.961Z workers Failed to map the stack to user code, entry message: Failed to instrument src/a.sample.spec.ts\n' +
" 1 | import { describe, it } from '@jest/globals';\n" +
"> 2 | import schema from './schema.json' with { type: 'json' };\n" +
' | ^ SyntaxError: Unexpected token (2:35)\n' +
" 3 | describe('test', () => {\n" +
" 4 | it('test', () => {\n" +
' 5 | console.log(schema);, stack: Error: Failed to instrument src/a.sample.spec.ts\n' +
" 1 | import { describe, it } from '@jest/globals';\n" +
"> 2 | import schema from './schema.json' with { type: 'json' };\n" +
' | ^ SyntaxError: Unexpected token (2:35)\n' +
" 3 | describe('test', () => {\n" +
" 4 | it('test', () => {\n" +
' 5 | console.log(schema);\n' +
' at Object.formatInstrumentationError (<homeDir>/Library/Caches/JetBrains/WebStorm2023.3/wallaby/wallaby/server.js:507:99682)\n' +
' at i (<homeDir>/Library/Caches/JetBrains/WebStorm2023.3/wallaby/wallaby/runners/node/jest@24.8.0/initializer.js:36:15236)\n' +
' at l.processAsync (<homeDir>/Library/Caches/JetBrains/WebStorm2023.3/wallaby/wallaby/runners/node/jest@24.8.0/initializer.js:36:17385)\n' +
' at ScriptTransformer.transformSourceAsync (<homeDir>/git/wallaby-3333/node_modules/@jest/transform/build/ScriptTransformer.js:599:19)\n' +
' at ScriptTransformer._transformAndBuildScriptAsync (<homeDir>/git/wallaby-3333/node_modules/@jest/transform/build/ScriptTra\n',
'2024-02-16T02:05:42.961Z project Test run finished\n',
'2024-02-16T02:05:42.961Z project Processed console.log entries\n',
'2024-02-16T02:05:42.961Z project Processed loading sequences\n',
'2024-02-16T02:05:42.961Z project Processed executed tests\n',
'2024-02-16T02:05:42.961Z project Processed code coverage\n',
'2024-02-16T02:05:42.964Z project Test run result processed and sent to IDE\n'
]
}
We're a little unsure of why we can't reproduce your exact problem but have isolated the cause in a project that uses vanilla JavaScript.
Wallaby currently does not support the use of import attributes. We will look at adding support soon.
I'm not sure if this is relevant. But I can only seem to produce the issue using jetbrains webstorm, when I use wallabyjs with vscode I don't get any errors and the tests pass.
@adcreare We have tried reproducing in WebStorm 2023.3.3, but still unable to. Having said that, we have now added native support of of import attributes use in Wallaby core. Please try updating to the latest core v1.0.528 and check if the sample project and your real project are working now in WebStorm?
the latest Wallaby core v1.0.1528 fixed this problem in both sample project as well as my real project. Thank you for taking care of it.
Issue description or question
Wallaby isn't working if I have
with { type: 'json' }
syntax in my test file. Here's a sample code and the error from Wallaby console.Wallaby diagnostics report