Skip to content

Instantly share code, notes, and snippets.

@el3um4s
el3um4s / gh-pages.js
Last active October 29, 2021 14:04
MEDIUM - Svelte & GitHub Pages - 01
var ghpages = require('gh-pages');
ghpages.publish(
'public', // path to public directory
{
branch: 'gh-pages',
repo: 'https://github.com/el3um4s/petits-chevaux.git', // Update to point to your repository
user: {
name: 'Samuele', // update to use your name
email: '[email protected]' // Update to use your email
@el3um4s
el3um4s / svelte.config.js
Last active October 29, 2021 14:05
MEDIUM - Svelte & GitHub Pages - 02
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: preprocess(),
kit: {
target: '#svelte',
adapter: adapter({
pages: 'build', // path to public directory
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:23
MEDIUM - Ho to Test Electron Apps - 03
const windowState = await electronApp.evaluate(async ({ BrowserWindow }) => {
const mainWindow = BrowserWindow.getAllWindows()[0];
const getState = () => ({
isVisible: mainWindow.isVisible(),
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(),
isCrashed: mainWindow.webContents.isCrashed(),
});
return new Promise((resolve) => {
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:24
MEDIUM - Ho to Test Electron Apps - 06
import { _electron as electron } from "playwright";
import { test, expect } from "@playwright/test";
test("Launch electron app", async () => {
const electronApp = await electron.launch({ args: ["."] });
const windowState: {
isVisible: boolean;
isDevToolsOpened: boolean;
isCrashed: boolean;
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:25
MEDIUM - Ho to Test Electron Apps - 08
test.describe("Check Man Page", async () => {
let electronApp: ElectronApplication;
let firstWindow: Page;
test.beforeAll(async () => {
electronApp = await electron.launch({ args: ["."] });
firstWindow = await electronApp.firstWindow();
});
// ...
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:27
MEDIUM - Ho to Test Electron Apps - 09
test("Check title", async () => {
const title = await firstWindow.title();
expect(title).toBe("MEMENTO - Svelte, TailwindCSS, Electron and TypeScript");
});
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:28
MEDIUM - Ho to Test Electron Apps - 10
test("Check version number: APP", async () => {
const versionNumberApp = await firstWindow.innerText(
"data-testid=version-number-app"
);
expect(versionNumberApp).not.toBe("-");
const isValidNumberApp = semver.valid(semver.coerce(versionNumberApp));
expect(semver.valid(isValidNumberApp)).not.toBeNull();
});
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:28
MEDIUM - Ho to Test Electron Apps - 11
test("Check Screenshot", async () => {
await firstWindow.screenshot({ path: "tests/screenshot/firstWindow.png" });
expect(await firstWindow.screenshot()).toMatchSnapshot("firstWindow.png");
});
@el3um4s
el3um4s / playwright.config.ts
Created October 29, 2021 14:29
MEDIUM - Ho to Test Electron Apps - 13
import { PlaywrightTestConfig } from "@playwright/test";
const config: PlaywrightTestConfig = {
testDir: "./tests",
expect: {
toMatchSnapshot: { threshold: 0.2 },
},
};
export default config;
@el3um4s
el3um4s / base.test.ts
Created October 29, 2021 14:31
MEDIUM - Ho to Test Electron Apps - 14
let context: BrowserContext;
test.beforeAll(async () => {
electronApp = await electron.launch({ args: ["."] });
context = electronApp.context();
await context.tracing.start({ screenshots: true, snapshots: true });
firstWindow = await electronApp.firstWindow();
await firstWindow.screenshot({ path: "tests/screenshot/firstWindow.png" });
expect(await firstWindow.screenshot()).toMatchSnapshot("firstWindow.png");