-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Plugin system for added functionality. #842
Comments
As far as I'm concerned, these are simple functions that run after jest sets up environment. |
I have setup something like that (deriving off of the jest-plugins but doing it all ES modules). I have it mostly working .. Except it would be nice to be able to query the current configuration from vitest. e.g. my current use is to query if "globals" is enabled or not. Also I meant "import from vitest" not "vite" (been writing that wrong all day today) For what I have "working now" ( https://github.com/OutOfOrder/vitest-plugins ) |
@sheremet-va so close.. Please see #843 |
I think for #843 is where having a plugin interface would make this much simpler and easier. e.g. have a config options for plugins: [] and have vitest load the modules and call an setup method in the module and pass the vitest module as an argument.. Then it'd be able to access the exports easily in the right context. |
Yes, we had the idea of creating a config option, like |
@sheremet-va yeah.. Something simple like having the function take one argument could work well. // the exported function from the library
export default (vitest) => {
// make calls to vitest.? to register things. e.g. a vitest.addons.registerExports(exports)
vitest.addons.registerExports({context: vitest.describe}); // or just have them assign directly to vitest.addons ?
}
// in test code. if globals: true
context(() => {
// do tests
});
// in test code. if globals: false
import { addons } from 'vitest';
const { set, context } = addons.methods;
context(() => {
// do test
}); Then I wouldn't have to include vitest in my plugins at all and could completely drop the vitest-plugins package and just do a addons = ['vitest-plugin-set', 'vitest-plugin-context'] in the vitest config. If you give me some direction I can build up a PR proposal to the team. |
It may be a good idea to wait a bit. There were some discussions about implementing a feature similar to playwright fixtures (https://playwright.dev/docs/api/class-fixtures). It will let you extend the test context, and each test will receive it instead of the current done callback (that can be replaced by a standard new Promise call). I dont know if it could cover your use case, but the resolved config coild be passed as part of the context. |
Extending tests is implemented with Test Context. Nothing is stopping anyone from creating "plugin-like" packages that jest has. Please, note that if you are importing directly from Vitest, your library should be inlined with |
Clear and concise description of the problem
In my projects where I am using jest I utilize several "plugins" to add functionality to Jest (note they are not really plugins as jest also lacks a plugin infrastructure).
Specifically the ones I am using are from this repo https://github.com/negativetwelve/jest-plugins
What would be "nice" would be to have a way to
Suggested solution
unknown
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: