JavaScript runnables expect to run Jest in every environment
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
When running JS tests via the runnables "Play" button in the editor's gutter, Zed always defaults to running Jest instead of any test runner that's used in the project.
See this reproduction sandbox.
Environment
Zed: v0.140.0 (Zed Nightly 75f8be6a0f711bd695cca04d89efa42c8108068c) OS: macOS 14.5.0 Memory: 18 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
No response
It actually not a bug, but lack of documentation. You can customize it by overriding js-test/ts-test tag. For example:
[
{
"label": "npx vitest run -t \"$ZED_SYMBOL\"",
"command": "npx vitest run -t",
"args": ["\"$ZED_SYMBOL\" $ZED_FILE"],
"tags": ["ts-test", "js-test"]
}
]
It actually not a bug, but lack of documentation. You can customize it by overriding
js-test/ts-testtag. For example:
While you can override the runnables config, I'm after "auto-detecting" the test runners in the workspace rather than writing custom tasks for them.
While you can override the runnables config, I'm after "auto-detecting" the test runners in the workspace rather than writing custom tasks for them.
Fair, but instead of auto-detect, auto populate the tasks template could be an option too, or both, like what VSCode did for the tasks.
The defaults should absolutely not be biased to Jest. If Zed has to have a default test runner, it should be the native Node.js test runner:
https://nodejs.org/api/test.html#test-runner
@Moshyfawn : When run like this it works correctly.
It would be nice to add recognition of before, beforeEach, after, afterEach, it.only and the various IIFE functions.
beforeEach(function () {
console.log("beforeEach1");
});
beforeEach(function main() {
console.log("beforeEach2");
});
beforeEach("description", function () {
console.log("beforeEach3");
});
describe("describe", () => {
before(() => console.log("before"));
beforeEach(() => console.log("beforeEach"));
after(() => console.log("after"));
afterEach(() => console.log("afterEach"));
it("it", function () {
assert.equal(true, true);
});
it.only("it only", function () {
assert.equal(true, true);
});
test("test", async () => {
console.log("test");
});
});
(() => console.log("0"))();
(async () => console.log("1"))();
(() => { console.log("2"); })();
(async () => { console.log("3"); })();
(function () { console.log("4"); })();
(async function () { console.log("5"); })();
(function main() { console.log("6"); })();
(async function main() { console.log("7"); })();
additional to @chungweileong94 comment if you are creating tests for tsx files then add tsx-test to the tags also. This is in the tasks.json file also
[
{
"label": "npx vitest run -t \"$ZED_SYMBOL\"",
"command": "npx vitest run -t",
"args": ["\"$ZED_SYMBOL\" $ZED_FILE"],
"tags": ["ts-test", "js-test", "tsx-test"]
}
]
Somewhat related but is there a way to get rid of the default jest tasks? Not sure where they're coming from tbh:
Also if you are using pnpm and vitest this task works for me:
{
"label": "vitest test -t \"$ZED_SYMBOL\"",
"command": "pnpm test:plain $(echo ${ZED_FILE} | sed 's|^${ZED_WORKTREE_ROOT}/||') --testNamePattern \"$ZED_SYMBOL\" --watch --hideSkippedTests",
"tags": ["ts-test", "js-test", "tsx-test"]
}
With this script in package.json:
"test:plain": "vitest",
It actually not a bug, but lack of documentation. You can customize it by overriding
js-test/ts-testtag. For example:[ { "label": "npx vitest run -t \"$ZED_SYMBOL\"", "command": "npx vitest run -t", "args": ["\"$ZED_SYMBOL\" $ZED_FILE"], "tags": ["ts-test", "js-test"] } ]
I have no clue where I would do something like this. Lack of documentation abounds :)
I found this issue due to clicking on this little run icon. Is this configurable?
And secondarily: can I just get rid of these? I'd rather just type the command in my terminal…
@paularmstrong You can customize them in tasks.json.
https://zed.dev/docs/tasks
The defaults should absolutely not be biased to Jest. If Zed has to have a default test runner, it should be the native Node.js test runner:
https://nodejs.org/api/test.html#test-runner
Why default to NodeJS? Not all JS projects are Node projects...
I just don't want defaults at all. We have jest but it's a dependency of another library that only runs in CI and needs several arguments.
I'd rather this default jest suggestions to not be a thing, let people make their own tasks.
Yup, would love for my tests to run with bun:test over jest
Closed in https://github.com/zed-industries/zed/pull/31711