Skip to content

Commit

Permalink
Merge pull request #235 from mrc-ide/mrc-6022
Browse files Browse the repository at this point in the history
Mrc 6022 - vitest server pt 2
  • Loading branch information
M-Kusumgar authored Dec 3, 2024
2 parents 62156cf + 3ffe65d commit 2a6e5ee
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 148 deletions.
127 changes: 125 additions & 2 deletions app/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wodin",
"private": true,
"version": "0.0.0",
"version": "1.0.0",
"scripts": {
"build": "tsc --project tsconfig.node.json",
"serve": "node dist/server/server.js ../../config",
Expand All @@ -28,6 +28,7 @@
"@vitest/coverage-istanbul": "^2.1.4",
"axios-mock-adapter": "^2.1.0",
"eslint": "^9.14.0",
"genversion": "^3.2.0",
"nodemon": "^3.1.7",
"supertest": "^7.0.0",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion app/server/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Generated by genversion.
export const version = "0.3.0";
export const version = "1.0.0";
14 changes: 7 additions & 7 deletions app/server/tests/apiService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { api } from "../src/apiService";
describe("apiService", () => {
beforeEach(() => {
mockAxios.reset();
jest.resetAllMocks();
vi.resetAllMocks();
});

const mockReq = {
Expand All @@ -23,17 +23,17 @@ describe("apiService", () => {
} as any;

const mockRes = {
status: jest.fn(),
header: jest.fn(),
end: jest.fn()
status: vi.fn(),
header: vi.fn(),
end: vi.fn()
} as any;

const postData = "posted data";

const responseData = { data: "test get" };
const responseHeaders = { respHeader1: "rh1", respHeader2: "rh2" };

const mockNext = jest.fn();
const mockNext = vi.fn();

const testExpectedResponse = () => {
expect(mockRes.status.mock.calls[0][0]).toBe(200);
Expand All @@ -50,13 +50,13 @@ describe("apiService", () => {
headers: AxiosRequestHeaders,
transformResponse: AxiosResponseTransformer
) => {
expect(headers).toStrictEqual({
expect(headers.toJSON()).toEqual({
Accept: "application/json",
"Content-Type": "text",
ArrayHeader: "arr1,arr2"
});
const transformTest = "{\"json\": \"test\"}";
expect((transformResponse as AxiosResponseTransformer)(transformTest)).toBe(transformTest);
expect((transformResponse as any)(transformTest)).toBe(transformTest);
};

const testExpectedError = () => {
Expand Down
12 changes: 6 additions & 6 deletions app/server/tests/appFileReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as fs from "fs";
import fs from "fs";
import { AppFileReader } from "../src/appFileReader";

describe("DefaultCodeReader", () => {
afterEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

it("returns lines from file when file exists", () => {
const mockExistsSync = jest.spyOn(fs, "existsSync").mockReturnValue(true);
const mockReadFileSync = jest.spyOn(fs, "readFileSync").mockReturnValue("line1\nline2\nline3");
const mockExistsSync = vi.spyOn(fs, "existsSync").mockReturnValue(true);
const mockReadFileSync = vi.spyOn(fs, "readFileSync").mockReturnValue("line1\nline2\nline3");

const result = new AppFileReader("/testDir", "R").readFile("TestApp");
expect(result).toStrictEqual(["line1", "line2", "line3"]);
Expand All @@ -18,8 +18,8 @@ describe("DefaultCodeReader", () => {
});

it("returns empty string array when file does not exist", () => {
const mockExistsSync = jest.spyOn(fs, "existsSync").mockReturnValue(false);
const mockReadFileSync = jest.spyOn(fs, "readFileSync");
const mockExistsSync = vi.spyOn(fs, "existsSync").mockReturnValue(false);
const mockReadFileSync = vi.spyOn(fs, "readFileSync");

const result = new AppFileReader("/testDir", "R").readFile("TestApp");
expect(result).toStrictEqual([]);
Expand Down
10 changes: 5 additions & 5 deletions app/server/tests/configReader.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as fs from "fs";
import fs from "fs";
import { ConfigReader } from "../src/configReader";

describe("configReader", () => {
beforeEach(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

it("returns null when config not found", () => {
const mockExistsSync = jest.spyOn(fs, "existsSync").mockReturnValue(false);
const mockExistsSync = vi.spyOn(fs, "existsSync").mockReturnValue(false);

const result = new ConfigReader("root").readConfigFile("test.config");

Expand All @@ -17,8 +17,8 @@ describe("configReader", () => {
});

it("returns parsed config file contents", () => {
const mockExistsSync = jest.spyOn(fs, "existsSync").mockReturnValue(true);
const mockReadFileSync = jest.spyOn(fs, "readFileSync").mockReturnValue("{\"test\": \"value\"}");
const mockExistsSync = vi.spyOn(fs, "existsSync").mockReturnValue(true);
const mockReadFileSync = vi.spyOn(fs, "readFileSync").mockReturnValue("{\"test\": \"value\"}");

const result = new ConfigReader("root").readConfigFile("test.config");

Expand Down
Loading

0 comments on commit 2a6e5ee

Please sign in to comment.