zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
48.87k stars 2.94k forks source link

JavaScript runnables expect to run Jest in every environment #12828

Open Moshyfawn opened 4 months ago

Moshyfawn commented 4 months ago

Check for existing issues

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

chungweileong94 commented 4 months ago

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"]
  }
]
Moshyfawn commented 4 months ago

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.

chungweileong94 commented 4 months ago

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.

jaydenseric commented 4 months ago

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

Angelk90 commented 4 months ago

@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"); })();
craigwduckett commented 3 months ago

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"]
  }
]
micthiesen commented 1 month ago

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",
paularmstrong commented 1 month ago

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 commented 1 month ago

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…

chungweileong94 commented 1 month ago

@paularmstrong You can customize them in tasks.json.

https://zed.dev/docs/tasks

lougreenwood commented 2 weeks ago

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