Closed tslocke closed 2 years ago
Update - I'm getting the same error with older revisions of my code, so nothing to do with vitest (was previously jest).
Not sure what changed to cause this - I did recently update the wallaby core version
Here is the diagnostic report for an older revision that was previously working in Wallaby. It looks like the new version of Wallaby sees the vite.config.ts
and assumes the framework is vitest.
{
editorVersion: '1.67.2',
pluginVersion: '1.0.344',
editorType: 'VSCode',
osVersion: 'darwin 21.4.0',
nodeVersion: 'v16.15.1',
coreVersion: '1.0.1299',
checksum: 'MDY1YTZlY2QyZTAzNjNiNDliMmViMDE1ODI2MDE1NjMsMTY4MjcyNjQwMDAwMCww',
config: {
resolveGetters: true,
diagnostics: {
vitest: {
file: {
config: "import { defineConfig, loadEnv } from 'vite';\n" +
"import solidPlugin from 'vite-plugin-solid';\n" +
"import tsconfigPaths from 'vite-tsconfig-paths'\n" +
'\n' +
'export default defineConfig(({mode}) => ({\n' +
' plugins: [\n' +
' tsconfigPaths({loose: true}),\n' +
' solidPlugin()\n' +
' ],\n' +
' build: {\n' +
" target: 'esnext',\n" +
' polyfillDynamicImport: false,\n' +
' minify: false,\n' +
' chunkSizeWarningLimit: 600,\n' +
' rollupOptions: {\n' +
" input: './src/main.tsx',\n" +
' output: {\n' +
' assetFileNames: "[name][extname]",\n' +
' chunkFileNames: "[name].js",\n' +
' entryFileNames: "[name].js",\n' +
' manualChunks: () => "main.js"\n' +
' }\n' +
' }\n' +
' },\n' +
' define: {\n' +
' ...envWithProcessPrefix(mode),\n' +
` ...(mode == 'production' ? {} : {'__REACT_DEVTOOLS_GLOBAL_HOOK__': '{ "isDisabled": true }'})\n` +
' }\n' +
'}))\n' +
'\n' +
'function envWithProcessPrefix(mode) {\n' +
' const env = loadEnv(mode, process.cwd())\n' +
'\n' +
' return Object.entries(env).reduce(\n' +
' (prev, [key, val]) => {\n' +
' return {\n' +
' ...prev,\n' +
' [\'process.env.\' + key]: `"${val}"`,\n' +
' }\n' +
' },\n' +
' {},\n' +
' )\n' +
'}\n'
},
config: {
allowOnly: true,
watch: true,
globals: false,
environment: 'node',
threads: true,
clearMocks: false,
restoreMocks: false,
mockReset: false,
include: [ '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' ],
exclude: [ '**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**' ],
testTimeout: 5000,
hookTimeout: 10000,
isolate: true,
watchExclude: [ '**/node_modules/**', '**/dist/**' ],
forceRerunTriggers: [ '**/package.json/**', '**/vitest.config.*/**', '**/vite.config.*/**' ],
update: false,
reporters: [ 'default' ],
silent: false,
ui: false,
uiBase: '/__vitest__/',
open: true,
css: { include: [ {} ] },
coverage: {
enabled: false,
clean: true,
cleanOnRerun: false,
reportsDirectory: '<homeDir>/Projects/Inio/inio/web/coverage',
excludeNodeModules: true,
exclude: [
'coverage/**',
'packages/*/test{,s}/**',
'**/*.d.ts',
'cypress/**',
'test{,s}/**',
'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
'**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
'**/__tests__/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}',
'**/.{eslint,mocha,prettier}rc.{js,cjs,yml}'
],
reporter: [ 'text', 'html' ],
allowExternal: false,
extension: [
'.js', '.cjs',
'.mjs', '.ts',
'.tsx', '.jsx',
'.vue', '.svelte'
],
tempDirectory: '<homeDir>/Projects/Inio/inio/web/coverage/tmp'
},
fakeTimers: { loopLimit: 10000, shouldClearNativeTimers: true, toFake: [ 'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date' ] },
maxConcurrency: 5,
defines: { __REACT_DEVTOOLS_GLOBAL_HOOK__: { isDisabled: true } },
root: '<homeDir>/Projects/Inio/inio/web',
deps: { inline: [ {}, {}, {}, {}, {}, {}, '@nuxt/test-utils' ] },
snapshotOptions: { snapshotFormat: {}, updateSnapshot: 'new' },
setupFiles: [],
cache: { dir: '<homeDir>/Projects/Inio/inio/web/node_modules/.vitest' },
sequence: {},
package: {
version: '0.18.0',
urls: { hooks: 'file://<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.344/wallaby4e3442/runners/node/hooks.mjs' },
paths: { root: '<homeDir>/Projects/Inio/inio/web/node_modules/vitest', dist: '<homeDir>/Projects/Inio/inio/web/node_modules/vitest/dist' }
}
}
}
},
testFramework: { version: 'vitest@0.14.0', configurator: 'vitest@0.14.0', reporter: 'vitest@0.14.0', starter: 'vitest@0.14.0', autoDetected: true },
preserveComments: false,
extractComments: true,
files: [
{ pattern: '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ignore: true, trigger: true, load: true },
{ pattern: '**/node_modules/**', ignore: true, trigger: true, load: true },
{ pattern: '**/dist/**', ignore: true, trigger: true, load: true },
{ pattern: '**/cypress/**', ignore: true, trigger: true, load: true },
{ pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true },
{ pattern: '**/*.*', ignore: false, trigger: true, load: true, order: 1 }
],
tests: [
{ pattern: '**/node_modules/**', ignore: true, trigger: true, load: true, test: true },
{ pattern: '**/dist/**', ignore: true, trigger: true, load: true, test: true },
{ pattern: '**/cypress/**', ignore: true, trigger: true, load: true, test: true },
{ pattern: '**/.{idea,git,cache,output,temp}/**', ignore: true, trigger: true, load: true, test: true },
{ pattern: '**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ignore: false, trigger: true, load: true, test: true, order: 2 }
],
workers: { initial: 1, regular: 1, recycle: false },
filesWithNoCoverageCalculated: [],
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 },
teardown: undefined,
hints: {
ignoreCoverage: '__REGEXP /ignore coverage|istanbul 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: '--experimental-loader=file://<homeDir>/.vscode/extensions/wallabyjs.wallaby-vscode-1.0.344/wallaby4e3442/runners/node/hooks.mjs' },
runner: '<homeDir>/.fnm/node-versions/v16.15.1/installation/bin/node',
viewportSize: { width: 800, height: 600 },
options: { width: 800, height: 600 },
bundle: true
},
reportUnhandledPromises: true,
slowTestThreshold: 75,
lowCoverageThreshold: 80,
loose: undefined,
symlinkNodeModules: undefined,
configCode: 'module.exports = function () {\n return {\n resolveGetters: true\n };\n};\n'
},
packageJSON: {
dependencies: {
'@headlessui/react': '^1.6',
'@popperjs/core': '^2.11.5',
arangojs: '^7.6',
axios: '^0.27',
'fast-array-diff': '^1.0.1',
'fractional-indexing': '^3.0',
fuzzy: '^0.1',
'hotkeys-js': '^3.8',
inflection: '^1.13',
mitt: '^3.0',
nanoid: '^3.3',
'next-tick': '^1.1',
'prosemirror-autocomplete': 'https://github.com/tslocke/prosemirror-autocomplete',
'prosemirror-commands': '^1.3',
'prosemirror-dropcursor': '^1.5',
'prosemirror-gapcursor': '^1.3',
'prosemirror-history': '^1.3',
'prosemirror-inputrules': '^1.2',
'prosemirror-keymap': '^1.2',
'prosemirror-model': '^1.17',
'prosemirror-schema-list': '^1.2',
'prosemirror-state': '^1.4',
'prosemirror-transform': '^1.6',
'prosemirror-view': '^1.25',
'pusher-js': '^7.0',
ramda: '^0.28',
react: '^18.1',
'react-dom': '^18.1',
replicache: '^10.0',
'solid-app-router': '^0.3',
'solid-js': '^1.3',
'tippy.js': '^6.3'
},
devDependencies: {
'@tailwindcss/forms': '^0.5',
'@tailwindcss/line-clamp': '^0.4',
'@tailwindcss/typography': '^0.5',
'@types/inflection': '^1.13.0',
'@types/jest': '^27.4.1',
'@types/next-tick': '^1.0.0',
'@types/node': '^17.0',
'@types/object-inspect': '^1.8.1',
'@types/ramda': '^0.28',
'@types/react': '^18.0',
'@types/react-dom': '^18.0',
autoprefixer: '^10.4',
jest: '^27.5',
'json-beautify': '^1.1',
'object-inspect': '^1.11',
postcss: '^8.3',
'solid-jest': '^0.2',
tailwindcss: '^3.0',
'ts-unused-exports': '^8.0',
'type-fest': '^2.12',
typescript: '^4.5',
vite: '^2.8',
'vite-plugin-solid': '^2.2',
'vite-tsconfig-paths': '^3.4'
}
},
fs: { numberOfFiles: 120 },
debug: []
}
I've tried adding testFramework: 'jest'
to my wallaby.js (and double checking that config file was selected) and from the diagnostic report it still looks like it's detecting vitest as the test framework
I'm trying out vitest. Tests are passing from the command line, but as soon as I start Wallaby, I get
Error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
There's no indication of which file has the problem.
Update - I'm getting the same error with older revisions of my code, so nothing to do with vitest (was previously jest).
Not sure what changed to cause this - I did recently update the wallaby core version
We found a previous vitest issue where someone had the same problem.
Had that error on a Vite + Vue 3 + TS project recently when the files were accidentally compiled to .js files as well by my IDE. Removing the compiled files resolved it
Could you please check whether your .ts
files are compiled to .js
files along side (or even in a dist folder that may be used for running your tests) and try removing them?
Here is the diagnostic report for an older revision that was previously working in Wallaby. It looks like the new version of Wallaby sees the vite.config.ts and assumes the framework is vitest.
In your older version diagnostics report, your project dependencies include jest
while your initial diagnostics report shows that you do not have jest
installed, but you do have vitest
installed. When Wallaby starts, it attempts to automatically configure your project's tests in the following order:
angular
and configure to run Angular tests,jest
and configure to run Jest tests,vitest
and configure to run Vitest tests.In your case, since you don't have jest installed as a project dependency, the check is failing and it falls through to trying to run your vitest
tests.
I've tried adding testFramework: 'jest' to my wallaby.js (and double checking that config file was selected) and from the diagnostic report it still looks like it's detecting vitest as the test framework
Setting testFramework: 'jest'
will use our legacy jest
integration and should still fail for you if you have correctly specified to use your configuration file. If for some reason you have multiple testing frameworks installed and wanted to explicitly set the testing framework detection order, you may specify a configuration file as shown below. You can also remove items from the array to not attempt to detect a specific testing framework.
wallaby.js (configuration file)
module.exports = ({
autoDetect: ['angular', 'jest', 'vitest'], // default detection order
});
I think our response will solve your problem. If not, please reply and we will reopen the issue.
Thank you for the help
Re: the parsing error, I did have a dist folder with js inside but deleting it didn't help. Given that issue you linked is about regular vitest (i.e. not with Wallaby), bear in mind that running vitest on the command line is working fine for me. So the question is, what is different when it runs via Wallaby. I did see this comment on that thread:
I feel like this issue might have a simple cause: running vite in the wrong directory. It keeps happening to me but it's always because I'm not in my app's root folder
Could that be relevant?
I'll have a go at getting things running with jest again using your advice...
OK I'm back up and running again with jest - must have messed up / missed a yarn install
somewhere along the lines. Sorry for the noise. Thanks very much.
Would still be great to get vitest working
Would still be great to get vitest working
Are you able to share a repo that has the same problem that you're experiencing so we can try and work out why it's not working?
I got it down to a pretty small repro: https://github.com/tslocke/vitest-wallaby-debug
The app is using SolidJS, BTW. See use of vite-plugin-solid
in vite.config.js
. I'm guessing that might be a combination you've not tested.
yarn test
works, Wallaby hits a parse failure.
The error message changed to something more specific at a certain point while I was stripping away the irrelevant stuff in my codebase, but I'm fairly sure this is the same issue.
Thanks for the sample repo. The parse error is from some additional instructions that Wallaby is adding to your code to capture code coverage. Not sure yet why it's failing as it is valid syntax. Will report back when we work it out.
Thanks for the sample repo. The problem was indeed with vitest-plugin-solid
. When Wallaby runs code in vitest
, it needs to add a cachebreaker to the end of the file URLs (e.g. /src/component.tsx?wallaby=${file.change.timestamp}
). The vitest-plugin-solid
getExtension() logic is simple and doesn't handle this case properly. Wallaby now patches vitest-plugin-solid
at runtime to fix this problem.
Please update to the latest version fo Wallaby core, v1.0.1301
, it will fix your problem.
Thanks for going above and beyond here : )
The parse bug does seem to be fixed, but I have another issue. It seems Wallaby is treating .tsx files as .jsx
I've added a commit to the same repo to illustrate the problem - it just adds some typescript syntax to the tsx file.
With this commit, I get
SyntaxError: ./src/component.tsx?wallaby=...: Unexpected token, expected "," (1:25)
p.s. I'll open an issue on vitest-plugin-solid.
Thanks for letting us know about your other issue. There was another place we needed to patch vite-plugin-solid
. This has been fixed in Wallaby core v1.0.1302
.
p.s. I'll open an issue on vitest-plugin-solid.
I'm not entirely sure that appending the cache breaker to the path is necessarily something that they should support. While it's possible and fully supported by file URI, it may be something specific to Wallaby.
Thanks very much for great support here. All working now. I had another issue related to loading multiple instances of modules, but I was able to work around it. I have a question about that but I'll post separately.
Issue description or question
I'm trying out vitest. Tests are passing from the command line, but as soon as I start Wallaby, I get
There's no indication of which file has the problem.
Wallaby diagnostics report