• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

electron / fiddle / 16349153970

17 Jul 2025 03:21PM UTC coverage: 80.235% (-7.8%) from 87.992%
16349153970

push

github

web-flow
test: switch to Vitest (#1718)

* test: switch to Vitest

* chore: update code comment

Co-authored-by: Kevin Cui <158blackhole@gmail.com>

* test: make use of vi.useFakeTimers to improve test

---------

Co-authored-by: Kevin Cui <158blackhole@gmail.com>

1520 of 1645 branches covered (92.4%)

Branch coverage included in aggregate %.

15 of 16 new or added lines in 12 files covered. (93.75%)

504 existing lines in 45 files now uncovered.

8807 of 11226 relevant lines covered (78.45%)

32.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.82
/src/main/dialogs.ts
1
import * as path from 'node:path';
1✔
2

3
import { Installer } from '@electron/fiddle-core';
1✔
4
import { BrowserWindow, dialog } from 'electron';
1✔
5
import fs from 'fs-extra';
1✔
6

7
import { ipcMainManager } from './ipc';
1✔
8
import { SelectedLocalVersion } from '../interfaces';
9
import { IpcEvents } from '../ipc-events';
1✔
10

11
/**
12
 * Build a default name for a local Electron version
13
 * from its dirname.
14
 * @returns human-readable local build name
15
 */
UNCOV
16
function makeLocalName(folderPath: string): string {
×
17
  // take a dirname like '/home/username/electron/gn/main/src/out/testing'
18
  // and return something like 'gn/main - testing'
19
  const tokens = folderPath.split(path.sep);
×
20
  const buildType = tokens.pop(); // e.g. 'testing' or 'release'
×
21
  const leader = tokens
×
22
    // remove 'src/out/' -- they are in every local build, so make poor names
UNCOV
23
    .slice(0, -2)
×
UNCOV
24
    .join(path.sep)
×
25
    // extract about enough for the end result to be about 20 chars
UNCOV
26
    .slice(-20 + buildType!.length)
×
27
    // remove any fragment in case the prev slice cut in the middle of a name
UNCOV
28
    .split(path.sep)
×
UNCOV
29
    .slice(1)
×
UNCOV
30
    .join(path.sep);
×
31
  return `${leader} - ${buildType}`;
×
UNCOV
32
}
×
33

34
/**
35
 * Verifies if the local electron path is valid
36
 */
37
function isValidElectronPath(folderPath: string): boolean {
1✔
38
  const execPath = Installer.getExecPath(folderPath);
1✔
39
  return fs.existsSync(execPath);
1✔
40
}
1✔
41

42
/**
43
 * Listens to IPC events related to dialogs and message boxes
44
 */
45
export function setupDialogs() {
1✔
46
  ipcMainManager.on(IpcEvents.SHOW_WARNING_DIALOG, (event, args) => {
7✔
47
    showWarningDialog(BrowserWindow.fromWebContents(event.sender)!, args);
2✔
48
  });
7✔
49

50
  ipcMainManager.handle(
7✔
51
    IpcEvents.LOAD_LOCAL_VERSION_FOLDER,
7✔
52
    async (event): Promise<SelectedLocalVersion | undefined> => {
7✔
53
      const folderPath = await showOpenDialog(
4✔
54
        BrowserWindow.fromWebContents(event.sender)!,
4✔
55
      );
4✔
56

57
      if (folderPath) {
4✔
58
        const isValidElectron = isValidElectronPath(folderPath);
1✔
59
        const localName = isValidElectron
1!
UNCOV
60
          ? makeLocalName(folderPath)
×
61
          : undefined;
1✔
62

63
        return { folderPath, isValidElectron, localName };
1✔
64
      }
1✔
65

66
      return undefined;
3✔
67
    },
4✔
68
  );
7✔
69
}
7✔
70

71
/**
72
 * Shows a warning dialog
73
 */
74
function showWarningDialog(
2✔
75
  window: BrowserWindow,
2✔
76
  args: Electron.MessageBoxOptions,
2✔
77
) {
2✔
78
  dialog.showMessageBox(window, {
2✔
79
    type: 'warning',
2✔
80
    ...args,
2✔
81
  });
2✔
82
}
2✔
83

84
async function showOpenDialog(window: BrowserWindow) {
4✔
85
  const { filePaths } = await dialog.showOpenDialog(window, {
4✔
86
    title: 'Open Folder',
4✔
87
    properties: ['openDirectory'],
4✔
88
  });
4✔
89

90
  if (!filePaths || filePaths.length < 1) {
4✔
91
    return;
3✔
92
  }
3✔
93

94
  return filePaths[0];
1✔
95
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc