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

test: add adapter tests #163

Merged
merged 9 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
21 changes: 21 additions & 0 deletions packages/testing/__test__/application.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { beforeAll, describe, expect, test } from 'vitest';
import { ApplicationMock, yasumu } from '../src';

describe('Application Mock', () => {
const app = yasumu.app;

test('should get name', async () => {
const name = await app.getName();
expect(name).toBe('Yasumu');
});

test('should get runtime version', async () => {
const version = await app.getRuntimeVersion();
expect(version).toBe('1.0.0');
});

test('should get version', async () => {
const version = await app.getVersion();
expect(version).toBe('1.0.0');
});
});
26 changes: 26 additions & 0 deletions packages/testing/__test__/command.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, beforeAll, expect, test } from 'vitest';
import { CommandsMock, yasumu, CommandInterceptor } from '../src';

describe('Commands Mock', () => {
const command = yasumu.command;
new CommandInterceptor('ping').intercept(() => {
return 'Pong!';
});


test('should add plugin listener', async () => {
const listener = await command.addPluginListener('plugin', 'event', () => {});
expect(listener.channelId).toBe(0);
expect(listener.event).toBe('event');
expect(listener.plugin).toBe('plugin');
});

test('should invoke command', async () => {
const result = await command.invoke('ping');
expect(result).toBe('Pong!');
});

test('should throw error to handle non-existent command ', async () => {
expect(yasumu.command.invoke('unknown')).rejects.toThrowError('Command unknown not found');
});
});
20 changes: 20 additions & 0 deletions packages/testing/__test__/dialog.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { yasumu } from '../src';
import { describe, test, expect } from 'vitest';

describe('Dialog Mock', () => {
const dialog = yasumu.dialog;

test('should open a dialog', async () => {
const result = await dialog.open({
title: 'Test',
});
expect(result).toBe(null);
});

test('should save a dialog', async () => {
const result = await dialog.save({
title: 'Test',
});
expect(result).toBe(null);
});
});
72 changes: 72 additions & 0 deletions packages/testing/__test__/fileSystem.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { yasumu } from '../src';
import { describe, test, expect, beforeAll } from 'vitest';
import fs from 'node:fs/promises';
import path from 'node:path';

const testFilePath = path.join(__dirname, 'testFile.txt');
const testDirPath = path.join(__dirname, 'testDir');

describe('FileSystem', () => {
beforeAll(async () => {
await fs.writeFile(testFilePath, 'Initial content for testing');
});

test('should have a lstat method', async () => {
const result = await yasumu.fs.lstat(testFilePath);
expect(result).toBeDefined();
expect(result.isDirectory).toBe(false);
expect(result.isFile).toBe(true);
expect(result.isSymlink).toBe(false);
expect(result.size).toBe(27);
});

test('should have a copyFile method', async () => {
const copyPath = path.join(__dirname, 'copyFile.txt');
await yasumu.fs.copyFile(testFilePath, copyPath);
expect(fs.readFile(copyPath, { encoding: 'utf-8' })).resolves.toBe('Initial content for testing');
yasumu.fs.remove(copyPath);
});

test('should have an exists method', () => {
expect(yasumu.fs.exists(testFilePath)).resolves.toBe(true);
});

test('should have a mkdir method', async () => {
await yasumu.fs.mkdir(testDirPath);
const exists = await yasumu.fs.exists(testDirPath);
expect(exists).toBe(true);

const stats = await yasumu.fs.lstat(testDirPath);
expect(stats.isDirectory).toBe(true);
});

test('should have a readDir method', async () => {
const file1 = path.join(testDirPath, 'file1.txt');
await fs.writeFile(file1, 'File 1 content');
const entries = await yasumu.fs.readDir(testDirPath);
const entryNames = entries.map((entry) => entry.name);

expect(entries).toBeDefined();
expect(Array.isArray(entries)).toBe(true);
expect(entryNames).toContain('file1.txt');
});

test('should have a readFile method', async () => {
const result = await yasumu.fs.readFile(testFilePath);
expect(result).toBe('Initial content for testing');
});

test('should have a remove method', async () => {
await yasumu.fs.remove(testFilePath);
const result = await yasumu.fs.exists(testFilePath);
expect(result).toBe(false);
});

test('should have a writeFile method', () => {
expect(yasumu.fs.writeFile).toBeDefined();
});

test('should have a watch method', () => {
expect(yasumu.fs.watch).toBeDefined();
});
});
1 change: 1 addition & 0 deletions packages/testing/__test__/testDir/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
File 1 content
Loading