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

feat: replace jest with vitest #154

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions resources/js/electron-plugin/__mocks__/electron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { vi } from 'vitest';

const electron = {
app: {
getPath: vi.fn().mockReturnValue('path'),
isPackaged: false,
},
powerMonitor: {
addListener: vi.fn(),
},
};

// Make sure this is an object with properties
Object.defineProperty(electron, '__esModule', { value: true });
export default electron;
export const app = electron.app;
export const powerMonitor = electron.powerMonitor;
210 changes: 0 additions & 210 deletions resources/js/electron-plugin/jest.config.back.ts

This file was deleted.

8 changes: 0 additions & 8 deletions resources/js/electron-plugin/jest.config.js

This file was deleted.

22 changes: 0 additions & 22 deletions resources/js/electron-plugin/jest.config.ts

This file was deleted.

12 changes: 0 additions & 12 deletions resources/js/electron-plugin/mocks/electron.ts

This file was deleted.

36 changes: 20 additions & 16 deletions resources/js/electron-plugin/tests/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
jest.mock('electron');

import startAPIServer, {APIProcess} from "../src/server/api";
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import startAPIServer, { APIProcess } from "../src/server/api";
import axios from "axios";

let apiServer: APIProcess;

describe('API test', () => {
beforeEach(async () => {
jest.resetModules();
vi.resetModules();
apiServer = await startAPIServer('randomSecret');
axios.defaults.baseURL = `http://localhost:${apiServer.port}`;
})
});

afterEach(done => {
apiServer.server.close(done);
afterEach(async () => {
await new Promise<void>((resolve) => {
apiServer.server.close(() => resolve());
});
});

it('starts API server on port 4000', async () => {
Expand All @@ -29,17 +30,20 @@ describe('API test', () => {

it('protects API endpoints with a secret', async () => {
try {
await axios.get('/api/process')
await axios.get('/api/process');
} catch (error) {
expect(error.response.status).toBe(403);
}

const response = await axios.get('/api/process', {
headers: {
'x-nativephp-secret': 'randomSecret',
}
})

expect(response.status).toBe(200);
let response;
try {
response = await axios.get('/api/process', {
headers: {
'x-nativephp-secret': 'randomSecret',
}
});
} finally {
expect(response.status).toBe(200);
}
});
})
});
Loading
Loading