generated from cawa-93/vite-electron-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c00f3f
commit a676d9f
Showing
5 changed files
with
133 additions
and
885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const surMac = process.platform === 'darwin'; | ||
export const surLinux = process.platform === 'linux'; | ||
export const surWindows = process.platform === 'win32'; | ||
export const plateforme = process.platform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,104 @@ | ||
import {createHash} from 'crypto'; | ||
import {expect, test} from 'vitest'; | ||
import {sha256sum, versions} from '../src'; | ||
import {expect, test, vi} from 'vitest'; | ||
|
||
test('versions', async () => { | ||
expect(versions).toBe(process.versions); | ||
import type { IpcRendererEvent } from 'electron'; | ||
import type { messageDeServeur, messageInitServeur } from '@constl/mandataire-electron-principal'; | ||
|
||
import {v4 as uuidv4} from 'uuid'; | ||
import EventEmitter from 'events'; | ||
import { attente } from '@constl/utils-tests'; | ||
|
||
import { | ||
envoyerMessageÀConstellation, | ||
écouterMessagesDeConstellation, | ||
envoyerMessageÀServeurConstellation, | ||
écouterMessagesDeServeurConstellation, | ||
surLinux, surMac, surWindows, plateforme, | ||
} from '../src'; | ||
import type { mandataire } from '@constl/ipa'; | ||
|
||
test('plateforme', async () => { | ||
expect(plateforme).toBe(process.platform); | ||
|
||
const plateformes: Partial<Record<NodeJS.Platform, boolean>> = { | ||
darwin: surMac, | ||
linux: surLinux, | ||
win32: surWindows, | ||
}; | ||
|
||
expect(plateformes[process.platform]).toBe(true); | ||
|
||
for (const p of Object.keys(plateformes).filter(p => p !== process.platform)) { | ||
expect(plateformes[p]).toBe(false); | ||
} | ||
}); | ||
|
||
vi.mock('electron', () => { | ||
const événements = new EventEmitter(); | ||
|
||
const ipcRenderer: Pick<Electron.IpcRenderer, 'on' | 'once' | 'send'> = { | ||
on(channel: string, listener: (event: IpcRendererEvent, ...args: unknown[]) => void) { | ||
if (channel === 'deClient') { | ||
événements.on(channel, (x: [IpcRendererEvent, mandataire.messages.MessageDeTravailleur[]]) => listener(...x)); | ||
} else if (channel === 'deServeur') { | ||
événements.on(channel, (x: [IpcRendererEvent, messageDeServeur[]]) => listener(...x)); | ||
} | ||
return this; | ||
}, | ||
once(channel: string, listener: (event: IpcRendererEvent, ...args: unknown[]) => void) { | ||
if (channel === 'clientPrêt') { | ||
// @ts-expect-error on saute l'événement | ||
listener({}); | ||
} | ||
événements.once(channel, listener); | ||
return this; | ||
}, | ||
send(channel: string, ...args: unknown[]) { | ||
if (channel === 'pourClient'){ | ||
événements.emit('deClient', [{}, args[0]]); | ||
} else if (channel === 'pourServeur'){ | ||
événements.emit('deServeur', [{}, args[0]]); | ||
} | ||
return this; | ||
}, | ||
}; | ||
|
||
|
||
return {ipcRenderer}; | ||
}); | ||
|
||
test('nodeCrypto', async () => { | ||
// Test hashing a random string. | ||
const testString = Math.random().toString(36).slice(2, 7); | ||
const expectedHash = createHash('sha256').update(testString).digest('hex'); | ||
test('messages ipa constellation', async () => { | ||
const résultat = new attente.AttendreRésultat<mandataire.messages.MessageDeTravailleur>(); | ||
|
||
expect(sha256sum(testString)).toBe(expectedHash); | ||
écouterMessagesDeConstellation( | ||
message => résultat.mettreÀJour(message), | ||
); | ||
|
||
const message: mandataire.messages.MessagePourTravailleur = { | ||
type: 'action', | ||
id: uuidv4(), | ||
fonction: ['on', 'test', 'une', 'fonction'], | ||
args: { qui: 'nexiste', pas: 'vraiment' }, | ||
}; | ||
await envoyerMessageÀConstellation(message); | ||
|
||
const val = await résultat.attendreExiste(); | ||
expect(val).to.deep.equal(message); | ||
}); | ||
|
||
test('messages serveur constellation', async () => { | ||
const résultat = new attente.AttendreRésultat<messageDeServeur>(); | ||
|
||
écouterMessagesDeServeurConstellation( | ||
message => résultat.mettreÀJour(message), | ||
); | ||
|
||
const message: messageInitServeur = { | ||
type: 'init', | ||
port: 1234, | ||
}; | ||
envoyerMessageÀServeurConstellation(message); | ||
|
||
const val = await résultat.attendreExiste(); | ||
expect(val).to.deep.equal(message); | ||
}); | ||
|
Oops, something went wrong.