Use `vitest` for backend tests: - `bench` script now uses [vitest's `bench`](https://vitest.dev/api/#bench) - e2e test fails with same error happening now with jest:`data-testid` attribute not present. vitest left, jest right <img width="1264" height="603" alt="image" src="https://github.com/user-attachments/assets/56fc43a6-e143-4208-bf14-7e016aae7fa9" />
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
// @ts-check
|
|
|
|
import axios from "axios";
|
|
import MockAdapter from "axios-mock-adapter";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import gist from "../../api-renamed/gist.js";
|
|
import { renderError } from "../../src/common/render.js";
|
|
import { gist_data } from "../test-data/gist-data.js";
|
|
|
|
const mock = new MockAdapter(axios);
|
|
|
|
afterEach(() => {
|
|
mock.reset();
|
|
});
|
|
|
|
describe("Test /api/gist", () => {
|
|
it("should render error if id is not provided", async () => {
|
|
const req = {
|
|
query: {},
|
|
};
|
|
const res = {
|
|
setHeader: vi.fn(),
|
|
send: vi.fn(),
|
|
};
|
|
mock.onPost("https://api.github.com/graphql").reply(200, gist_data);
|
|
|
|
await gist(req, res);
|
|
|
|
expect(res.setHeader).toHaveBeenCalledWith("Content-Type", "image/svg+xml");
|
|
expect(res.send).toHaveBeenCalledWith(
|
|
renderError({
|
|
message: 'Missing params "id" make sure you pass the parameters in URL',
|
|
secondaryMessage: "/api/gist?id=GIST_ID",
|
|
renderOptions: { show_repo_link: false },
|
|
}),
|
|
);
|
|
});
|
|
});
|