diff --git a/packages/testing/__test__/application.spec.ts b/packages/testing/__test__/application.spec.ts new file mode 100644 index 0000000..055c462 --- /dev/null +++ b/packages/testing/__test__/application.spec.ts @@ -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'); + }); +}); diff --git a/packages/testing/__test__/command.spec.ts b/packages/testing/__test__/command.spec.ts new file mode 100644 index 0000000..75e3166 --- /dev/null +++ b/packages/testing/__test__/command.spec.ts @@ -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'); + }); +}); diff --git a/packages/testing/__test__/dialog.spec.ts b/packages/testing/__test__/dialog.spec.ts new file mode 100644 index 0000000..5d6504d --- /dev/null +++ b/packages/testing/__test__/dialog.spec.ts @@ -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); + }); +}); diff --git a/packages/testing/__test__/fileSystem.spec.ts b/packages/testing/__test__/fileSystem.spec.ts new file mode 100644 index 0000000..d906564 --- /dev/null +++ b/packages/testing/__test__/fileSystem.spec.ts @@ -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(); + }); +}); diff --git a/packages/testing/__test__/process.spec.ts b/packages/testing/__test__/process.spec.ts new file mode 100644 index 0000000..3a2ef5c --- /dev/null +++ b/packages/testing/__test__/process.spec.ts @@ -0,0 +1,25 @@ +import { describe, expect, test, vi } from 'vitest'; +import { yasumu } from '../src'; + +describe('Process', () => { + test('should define an exit method', async () => { + const processExitSpy = vi.spyOn(yasumu.process, 'exit').mockImplementation(() => { + return Promise.resolve(); + }); + + await yasumu.process.exit(0); + + expect(processExitSpy).toHaveBeenCalledTimes(1); + expect(processExitSpy).toHaveBeenCalledWith(0); + + processExitSpy.mockRestore(); + }); + + test('should define a relaunch method', async () => { + const relaunchSpy = vi.spyOn(yasumu.process, 'relaunch'); + + await yasumu.process.relaunch(); + + expect(relaunchSpy).toHaveBeenCalledTimes(1); + }); +}); diff --git a/packages/testing/__test__/store.spec.ts b/packages/testing/__test__/store.spec.ts new file mode 100644 index 0000000..bf609b3 --- /dev/null +++ b/packages/testing/__test__/store.spec.ts @@ -0,0 +1,71 @@ +import { yasumu } from '../src'; +import { describe, test, expect } from 'vitest'; + +describe('Store', () => { + test('should set and get value', async () => { + const store = yasumu.store; + await store.set('key', 'value'); + const value = await store.get('key'); + expect(value).toBe('value'); + await store.delete('key'); + }); + + test('should get all entries', async () => { + const newStore = yasumu.store; + await newStore.set('key1', 'value1'); + await newStore.set('key2', 'value2'); + const entries = await newStore.entries(); + expect(entries).toEqual([ + ['key1', 'value1'], + ['key2', 'value2'], + ]); + }); + + test('should get all keys', async () => { + const store = yasumu.store; + await store.set('key1', 'value1'); + await store.set('key2', 'value2'); + const keys = await store.keys(); + expect(keys).toEqual(['key1', 'key2']); + }); + + test('should get all values', async () => { + const store = yasumu.store; + await store.set('key1', 'value1'); + await store.set('key2', 'value2'); + const values = await store.values(); + expect(values).toEqual(['value1', 'value2']); + }); + + test('should get length', async () => { + const store = yasumu.store; + await store.set('key1', 'value1'); + await store.set('key2', 'value2'); + const length = await store.length(); + expect(length).toBe(2); + }); + + test('should reset store', async () => { + const store = yasumu.store; + await store.set('key1', 'value1'); + await store.set('key2', 'value2'); + await store.reset(); + const length = await store.length(); + expect(length).toBe(0); + }); + + test('should check if key exists', async () => { + const store = yasumu.store; + await store.set('key', 'value'); + const exists = await store.has('key'); + expect(exists).toBe(true); + }); + + test('should delete value', async () => { + const store = yasumu.store; + await store.set('key', 'value'); + await store.delete('key'); + const value = await store.get('key'); + expect(value).toBeUndefined(); + }); +});