zed icon indicating copy to clipboard operation
zed copied to clipboard

JavaScript runnables expect to run Jest in every environment

Open Moshyfawn opened this issue 1 year ago • 11 comments

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

image

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

Moshyfawn avatar Jun 09 '24 23:06 Moshyfawn

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"]
  }
]

chungweileong94 avatar Jun 10 '24 09:06 chungweileong94

It actually not a bug, but lack of documentation. You can customize it by overriding js-test/ts-test tag. 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.

Moshyfawn avatar Jun 10 '24 15:06 Moshyfawn

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.

chungweileong94 avatar Jun 10 '24 15:06 chungweileong94

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

jaydenseric avatar Jun 11 '24 03:06 jaydenseric

@Moshyfawn : When run like this it works correctly. Screenshot 2024-06-16 alle 22 12 31

It would be nice to add recognition of before, beforeEach, after, afterEach, it.only and the various IIFE functions.

Screenshot 2024-06-16 alle 22 28 30 Screenshot 2024-06-16 alle 22 32 36
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"); })();

Angelk90 avatar Jun 16 '24 20:06 Angelk90

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"]
  }
]

craigwduckett avatar Jul 03 '24 19:07 craigwduckett

Somewhat related but is there a way to get rid of the default jest tasks? Not sure where they're coming from tbh: CleanShot 2024-08-28 at 10 19 24

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",

micthiesen avatar Aug 28 '24 17:08 micthiesen

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"]
  }
]

I have no clue where I would do something like this. Lack of documentation abounds :)

paularmstrong avatar Sep 08 '24 03:09 paularmstrong

I found this issue due to clicking on this little run icon. Is this configurable?

Screenshot 2024-09-07 at 20 49 40

And secondarily: can I just get rid of these? I'd rather just type the command in my terminal…

paularmstrong avatar Sep 08 '24 03:09 paularmstrong

@paularmstrong You can customize them in tasks.json.

https://zed.dev/docs/tasks

chungweileong94 avatar Sep 08 '24 06:09 chungweileong94

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...

lougreenwood avatar Oct 09 '24 07:10 lougreenwood

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.

jpike88 avatar Mar 04 '25 05:03 jpike88

Yup, would love for my tests to run with bun:test over jest

itsezc avatar May 17 '25 05:05 itsezc

Closed in https://github.com/zed-industries/zed/pull/31711

SomeoneToIgnore avatar May 29 '25 23:05 SomeoneToIgnore