Skip to content
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

Extension does not detect tests when "test" is aliased or default export etc. #127

Closed
jmagaram opened this issue Jan 25, 2023 · 1 comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@jmagaram
Copy link

jmagaram commented Jan 25, 2023

Consider the test file below. All of these tests execute when run using the vitest command; I can see the results for all in the VS Code terminal. But only the last test is shown in the VS Code Test Explorer; the rest are ignored.

import { assert, test, test as testDup1 } from "vitest";
import * as V from "vitest";

// Not detected by extension
V.test("math with default export", function () {
  assert.equal(1, 1);
});

// Not detected by extension
testDup1("math with aliased test import", function () {
  assert.equal(1, 1);
});

// Not detected by extension
const testDup2 = test;
testDup2("with copied test function variable", function () {
  assert.equal(1, 1);
});

// Not detected by extension
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const testWithTimeout = (title, f) => test(title, f, 3000);
testWithTimeout("with wrapper convenience method", function () {
  assert.equal(1, 1);
});

// Works; detected by extension
test("works 1", function () {
  assert.equal(1, 1);
});

export {};

This is on macOS, latest VS Code, vitest ^0.28.0 and extension dated 1/19/2023.

I ran into this problem while attempting to use vitest from the ReScript programming language. I wrote a binding - just a simple line or two - and it generates this kind of javascript. All tests authored in Rescript go through this wrapper. I'm going to look into whether ReScript can inline everything, so the wrapper disappears, but so far no luck with that.

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Curry from "rescript/lib/es6/curry.js";
import * as Vitest from "vitest";

function test(name, f, timeout) {
  Vitest.test(name, (function () {
          return Curry._1(f, undefined);
        }), timeout);
}

export {
  test ,
}
@sheremet-va
Copy link
Member

This is now supported in pre-release 0.5.0 and higher. Note that the extension now requires Vitest 1.4.0 or higher.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants