vscode-jest
vscode-jest copied to clipboard
[BUG] The extension does not paint the tests after launch
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"
}
- start the tests
- get the errors
- why hasn't anything changed on the list? they were to be painted red and green.
api: warning | success 2, fail 0, unknown 1; mode: on-demand; state: idle
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
That's intriguing—I haven't encountered this behavior before. Could you create a minimal sample repository that reproduces the issue? Thanks!
@connectdotz You can check e.g. https://github.com/ladariha/jest_test_repro
- run
npm installwithinclientfolder - open folder
clientin VSCode - open file Demo.spec.tsx and click the triangle "play" icon next to describe (line 6)
@ladariha, thanks for the repo, but I did not see the behavior that @NeilRiver described above; everything worked as expected. Did I miss anything?
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?
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
Now it does not work again, no change from my side. Seems it happens intermittently
@ladariha, thanks for trying. If you can get a screenshot or a pattern to produce this state, that will be very helpful.