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

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

Open
NeilRiver opened this issue Dec 20, 2024 · 2 comments
Open

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

NeilRiver opened this issue Dec 20, 2024 · 2 comments

Comments

@NeilRiver
Copy link

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
Copy link
Author

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

@NeilRiver
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant