From a6968438a2fb4f9eeb86611b28eaf94e8499240b Mon Sep 17 00:00:00 2001 From: ndom91 Date: Mon, 6 May 2024 13:06:13 +0200 Subject: [PATCH] chore: prettier --- app/e2e/playwright/basic.spec.ts | 12 +- app/playwright.config.ts | 36 ++--- app/src/app.html | 20 ++- app/src/hooks.client.ts | 12 +- app/src/lib/testing/fixtures.ts | 233 ++++++++++++++++--------------- app/src/lib/testing/index.ts | 86 ++++++------ app/src/routes/+layout.ts | 76 +++++----- app/vite.config.ts | 94 ++++++------- 8 files changed, 284 insertions(+), 285 deletions(-) diff --git a/app/e2e/playwright/basic.spec.ts b/app/e2e/playwright/basic.spec.ts index 9c691a28a..d42709e64 100644 --- a/app/e2e/playwright/basic.spec.ts +++ b/app/e2e/playwright/basic.spec.ts @@ -1,15 +1,15 @@ import { test, expect } from '@playwright/test'; test('has empty title', async ({ page }) => { - await page.goto('http://localhost:1420'); + await page.goto('http://localhost:1420'); - await expect(page).toHaveTitle(''); + await expect(page).toHaveTitle(''); }); test('has text package.json', async ({ page }) => { - await page.goto('http://localhost:1420'); + await page.goto('http://localhost:1420'); - const listBox = page.getByRole('listbox').getByRole('button') + const listBox = page.getByRole('listbox').getByRole('button'); - await expect(listBox).toHaveText('package.json'); -}) + await expect(listBox).toHaveText('package.json'); +}); diff --git a/app/playwright.config.ts b/app/playwright.config.ts index 307bd532e..90a07381d 100644 --- a/app/playwright.config.ts +++ b/app/playwright.config.ts @@ -4,22 +4,22 @@ import { defineConfig, devices } from '@playwright/test'; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - testDir: './e2e/playwright', - testMatch: /(.+\.)?(test|spec)\.[jt]s/, - projects: [ - { - name: 'Google Chrome', - use: { ...devices['Desktop Chrome'] } - } - ], - expect: { - timeout: 20 * 1000, - }, - use: { - trace: 'retain-on-failure', - }, - webServer: { - command: 'pnpm test:e2e:run', - url: 'http://localhost:1420', - } + testDir: './e2e/playwright', + testMatch: /(.+\.)?(test|spec)\.[jt]s/, + projects: [ + { + name: 'Google Chrome', + use: { ...devices['Desktop Chrome'] } + } + ], + expect: { + timeout: 20 * 1000 + }, + use: { + trace: 'retain-on-failure' + }, + webServer: { + command: 'pnpm test:e2e:run', + url: 'http://localhost:1420' + } }); diff --git a/app/src/app.html b/app/src/app.html index 930498305..443c8f97e 100644 --- a/app/src/app.html +++ b/app/src/app.html @@ -1,16 +1,14 @@ + + - - - - - - %sveltekit.head% - - - -
%sveltekit.body%
- + + + %sveltekit.head% + + +
%sveltekit.body%
+ diff --git a/app/src/hooks.client.ts b/app/src/hooks.client.ts index 873d32fac..9ba068aaf 100644 --- a/app/src/hooks.client.ts +++ b/app/src/hooks.client.ts @@ -3,9 +3,9 @@ import { error as logErrorToFile } from 'tauri-plugin-log-api'; import type { NavigationEvent } from '@sveltejs/kit'; function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) { - console.error(error.message + '\n' + error.stack); - logErrorToFile(error.toString()); - console.error('An error occurred on the client side:', error, event); + console.error(error.message + '\n' + error.stack); + logErrorToFile(error.toString()); + console.error('An error occurred on the client side:', error, event); } export const handleError = handleErrorWithSentry(myErrorHandler); @@ -19,7 +19,7 @@ export const handleError = handleErrorWithSentry(myErrorHandler); */ const originalUnhandledHandler = window.onunhandledrejection; window.onunhandledrejection = (event: PromiseRejectionEvent) => { - logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL); - console.log('Unhandled exception', event.reason); - originalUnhandledHandler?.bind(window)(event); + logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL); + console.log('Unhandled exception', event.reason); + originalUnhandledHandler?.bind(window)(event); }; diff --git a/app/src/lib/testing/fixtures.ts b/app/src/lib/testing/fixtures.ts index be9124a07..d915b50d3 100644 --- a/app/src/lib/testing/fixtures.ts +++ b/app/src/lib/testing/fixtures.ts @@ -1,103 +1,103 @@ -import type { User } from '$lib/stores/user' +import type { User } from '$lib/stores/user'; export type Constructor = new (...args: any[]) => T; export type Class = InstanceType>; export const project = { - api: null, - description: null, - gitbutler_code_push_state: null, - gitbutler_data_last_fetch: null, - id: "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295", - ok_with_force_push: true, - omit_certificate_check: null, - path: "/opt/ndomino/home2021", - preferred_key: "systemExecutable", - project_data_last_fetch: Object, - fetched: { - timestamp: { - nanos_since_epoch: 410569736, - secs_since_epoch: 1714924416 - } - }, - title: "home2021" -} + api: null, + description: null, + gitbutler_code_push_state: null, + gitbutler_data_last_fetch: null, + id: 'ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295', + ok_with_force_push: true, + omit_certificate_check: null, + path: '/opt/ndomino/home2021', + preferred_key: 'systemExecutable', + project_data_last_fetch: Object, + fetched: { + timestamp: { + nanos_since_epoch: 410569736, + secs_since_epoch: 1714924416 + } + }, + title: 'home2021' +}; export const author = { - name: 'John Snow', - email: 'user@company.com', - gravatarUrl: 'https://gravatar.com/avatar/abc123' -} + name: 'John Snow', + email: 'user@company.com', + gravatarUrl: 'https://gravatar.com/avatar/abc123' +}; export const remoteCommit0 = { - id: 'fe30876278739f7182effd27e9d9debde648b4de', - author, - description: 'fix: updated files', - createdAt: 1714902366, -} + id: 'fe30876278739f7182effd27e9d9debde648b4de', + author, + description: 'fix: updated files', + createdAt: 1714902366 +}; export const remoteCommit1 = { - id: 'fe30876278739f7182effd27e9d9debde648b4dd', - author, - description: 'fix: updated files', - createdAt: 1714902366, -} + id: 'fe30876278739f7182effd27e9d9debde648b4dd', + author, + description: 'fix: updated files', + createdAt: 1714902366 +}; export const remoteBranch0 = { - sha: '90c225edcc74b31718a9cd8963c1bc89c17d8863', - name: '', - upstream: '', - lastCommitTimestampMs: 1714902366140, - lastCommitAuthor: 'John Snow' -} + sha: '90c225edcc74b31718a9cd8963c1bc89c17d8863', + name: '', + upstream: '', + lastCommitTimestampMs: 1714902366140, + lastCommitAuthor: 'John Snow' +}; export const baseBranch = { - branchName: 'origin/gitbutler/integration', - remoteName: 'origin', - remoteUrl: 'ssh://github.com/user/project.git', - baseSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', - currentSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', - behind: 0, - upstreamCommits: [], - recentCommits: [remoteCommit0], - lastFetchedMs: 1714843209991, -} + branchName: 'origin/gitbutler/integration', + remoteName: 'origin', + remoteUrl: 'ssh://github.com/user/project.git', + baseSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', + currentSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', + behind: 0, + upstreamCommits: [], + recentCommits: [remoteCommit0], + lastFetchedMs: 1714843209991 +}; export const user: User = { - access_token: "c5da8ec0-2a2e-4f1c-a796-686c5606e566", - created_at: "2024-05-04T13:27:30Z", - email: "yo@ndo.dev", - family_name: undefined, - github_access_token: undefined, - github_username: undefined, - given_name: undefined, - id: 31, - locale: "en_US", - name: "Nico", - picture: "https://source.boringavatar.com/marble/120", - role: undefined, - updated_at: "2024-05-05T15:38:02Z", - supporter: false -} + access_token: 'c5da8ec0-2a2e-4f1c-a796-686c5606e566', + created_at: '2024-05-04T13:27:30Z', + email: 'yo@ndo.dev', + family_name: undefined, + github_access_token: undefined, + github_username: undefined, + given_name: undefined, + id: 31, + locale: 'en_US', + name: 'Nico', + picture: 'https://source.boringavatar.com/marble/120', + role: undefined, + updated_at: '2024-05-05T15:38:02Z', + supporter: false +}; export const remoteBranchData = { - sha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', - name: 'test', - upstream: 'abc123', - authors: [author], - displayName: 'test', - lastCommitTs: new Date(), - firstCommitAt: new Date(), - ahead: 0, - behind: 0, - commits: [remoteCommit0], - isMergeable: true, -} + sha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', + name: 'test', + upstream: 'abc123', + authors: [author], + displayName: 'test', + lastCommitTs: new Date(), + firstCommitAt: new Date(), + ahead: 0, + behind: 0, + commits: [remoteCommit0], + isMergeable: true +}; export const fileHunk = { - binary: false, - changeType: "modified", - diff: ` + binary: false, + changeType: 'modified', + diff: ` @@ -63,7 +63,7 @@ "simple-git-hooks": "^2.11.1", "tailwindcss": "^3.4.3", @@ -108,46 +108,47 @@ export const fileHunk = { "commitlint": { "extends": [ `, - end: 70, - filePath: "package.json", - hash: "dc79c984a36b2f8a29007633bde4daf3", - id: "63-70", - locked: false, - lockedTo: null, - modifiedAt: 1714829527993, - oldStart: 63, - start: 63 -} + end: 70, + filePath: 'package.json', + hash: 'dc79c984a36b2f8a29007633bde4daf3', + id: '63-70', + locked: false, + lockedTo: null, + modifiedAt: 1714829527993, + oldStart: 63, + start: 63 +}; export const file0 = { - binary: false, - conflicted: false, - hunks: [fileHunk], - id: "package.json", - large: false, - modifiedAt: 1714829589111, - path: "package.json", -} + binary: false, + conflicted: false, + hunks: [fileHunk], + id: 'package.json', + large: false, + modifiedAt: 1714829589111, + path: 'package.json' +}; export const virtualBranch = { - active: true, - baseCurrent: true, - commits: [], - conflicted: false, - files: [file0], - head: "90c225edcc74b31718a9cd8963c1bc89c17d8864", - id: "29cdc7a7-3462-4c14-a037-0a6cdad68da3", - name: "Virtual branch", - notes: "", - order: 0, - ownership: "package.json:63-70-dc79c984a36b2f8a29007633bde4daf3-1714829528116,23-58-fbf18cec4afef8aafbbc2dddef3e3391-1714829528116,79-85-c4d0a57fca736c384cde2a68009ffcb3-1714829503193", - requiresForce: false, - updatedAt: 1714829503190, - upstream: null, - upstreamName: null, -} + active: true, + baseCurrent: true, + commits: [], + conflicted: false, + files: [file0], + head: '90c225edcc74b31718a9cd8963c1bc89c17d8864', + id: '29cdc7a7-3462-4c14-a037-0a6cdad68da3', + name: 'Virtual branch', + notes: '', + order: 0, + ownership: + 'package.json:63-70-dc79c984a36b2f8a29007633bde4daf3-1714829528116,23-58-fbf18cec4afef8aafbbc2dddef3e3391-1714829528116,79-85-c4d0a57fca736c384cde2a68009ffcb3-1714829503193', + requiresForce: false, + updatedAt: 1714829503190, + upstream: null, + upstreamName: null +}; export const virtualBranches = { - branches: [virtualBranch], - skippedFiles: [] -} + branches: [virtualBranch], + skippedFiles: [] +}; diff --git a/app/src/lib/testing/index.ts b/app/src/lib/testing/index.ts index ebc239ebd..764b7852f 100644 --- a/app/src/lib/testing/index.ts +++ b/app/src/lib/testing/index.ts @@ -1,59 +1,59 @@ -import { baseBranch, project, remoteBranchData, user, virtualBranches } from "./fixtures" -import { mockIPC } from "@tauri-apps/api/mocks"; +import { baseBranch, project, remoteBranchData, user, virtualBranches } from './fixtures'; +import { mockIPC } from '@tauri-apps/api/mocks'; import { mockWindows } from '@tauri-apps/api/mocks'; export function mockTauri() { - mockWindows('main'); - mockIPC((cmd, args) => { - console.log(`%c${cmd}`, 'background: #222; color: #4db2ad', args) + mockWindows('main'); + mockIPC((cmd, args) => { + console.log(`%c${cmd}`, 'background: #222; color: #4db2ad', args); - // @ts-expect-error 'message' is dynamic - if (cmd === "tauri" && args.message?.cmd === "openDialog") { - return "/Users/user/project" - } + // @ts-expect-error 'message' is dynamic + if (cmd === 'tauri' && args.message?.cmd === 'openDialog') { + return '/Users/user/project'; + } - if (cmd === "list_projects") { - return [project] - } + if (cmd === 'list_projects') { + return [project]; + } - if (cmd === "get_project" && args.id === "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295") { - return project - } + if (cmd === 'get_project' && args.id === 'ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295') { + return project; + } - if (cmd === "git_head") { - return "refs/heads/gitbutler/integration" - } + if (cmd === 'git_head') { + return 'refs/heads/gitbutler/integration'; + } - if (cmd === "menu_item_set_enabled") { - return null - } + if (cmd === 'menu_item_set_enabled') { + return null; + } - if (cmd === "fetch_from_target") { - return true - } + if (cmd === 'fetch_from_target') { + return true; + } - if (cmd === "get_base_branch_data") { - return baseBranch - } + if (cmd === 'get_base_branch_data') { + return baseBranch; + } - if (cmd === "list_virtual_branches") { - return virtualBranches - } + if (cmd === 'list_virtual_branches') { + return virtualBranches; + } - if (cmd === "list_remote_branches") { - return [] - } + if (cmd === 'list_remote_branches') { + return []; + } - if (cmd === "get_remote_branch_data") { - return remoteBranchData - } + if (cmd === 'get_remote_branch_data') { + return remoteBranchData; + } - if (cmd === "get_remote_branchs") { - return ["refs/heads/abc123"] - } + if (cmd === 'get_remote_branchs') { + return ['refs/heads/abc123']; + } - if (cmd === "get_user") { - return user - } - }); + if (cmd === 'get_user') { + return user; + } + }); } diff --git a/app/src/routes/+layout.ts b/app/src/routes/+layout.ts index eb9108911..3839e4e56 100644 --- a/app/src/routes/+layout.ts +++ b/app/src/routes/+layout.ts @@ -1,6 +1,6 @@ import lscache from 'lscache'; import { BehaviorSubject, config } from 'rxjs'; -import { env } from "$env/dynamic/public"; +import { env } from '$env/dynamic/public'; import { AIService } from '$lib/ai/service'; import { initAnalyticsIfEnabled } from '$lib/analytics/analytics'; import { AuthService } from '$lib/backend/auth'; @@ -24,46 +24,46 @@ export const prerender = false; export const csr = true; export async function load() { - // Mock Tauri API during E2E tests - if (env.PUBLIC_TESTING) { - mockTauri() - } - initAnalyticsIfEnabled(); + // Mock Tauri API during E2E tests + if (env.PUBLIC_TESTING) { + mockTauri(); + } + initAnalyticsIfEnabled(); - // TODO: Find a workaround to avoid this dynamic import - // https://github.com/sveltejs/kit/issues/905 - const defaultPath = await (await import('@tauri-apps/api/path')).homeDir(); + // TODO: Find a workaround to avoid this dynamic import + // https://github.com/sveltejs/kit/issues/905 + const defaultPath = await (await import('@tauri-apps/api/path')).homeDir(); - const httpClient = new HttpClient(); - const authService = new AuthService(); - const projectService = new ProjectService(defaultPath, httpClient); - const updaterService = new UpdaterService(); - const promptService = new PromptService(); - const userService = new UserService(httpClient); + const httpClient = new HttpClient(); + const authService = new AuthService(); + const projectService = new ProjectService(defaultPath, httpClient); + const updaterService = new UpdaterService(); + const promptService = new PromptService(); + const userService = new UserService(httpClient); - // We're declaring a remoteUrl$ observable here that is written to by `BaseBranchService`. This - // is a bit awkard, but `GitHubService` needs to be available at the root scoped layout.ts, such - // that we can perform actions related to GitHub that do not depend on repo information. - // We should evaluate whether or not to split this service into two separate services. That - // way we would not need `remoteUrl$` for the non-repo service, and therefore the other one - // could easily get an observable of the remote url from `BaseBranchService`. - const remoteUrl$ = new BehaviorSubject(undefined); - const githubService = new GitHubService(userService.accessToken$, remoteUrl$); + // We're declaring a remoteUrl$ observable here that is written to by `BaseBranchService`. This + // is a bit awkard, but `GitHubService` needs to be available at the root scoped layout.ts, such + // that we can perform actions related to GitHub that do not depend on repo information. + // We should evaluate whether or not to split this service into two separate services. That + // way we would not need `remoteUrl$` for the non-repo service, and therefore the other one + // could easily get an observable of the remote url from `BaseBranchService`. + const remoteUrl$ = new BehaviorSubject(undefined); + const githubService = new GitHubService(userService.accessToken$, remoteUrl$); - const gitConfig = new GitConfigService(); - const aiService = new AIService(gitConfig, httpClient); + const gitConfig = new GitConfigService(); + const aiService = new AIService(gitConfig, httpClient); - return { - authService, - cloud: httpClient, - githubService, - projectService, - updaterService, - promptService, - userService, - // These observables are provided for convenience - remoteUrl$, - gitConfig, - aiService - }; + return { + authService, + cloud: httpClient, + githubService, + projectService, + updaterService, + promptService, + userService, + // These observables are provided for convenience + remoteUrl$, + gitConfig, + aiService + }; } diff --git a/app/vite.config.ts b/app/vite.config.ts index 4b8add347..d135e7c11 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -3,52 +3,52 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vitest/config'; export default defineConfig({ - plugins: [ - sentrySvelteKit({ - autoInstrument: false, - sourceMapsUploadOptions: { - dryRun: process.env.SENTRY_RELEASE === undefined, - org: 'gitbutler', - project: 'app-js', - authToken: process.env.SENTRY_AUTH_TOKEN, - include: ['build'], - cleanArtifacts: true, - setCommits: { - auto: true, - ignoreMissing: true, - ignoreEmpty: true - }, - telemetry: false, - uploadSourceMaps: process.env.SENTRY_RELEASE !== undefined - } - }), - sveltekit() - ], + plugins: [ + sentrySvelteKit({ + autoInstrument: false, + sourceMapsUploadOptions: { + dryRun: process.env.SENTRY_RELEASE === undefined, + org: 'gitbutler', + project: 'app-js', + authToken: process.env.SENTRY_AUTH_TOKEN, + include: ['build'], + cleanArtifacts: true, + setCommits: { + auto: true, + ignoreMissing: true, + ignoreEmpty: true + }, + telemetry: false, + uploadSourceMaps: process.env.SENTRY_RELEASE !== undefined + } + }), + sveltekit() + ], - // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` - // prevent vite from obscuring rust errors - clearScreen: false, - // tauri expects a fixed port, fail if that port is not available - server: { - port: 1420, - strictPort: true - }, - // to make use of `TAURI_DEBUG` and other env variables - // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand - envPrefix: ['VITE_', 'TAURI_'], - build: { - // Tauri supports es2021 - target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13', - // minify production builds - minify: !process.env.TAURI_DEBUG ? 'esbuild' : false, - // ship sourcemaps for better sentry error reports - sourcemap: 'inline' - }, - test: { - deps: { - inline: ['sorcery'] - }, - includeSource: ['src/**/*.{js,ts}'], - exclude: ['**/e2e/playwright/**/*'] - } + // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` + // prevent vite from obscuring rust errors + clearScreen: false, + // tauri expects a fixed port, fail if that port is not available + server: { + port: 1420, + strictPort: true + }, + // to make use of `TAURI_DEBUG` and other env variables + // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand + envPrefix: ['VITE_', 'TAURI_'], + build: { + // Tauri supports es2021 + target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13', + // minify production builds + minify: !process.env.TAURI_DEBUG ? 'esbuild' : false, + // ship sourcemaps for better sentry error reports + sourcemap: 'inline' + }, + test: { + deps: { + inline: ['sorcery'] + }, + includeSource: ['src/**/*.{js,ts}'], + exclude: ['**/e2e/playwright/**/*'] + } });