chore: prettier

This commit is contained in:
ndom91 2024-05-06 13:06:13 +02:00
parent 80f517b13b
commit a6968438a2
No known key found for this signature in database
8 changed files with 284 additions and 285 deletions

View File

@ -1,15 +1,15 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test('has empty title', async ({ page }) => { 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 }) => { 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');
}) });

View File

@ -4,22 +4,22 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration. * See https://playwright.dev/docs/test-configuration.
*/ */
export default defineConfig({ export default defineConfig({
testDir: './e2e/playwright', testDir: './e2e/playwright',
testMatch: /(.+\.)?(test|spec)\.[jt]s/, testMatch: /(.+\.)?(test|spec)\.[jt]s/,
projects: [ projects: [
{ {
name: 'Google Chrome', name: 'Google Chrome',
use: { ...devices['Desktop Chrome'] } use: { ...devices['Desktop Chrome'] }
} }
], ],
expect: { expect: {
timeout: 20 * 1000, timeout: 20 * 1000
}, },
use: { use: {
trace: 'retain-on-failure', trace: 'retain-on-failure'
}, },
webServer: { webServer: {
command: 'pnpm test:e2e:run', command: 'pnpm test:e2e:run',
url: 'http://localhost:1420', url: 'http://localhost:1420'
} }
}); });

View File

@ -1,16 +1,14 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head>
<script src="http://localhost:9222/scripts/launcher.js" data-origin="debugger"></script>
<head> <meta charset="utf-8" />
<script src="http://localhost:9222/scripts/launcher.js" data-origin="debugger"></script> <meta name="viewport" content="width=device-width" />
%sveltekit.head%
<meta charset="utf-8" /> </head>
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body class="text-base">
<div style="display: contents">%sveltekit.body%</div>
</body>
<body class="text-base">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html> </html>

View File

@ -3,9 +3,9 @@ import { error as logErrorToFile } from 'tauri-plugin-log-api';
import type { NavigationEvent } from '@sveltejs/kit'; import type { NavigationEvent } from '@sveltejs/kit';
function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) { function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) {
console.error(error.message + '\n' + error.stack); console.error(error.message + '\n' + error.stack);
logErrorToFile(error.toString()); logErrorToFile(error.toString());
console.error('An error occurred on the client side:', error, event); console.error('An error occurred on the client side:', error, event);
} }
export const handleError = handleErrorWithSentry(myErrorHandler); export const handleError = handleErrorWithSentry(myErrorHandler);
@ -19,7 +19,7 @@ export const handleError = handleErrorWithSentry(myErrorHandler);
*/ */
const originalUnhandledHandler = window.onunhandledrejection; const originalUnhandledHandler = window.onunhandledrejection;
window.onunhandledrejection = (event: PromiseRejectionEvent) => { window.onunhandledrejection = (event: PromiseRejectionEvent) => {
logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL); logErrorToFile('Unhandled exception: ' + event?.reason + ' ' + event?.reason?.sourceURL);
console.log('Unhandled exception', event.reason); console.log('Unhandled exception', event.reason);
originalUnhandledHandler?.bind(window)(event); originalUnhandledHandler?.bind(window)(event);
}; };

View File

@ -1,103 +1,103 @@
import type { User } from '$lib/stores/user' import type { User } from '$lib/stores/user';
export type Constructor<T = any> = new (...args: any[]) => T; export type Constructor<T = any> = new (...args: any[]) => T;
export type Class<T = any> = InstanceType<Constructor<T>>; export type Class<T = any> = InstanceType<Constructor<T>>;
export const project = { export const project = {
api: null, api: null,
description: null, description: null,
gitbutler_code_push_state: null, gitbutler_code_push_state: null,
gitbutler_data_last_fetch: null, gitbutler_data_last_fetch: null,
id: "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295", id: 'ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295',
ok_with_force_push: true, ok_with_force_push: true,
omit_certificate_check: null, omit_certificate_check: null,
path: "/opt/ndomino/home2021", path: '/opt/ndomino/home2021',
preferred_key: "systemExecutable", preferred_key: 'systemExecutable',
project_data_last_fetch: Object, project_data_last_fetch: Object,
fetched: { fetched: {
timestamp: { timestamp: {
nanos_since_epoch: 410569736, nanos_since_epoch: 410569736,
secs_since_epoch: 1714924416 secs_since_epoch: 1714924416
} }
}, },
title: "home2021" title: 'home2021'
} };
export const author = { export const author = {
name: 'John Snow', name: 'John Snow',
email: 'user@company.com', email: 'user@company.com',
gravatarUrl: 'https://gravatar.com/avatar/abc123' gravatarUrl: 'https://gravatar.com/avatar/abc123'
} };
export const remoteCommit0 = { export const remoteCommit0 = {
id: 'fe30876278739f7182effd27e9d9debde648b4de', id: 'fe30876278739f7182effd27e9d9debde648b4de',
author, author,
description: 'fix: updated files', description: 'fix: updated files',
createdAt: 1714902366, createdAt: 1714902366
} };
export const remoteCommit1 = { export const remoteCommit1 = {
id: 'fe30876278739f7182effd27e9d9debde648b4dd', id: 'fe30876278739f7182effd27e9d9debde648b4dd',
author, author,
description: 'fix: updated files', description: 'fix: updated files',
createdAt: 1714902366, createdAt: 1714902366
} };
export const remoteBranch0 = { export const remoteBranch0 = {
sha: '90c225edcc74b31718a9cd8963c1bc89c17d8863', sha: '90c225edcc74b31718a9cd8963c1bc89c17d8863',
name: '', name: '',
upstream: '', upstream: '',
lastCommitTimestampMs: 1714902366140, lastCommitTimestampMs: 1714902366140,
lastCommitAuthor: 'John Snow' lastCommitAuthor: 'John Snow'
} };
export const baseBranch = { export const baseBranch = {
branchName: 'origin/gitbutler/integration', branchName: 'origin/gitbutler/integration',
remoteName: 'origin', remoteName: 'origin',
remoteUrl: 'ssh://github.com/user/project.git', remoteUrl: 'ssh://github.com/user/project.git',
baseSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', baseSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
currentSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', currentSha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
behind: 0, behind: 0,
upstreamCommits: [], upstreamCommits: [],
recentCommits: [remoteCommit0], recentCommits: [remoteCommit0],
lastFetchedMs: 1714843209991, lastFetchedMs: 1714843209991
} };
export const user: User = { export const user: User = {
access_token: "c5da8ec0-2a2e-4f1c-a796-686c5606e566", access_token: 'c5da8ec0-2a2e-4f1c-a796-686c5606e566',
created_at: "2024-05-04T13:27:30Z", created_at: '2024-05-04T13:27:30Z',
email: "yo@ndo.dev", email: 'yo@ndo.dev',
family_name: undefined, family_name: undefined,
github_access_token: undefined, github_access_token: undefined,
github_username: undefined, github_username: undefined,
given_name: undefined, given_name: undefined,
id: 31, id: 31,
locale: "en_US", locale: 'en_US',
name: "Nico", name: 'Nico',
picture: "https://source.boringavatar.com/marble/120", picture: 'https://source.boringavatar.com/marble/120',
role: undefined, role: undefined,
updated_at: "2024-05-05T15:38:02Z", updated_at: '2024-05-05T15:38:02Z',
supporter: false supporter: false
} };
export const remoteBranchData = { export const remoteBranchData = {
sha: '90c225edcc74b31718a9cd8963c1bc89c17d8864', sha: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
name: 'test', name: 'test',
upstream: 'abc123', upstream: 'abc123',
authors: [author], authors: [author],
displayName: 'test', displayName: 'test',
lastCommitTs: new Date(), lastCommitTs: new Date(),
firstCommitAt: new Date(), firstCommitAt: new Date(),
ahead: 0, ahead: 0,
behind: 0, behind: 0,
commits: [remoteCommit0], commits: [remoteCommit0],
isMergeable: true, isMergeable: true
} };
export const fileHunk = { export const fileHunk = {
binary: false, binary: false,
changeType: "modified", changeType: 'modified',
diff: ` diff: `
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
"simple-git-hooks": "^2.11.1", "simple-git-hooks": "^2.11.1",
"tailwindcss": "^3.4.3", "tailwindcss": "^3.4.3",
@ -108,46 +108,47 @@ export const fileHunk = {
"commitlint": { "commitlint": {
"extends": [ "extends": [
`, `,
end: 70, end: 70,
filePath: "package.json", filePath: 'package.json',
hash: "dc79c984a36b2f8a29007633bde4daf3", hash: 'dc79c984a36b2f8a29007633bde4daf3',
id: "63-70", id: '63-70',
locked: false, locked: false,
lockedTo: null, lockedTo: null,
modifiedAt: 1714829527993, modifiedAt: 1714829527993,
oldStart: 63, oldStart: 63,
start: 63 start: 63
} };
export const file0 = { export const file0 = {
binary: false, binary: false,
conflicted: false, conflicted: false,
hunks: [fileHunk], hunks: [fileHunk],
id: "package.json", id: 'package.json',
large: false, large: false,
modifiedAt: 1714829589111, modifiedAt: 1714829589111,
path: "package.json", path: 'package.json'
} };
export const virtualBranch = { export const virtualBranch = {
active: true, active: true,
baseCurrent: true, baseCurrent: true,
commits: [], commits: [],
conflicted: false, conflicted: false,
files: [file0], files: [file0],
head: "90c225edcc74b31718a9cd8963c1bc89c17d8864", head: '90c225edcc74b31718a9cd8963c1bc89c17d8864',
id: "29cdc7a7-3462-4c14-a037-0a6cdad68da3", id: '29cdc7a7-3462-4c14-a037-0a6cdad68da3',
name: "Virtual branch", name: 'Virtual branch',
notes: "", notes: '',
order: 0, order: 0,
ownership: "package.json:63-70-dc79c984a36b2f8a29007633bde4daf3-1714829528116,23-58-fbf18cec4afef8aafbbc2dddef3e3391-1714829528116,79-85-c4d0a57fca736c384cde2a68009ffcb3-1714829503193", ownership:
requiresForce: false, 'package.json:63-70-dc79c984a36b2f8a29007633bde4daf3-1714829528116,23-58-fbf18cec4afef8aafbbc2dddef3e3391-1714829528116,79-85-c4d0a57fca736c384cde2a68009ffcb3-1714829503193',
updatedAt: 1714829503190, requiresForce: false,
upstream: null, updatedAt: 1714829503190,
upstreamName: null, upstream: null,
} upstreamName: null
};
export const virtualBranches = { export const virtualBranches = {
branches: [virtualBranch], branches: [virtualBranch],
skippedFiles: [] skippedFiles: []
} };

View File

@ -1,59 +1,59 @@
import { baseBranch, project, remoteBranchData, user, virtualBranches } from "./fixtures" import { baseBranch, project, remoteBranchData, user, virtualBranches } from './fixtures';
import { mockIPC } from "@tauri-apps/api/mocks"; import { mockIPC } from '@tauri-apps/api/mocks';
import { mockWindows } from '@tauri-apps/api/mocks'; import { mockWindows } from '@tauri-apps/api/mocks';
export function mockTauri() { export function mockTauri() {
mockWindows('main'); mockWindows('main');
mockIPC((cmd, args) => { mockIPC((cmd, args) => {
console.log(`%c${cmd}`, 'background: #222; color: #4db2ad', args) console.log(`%c${cmd}`, 'background: #222; color: #4db2ad', args);
// @ts-expect-error 'message' is dynamic // @ts-expect-error 'message' is dynamic
if (cmd === "tauri" && args.message?.cmd === "openDialog") { if (cmd === 'tauri' && args.message?.cmd === 'openDialog') {
return "/Users/user/project" return '/Users/user/project';
} }
if (cmd === "list_projects") { if (cmd === 'list_projects') {
return [project] return [project];
} }
if (cmd === "get_project" && args.id === "ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295") { if (cmd === 'get_project' && args.id === 'ac44a3bb-8bbb-4af9-b8c9-7950dd9ec295') {
return project return project;
} }
if (cmd === "git_head") { if (cmd === 'git_head') {
return "refs/heads/gitbutler/integration" return 'refs/heads/gitbutler/integration';
} }
if (cmd === "menu_item_set_enabled") { if (cmd === 'menu_item_set_enabled') {
return null return null;
} }
if (cmd === "fetch_from_target") { if (cmd === 'fetch_from_target') {
return true return true;
} }
if (cmd === "get_base_branch_data") { if (cmd === 'get_base_branch_data') {
return baseBranch return baseBranch;
} }
if (cmd === "list_virtual_branches") { if (cmd === 'list_virtual_branches') {
return virtualBranches return virtualBranches;
} }
if (cmd === "list_remote_branches") { if (cmd === 'list_remote_branches') {
return [] return [];
} }
if (cmd === "get_remote_branch_data") { if (cmd === 'get_remote_branch_data') {
return remoteBranchData return remoteBranchData;
} }
if (cmd === "get_remote_branchs") { if (cmd === 'get_remote_branchs') {
return ["refs/heads/abc123"] return ['refs/heads/abc123'];
} }
if (cmd === "get_user") { if (cmd === 'get_user') {
return user return user;
} }
}); });
} }

View File

@ -1,6 +1,6 @@
import lscache from 'lscache'; import lscache from 'lscache';
import { BehaviorSubject, config } from 'rxjs'; import { BehaviorSubject, config } from 'rxjs';
import { env } from "$env/dynamic/public"; import { env } from '$env/dynamic/public';
import { AIService } from '$lib/ai/service'; import { AIService } from '$lib/ai/service';
import { initAnalyticsIfEnabled } from '$lib/analytics/analytics'; import { initAnalyticsIfEnabled } from '$lib/analytics/analytics';
import { AuthService } from '$lib/backend/auth'; import { AuthService } from '$lib/backend/auth';
@ -24,46 +24,46 @@ export const prerender = false;
export const csr = true; export const csr = true;
export async function load() { export async function load() {
// Mock Tauri API during E2E tests // Mock Tauri API during E2E tests
if (env.PUBLIC_TESTING) { if (env.PUBLIC_TESTING) {
mockTauri() mockTauri();
} }
initAnalyticsIfEnabled(); initAnalyticsIfEnabled();
// TODO: Find a workaround to avoid this dynamic import // TODO: Find a workaround to avoid this dynamic import
// https://github.com/sveltejs/kit/issues/905 // https://github.com/sveltejs/kit/issues/905
const defaultPath = await (await import('@tauri-apps/api/path')).homeDir(); const defaultPath = await (await import('@tauri-apps/api/path')).homeDir();
const httpClient = new HttpClient(); const httpClient = new HttpClient();
const authService = new AuthService(); const authService = new AuthService();
const projectService = new ProjectService(defaultPath, httpClient); const projectService = new ProjectService(defaultPath, httpClient);
const updaterService = new UpdaterService(); const updaterService = new UpdaterService();
const promptService = new PromptService(); const promptService = new PromptService();
const userService = new UserService(httpClient); const userService = new UserService(httpClient);
// We're declaring a remoteUrl$ observable here that is written to by `BaseBranchService`. This // 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 // 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. // 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 // 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 // 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`. // could easily get an observable of the remote url from `BaseBranchService`.
const remoteUrl$ = new BehaviorSubject<string | undefined>(undefined); const remoteUrl$ = new BehaviorSubject<string | undefined>(undefined);
const githubService = new GitHubService(userService.accessToken$, remoteUrl$); const githubService = new GitHubService(userService.accessToken$, remoteUrl$);
const gitConfig = new GitConfigService(); const gitConfig = new GitConfigService();
const aiService = new AIService(gitConfig, httpClient); const aiService = new AIService(gitConfig, httpClient);
return { return {
authService, authService,
cloud: httpClient, cloud: httpClient,
githubService, githubService,
projectService, projectService,
updaterService, updaterService,
promptService, promptService,
userService, userService,
// These observables are provided for convenience // These observables are provided for convenience
remoteUrl$, remoteUrl$,
gitConfig, gitConfig,
aiService aiService
}; };
} }

View File

@ -3,52 +3,52 @@ import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
sentrySvelteKit({ sentrySvelteKit({
autoInstrument: false, autoInstrument: false,
sourceMapsUploadOptions: { sourceMapsUploadOptions: {
dryRun: process.env.SENTRY_RELEASE === undefined, dryRun: process.env.SENTRY_RELEASE === undefined,
org: 'gitbutler', org: 'gitbutler',
project: 'app-js', project: 'app-js',
authToken: process.env.SENTRY_AUTH_TOKEN, authToken: process.env.SENTRY_AUTH_TOKEN,
include: ['build'], include: ['build'],
cleanArtifacts: true, cleanArtifacts: true,
setCommits: { setCommits: {
auto: true, auto: true,
ignoreMissing: true, ignoreMissing: true,
ignoreEmpty: true ignoreEmpty: true
}, },
telemetry: false, telemetry: false,
uploadSourceMaps: process.env.SENTRY_RELEASE !== undefined uploadSourceMaps: process.env.SENTRY_RELEASE !== undefined
} }
}), }),
sveltekit() sveltekit()
], ],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build` // Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
// prevent vite from obscuring rust errors // prevent vite from obscuring rust errors
clearScreen: false, clearScreen: false,
// tauri expects a fixed port, fail if that port is not available // tauri expects a fixed port, fail if that port is not available
server: { server: {
port: 1420, port: 1420,
strictPort: true strictPort: true
}, },
// to make use of `TAURI_DEBUG` and other env variables // to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand // https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ['VITE_', 'TAURI_'], envPrefix: ['VITE_', 'TAURI_'],
build: { build: {
// Tauri supports es2021 // Tauri supports es2021
target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13', target: process.env.TAURI_PLATFORM == 'windows' ? 'chrome105' : 'safari13',
// minify production builds // minify production builds
minify: !process.env.TAURI_DEBUG ? 'esbuild' : false, minify: !process.env.TAURI_DEBUG ? 'esbuild' : false,
// ship sourcemaps for better sentry error reports // ship sourcemaps for better sentry error reports
sourcemap: 'inline' sourcemap: 'inline'
}, },
test: { test: {
deps: { deps: {
inline: ['sorcery'] inline: ['sorcery']
}, },
includeSource: ['src/**/*.{js,ts}'], includeSource: ['src/**/*.{js,ts}'],
exclude: ['**/e2e/playwright/**/*'] exclude: ['**/e2e/playwright/**/*']
} }
}); });