How to run a specific test

I would like to run a specific test in a package, for example only create.test.tsx in @refinedev/inferencer , so I don't run tests for the entire package @kapa.ai
5 Replies
kapa.ai
kapa.ai9h ago
Hi @Phuong. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To run a specific test in a refine package, you can use the Jest test runner with specific filters. Based on the knowledge sources, here's how you can run a specific test file: For running a specific test file like create.test.tsx in the @refinedev/inferencer package, you can use one of these approaches: 1. Using the pnpm test command with a filter:
pnpm test --filter @refinedev/inferencer -- create.test.tsx
pnpm test --filter @refinedev/inferencer -- create.test.tsx
2. Using the nx test command:
pnpm nx test @refinedev/inferencer -- -t "create"
pnpm nx test @refinedev/inferencer -- -t "create"
The -t flag allows you to specify a pattern to match against test names. If you're working on a specific UI framework's inferencer (like Ant Design, Material UI, or Mantine), you might need to run tests from the ui-tests package with a specific pattern:
pnpm test --filter @refinedev/ui-tests -- breadcrumb
pnpm test --filter @refinedev/ui-tests -- breadcrumb
This example would run only tests containing "breadcrumb" in their name or path. If you're encountering issues with the test command, make sure you've properly bootstrapped the packages you're working with first:
pnpm run bootstrap -- --scope @refinedev/inferencer
pnpm run bootstrap -- --scope @refinedev/inferencer
Then you can run the specific test. Note that according to the Testing documentation, refine's components and hooks are already tested by its maintainers, so you typically only need to write end-to-end tests for your application rather than unit tests for refine itself. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9h ago
<@707609347978690641> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
blank-aquamarine
blank-aquamarineOP9h ago
thanks! now how can I run this test pnpm test --filter @refinedev/inferencer -- create.test.tsx with debugger attached in vscode? @kapa.ai
kapa.ai
kapa.ai9h ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To run a specific test with the VSCode debugger attached, you can set up a launch configuration in VSCode specifically for debugging Jest tests in the refine monorepo. Here's how to do it: 1. Create or update your .vscode/launch.json file with a configuration for debugging Jest tests:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Jest Test",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runInBand",
"--testPathPattern=create.test.tsx",
"--config",
"${workspaceFolder}/packages/inferencer/jest.config.js"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Jest Test",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--runInBand",
"--testPathPattern=create.test.tsx",
"--config",
"${workspaceFolder}/packages/inferencer/jest.config.js"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
2. Adjust the configuration as needed: - Update the --testPathPattern to match your specific test file - Make sure the path to the Jest config file is correct for your package 3. Set breakpoints in your test file by clicking in the gutter next to the line numbers in VSCode. 4. Start debugging by: - Going to the "Run and Debug" view in VSCode (Ctrl+Shift+D or Cmd+Shift+D) - Selecting the "Debug Jest Test" configuration from the dropdown - Clicking the green play button or pressing F5 This will run your specific test with the debugger attached, allowing you to step through the code, inspect variables, and debug effectively. If you're working in the refine monorepo and need to debug a specific package's test, you might need to adjust the configuration to work with pnpm's workspace structure. Note that based on the knowledge sources, there isn't specific documentation about debugging tests in refine with VSCode, so this is a general approach for debugging Jest tests in a monorepo structure. I hope this helps! Let me know if you need any clarification or have any issues with setting up the debugger. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai9h ago
<@707609347978690641> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?