-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add support for inline tests for Vitest using includeSource
attribute
#3108
Comments
includeSource
attribute of Vitest.includeSource
attribute of Vitest
includeSource
attribute of VitestincludeSource
attribute of Vitest config are not run in monorepo
Wallaby doesn't currently support inline tests in source files using Adding as a feature request. |
includeSource
attribute of Vitest config are not run in monorepoincludeSource
attribute
Thanks!
Things work great however if I rename
I think in combo with Smart Start this would work very well. |
At this point in time, we're not entirely sure how One approach you may like to try is to try overriding the |
Also expressing my interest in this feature! Many of the tests where inline tests are most useful are for small chunks of code where creating a separate test file is burdensome. These are also often the tests that wallaby is most handy for too. |
Folks using vitest that want to use inline tests alongside regular tests, this import path from 'node:path'
import fm from 'file-matcher'
export default async () => {
const root = 'src/'
const ext = '{js,jsx,ts,tsx}'
const filePattern = '**/*.' + ext
const testFilePattern = '**/*.{spec,test}.' + ext
const inlineTestPattern = filePattern
const fileOptions = {
path: root,
recursiveSearch: true,
fileFilter: {
fileNamePattern: testFilePattern,
}
}
const inlineOptions = {
path: root,
recursiveSearch: true,
fileFilter: {
fileNamePattern: inlineTestPattern,
content: /import\.meta\.vitest/,
}
}
const cwd = process.cwd()
const relative = filename => path.relative(cwd, filename)
const fileMatcher = new fm.FileMatcher()
const fileTests = (await fileMatcher.find(fileOptions)).map(relative)
const inlineTests = (await fileMatcher.find(inlineOptions)).map(relative)
return {
autoDetect: true,
files: [
root + filePattern,
...fileTests.map(file => `!${file}`),
...inlineTests.map(file => `!${file}`)
],
tests: [
...fileTests,
...inlineTests,
],
}
} |
@stagas - thanks for sharing your configuration. While this may partially work for some projects, it can also lead to errors. For example, if you have a file that imports from your
You will also find that Wallaby App no longer includes your inline test files in your project code coverage calculations. If this works for you, please go ahead and use your configuration, but we wanted to highlight that there are some larger fundamental Wallaby changes that are required to properly support this scenario and this configuration does not add proper support for |
Issue description or question
In my monorepo, I have a
packages/parts/src/lib/foo.ts
file which contains a function and an inline test:My
vite.config.js
points Vitest to run this test and it does, successfully:Wallaby doesn't find this test. However, if I change my filename to
foo.test.ts
if runs just fine. Am I missing something in the documentation? Wallaby has no trouble with running an inline test when the extension istest.ts
, but rather doesn't act on theincludeSource
property of the vitest config to run tests found in files pointed to byincludeSource
.Wallaby diagnostics report
The text was updated successfully, but these errors were encountered: