Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Jul 3, 2024
1 parent 2275aa3 commit 2ec9ec1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 104 deletions.
23 changes: 0 additions & 23 deletions packages/renderer/tests/ElectronVersions.spec.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/renderer/tests/ReactiveCounter.spec.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/renderer/tests/ReactiveHash.spec.ts

This file was deleted.

47 changes: 1 addition & 46 deletions tests/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {ElectronApplication, JSHandle} from 'playwright';
import {_electron as electron} from 'playwright';
import {afterAll, beforeAll, expect, test} from 'vitest';
import {createHash} from 'crypto';
import type {BrowserWindow} from 'electron';

let electronApp: ElectronApplication;
Expand Down Expand Up @@ -51,49 +50,5 @@ test('Main window web content', async () => {
const page = await electronApp.firstWindow();
const element = await page.$('#app', {strict: true});
expect(element, 'Was unable to find the root element').toBeDefined();
expect((await element.innerHTML()).trim(), 'Window content was empty').not.equal('');
});

test('Preload versions', async () => {
const page = await electronApp.firstWindow();
const versionsElement = page.locator('#process-versions');
expect(await versionsElement.count(), 'expect find one element #process-versions').toStrictEqual(
1,
);

/**
* In this test we check only text value and don't care about formatting. That's why here we remove any space symbols
*/
const renderedVersions = (await versionsElement.innerText()).replace(/\s/g, '');
const expectedVersions = await electronApp.evaluate(() => process.versions);

for (const expectedVersionsKey in expectedVersions) {
expect(renderedVersions).include(
`${expectedVersionsKey}:v${expectedVersions[expectedVersionsKey]}`,
);
}
});

test('Preload nodeCrypto', async () => {
const page = await electronApp.firstWindow();

// Test hashing a random string
const testString = Math.random().toString(36).slice(2, 7);

const rawInput = page.locator('input#reactive-hash-raw-value');
expect(
await rawInput.count(),
'expect find one element input#reactive-hash-raw-value',
).toStrictEqual(1);

const hashedInput = page.locator('input#reactive-hash-hashed-value');
expect(
await hashedInput.count(),
'expect find one element input#reactive-hash-hashed-value',
).toStrictEqual(1);

await rawInput.fill(testString);
const renderedHash = await hashedInput.inputValue();
const expectedHash = createHash('sha256').update(testString).digest('hex');
expect(renderedHash).toEqual(expectedHash);
expect((await element!.innerHTML()).trim(), 'Window content was empty').not.equal('');
});

0 comments on commit 2ec9ec1

Please sign in to comment.