vscode-jest icon indicating copy to clipboard operation
vscode-jest copied to clipboard

[BUG] The extension does not paint the tests after launch

Open NeilRiver opened this issue 11 months ago • 9 comments

Installation
Identifier
orta.vscode-jest
Version
6.4.0
Last Updated
2024-12-21, 01:19:12
Size
1.5 MB
Marketplace
Published
2016-10-15, 11:17:19
Last Released
2024-11-04, 02:02:35
  "devDependencies": {
    "@faker-js/faker": "^9.2.0",
    "@types/jest": "^29.5.13",
    "axios": "^1.7.7",
    "faker": "^6.6.6",
    "jest": "^29.7.0",
    "prettier": "^3.3.3",
    "ts-jest": "^29.2.5",
    "uuid": "^11.0.3",
    "zod": "^3.23.8"
  }
{
  "editor.formatOnSave": true,
  "jest.runMode": "on-demand"
}

  1. start the tests Image
  2. get the errors Image
  3. why hasn't anything changed on the list? they were to be painted red and green.

NeilRiver avatar Dec 20 '24 22:12 NeilRiver

api: warning | success 2, fail 0, unknown 1; mode: on-demand; state: idle

NeilRiver avatar Dec 20 '24 22:12 NeilRiver

I figured out the cause... although I'm not entirely sure I understand it, the problem was with throw. When I encountered an error in the test (for example, if the typing changed), throw would fail, and when I formed the object to send to the reporter, it would somehow 'silently break' without any errors.

I found the solution through trial and error, and here's how I fixed it.

from

    performApiChecks(response);
    return response;
  } catch (error: any) {
    console.error('err:', error.response ? error.response.data : error.message);
    throw parseAxiosErrors(error);
  }
}

to

    performApiChecks(response);
    validateResponseData(schema, response) as T;
    return response as AxiosResponse<T>;
  } catch (error: any) {
    console.error('err', error.response ? error.response.data : error.message);
    const parsedError = parseAxiosErrors(error);
    const errorToThrow = new Error();
    Object.assign(errorToThrow, parsedError);
    throw errorToThrow;
  }

full code

async function makeRequest<T>({
  url,
  method,
  schema,
  data = null,
  token,
  headers = {},
  params = {},
  apiName = 'client'
}: RequestParams): Promise<AxiosResponse<T>> {
  try {
    const finalHeaders = new AxiosHeaders({
      ...headers,
      ...(token ? { Authorization: `Bearer ${token}` } : {})
    });

    const axiosInstance = createAxiosInstance(apiConfig[apiName]);

    const response = await axiosInstance({
      url,
      method,
      data,
      headers: finalHeaders,
      params
    });

    performApiChecks(response);
    validateResponseData(schema, response) as T;
    return response as AxiosResponse<T>;
  } catch (error: any) {
    console.error('err', error.response ? error.response.data : error.message);
    const parsedError = parseAxiosErrors(error);
    const errorToThrow = new Error();
    Object.assign(errorToThrow, parsedError);
    throw errorToThrow;
  }
}

Jest developers for VSCode should have provided more detailed errors for their extension, so others wouldn’t have to figure out why their extension isn’t working

NeilRiver avatar Jan 04 '25 15:01 NeilRiver

That's intriguing—I haven't encountered this behavior before. Could you create a minimal sample repository that reproduces the issue? Thanks!

connectdotz avatar Apr 03 '25 21:04 connectdotz

@connectdotz You can check e.g. https://github.com/ladariha/jest_test_repro

  • run npm install within client folder
  • open folder client in VSCode
  • open file Demo.spec.tsx and click the triangle "play" icon next to describe (line 6)

ladariha avatar Apr 07 '25 14:04 ladariha

@ladariha, thanks for the repo, but I did not see the behavior that @NeilRiver described above; everything worked as expected. Did I miss anything?

connectdotz avatar Apr 07 '25 20:04 connectdotz

I can record a screen cast tomorrow if that helps, it happens to me as well (latest VSCode 1.99). Would any specific logs be helpful?

ladariha avatar Apr 07 '25 20:04 ladariha

It works OK for me know as well. I re-setup the extension (delete some obsolete options, set new "jest.commandLine" - I wonder if that was somewhat related

ladariha avatar Apr 08 '25 07:04 ladariha

Now it does not work again, no change from my side. Seems it happens intermittently

ladariha avatar Apr 08 '25 12:04 ladariha

@ladariha, thanks for trying. If you can get a screenshot or a pattern to produce this state, that will be very helpful.

connectdotz avatar Apr 13 '25 20:04 connectdotz