Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/runner/src/browser-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ export const KNOWN_BROWSER_PATHS: Record<
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chrome.app/Contents/MacOS/Google Chrome',
],
linux: [],
linux: [
// Debian/Ubuntu official Google Chrome package
// Prefer the real binary over wrapper scripts to keep extra file descriptors open.
'/opt/google/chrome/chrome',
'/usr/bin/google-chrome',
'/usr/bin/google-chrome-stable',
],
windows: ['C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'],
},
'chrome-beta': {
Expand Down
1 change: 1 addition & 0 deletions packages/runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './run';
export * from './options';
export * from './install';
export * from './browser-paths';
1 change: 1 addition & 0 deletions packages/wxt-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "buildc --deps-only -- wxt",
"dev:firefox": "buildc --deps-only -- wxt -b firefox --mv2",
"build": "buildc --deps-only -- wxt build",
"build:all": "buildc --deps-only -- pnpm run --reporter-hide-prefix /^build:all:.*/",
"build:all:chrome-mv3": "wxt build",
Expand Down
1 change: 1 addition & 0 deletions packages/wxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@webext-core/isolated-element": "^1.1.2",
"@webext-core/match-patterns": "^1.0.3",
"@wxt-dev/browser": "workspace:^",
"@wxt-dev/runner": "workspace:^",
"@wxt-dev/storage": "workspace:^1.0.0",
"async-mutex": "^0.5.0",
"c12": "^3.3.2",
Expand Down
69 changes: 65 additions & 4 deletions packages/wxt/src/core/runners/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { describe, expect, it, vi } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { createExtensionRunner } from '..';
import { setFakeWxt } from '../../utils/testing/fake-objects';
import { mock } from 'vitest-mock-extended';
import { createSafariRunner } from '../safari';
import { createWslRunner } from '../wsl';
import { createManualRunner } from '../manual';
import { isWsl } from '../../utils/wsl';
import { hasGuiDisplay, isWsl } from '../../utils/wsl';
import { createWebExtRunner } from '../web-ext';
import { createWxtRunner } from '../wxt-runner';
import { ExtensionRunner } from '../../../types';

vi.mock('../../utils/wsl');
const isWslMock = vi.mocked(isWsl);
const hasGuiDisplayMock = vi.mocked(hasGuiDisplay);

vi.mock('../safari');
const createSafariRunnerMock = vi.mocked(createSafariRunner);
Expand All @@ -24,7 +26,22 @@ const createManualRunnerMock = vi.mocked(createManualRunner);
vi.mock('../web-ext');
const createWebExtRunnerMock = vi.mocked(createWebExtRunner);

vi.mock('../wxt-runner');
const createWxtRunnerMock = vi.mocked(createWxtRunner);

describe('createExtensionRunner', () => {
const originalDisplay = process.env.DISPLAY;
const originalWaylandDisplay = process.env.WAYLAND_DISPLAY;

beforeEach(() => {
vi.clearAllMocks();
});

afterEach(() => {
process.env.DISPLAY = originalDisplay;
process.env.WAYLAND_DISPLAY = originalWaylandDisplay;
});

it('should return a Safari runner when browser is "safari"', async () => {
setFakeWxt({
config: {
Expand All @@ -37,8 +54,9 @@ describe('createExtensionRunner', () => {
await expect(createExtensionRunner()).resolves.toBe(safariRunner);
});

it('should return a WSL runner when `is-wsl` is true', async () => {
it('should return a WSL runner when `is-wsl` is true and no GUI is available', async () => {
isWslMock.mockResolvedValueOnce(true);
hasGuiDisplayMock.mockReturnValueOnce(false);
setFakeWxt({
config: {
browser: 'chrome',
Expand All @@ -50,8 +68,50 @@ describe('createExtensionRunner', () => {
await expect(createExtensionRunner()).resolves.toBe(wslRunner);
});

it('should return an internal runner when `is-wsl` is true and DISPLAY is set for Chrome/Chromium', async () => {
isWslMock.mockResolvedValueOnce(true);
hasGuiDisplayMock.mockReturnValueOnce(true);
setFakeWxt({
config: {
browser: 'chrome',
},
});
const internalRunner = mock<ExtensionRunner>();
createWxtRunnerMock.mockReturnValue(internalRunner);

await expect(createExtensionRunner()).resolves.toBe(internalRunner);
});

it('should return an internal runner when `is-wsl` is true and WAYLAND_DISPLAY is set for Chrome/Chromium', async () => {
isWslMock.mockResolvedValueOnce(true);
hasGuiDisplayMock.mockReturnValueOnce(true);
setFakeWxt({
config: {
browser: 'chrome',
},
});
const internalRunner = mock<ExtensionRunner>();
createWxtRunnerMock.mockReturnValue(internalRunner);

await expect(createExtensionRunner()).resolves.toBe(internalRunner);
});

it('should return an internal runner when `is-wsl` is true and GUI is available for Firefox', async () => {
isWslMock.mockResolvedValueOnce(true);
hasGuiDisplayMock.mockReturnValueOnce(true);
setFakeWxt({
config: {
browser: 'firefox',
},
});
const internalRunner = mock<ExtensionRunner>();
createWxtRunnerMock.mockReturnValue(internalRunner);

await expect(createExtensionRunner()).resolves.toBe(internalRunner);
});

it('should return a manual runner when `runner.disabled` is true', async () => {
isWslMock.mockResolvedValueOnce(false);
isWslMock.mockResolvedValueOnce(true);
setFakeWxt({
config: {
browser: 'chrome',
Expand All @@ -69,6 +129,7 @@ describe('createExtensionRunner', () => {
});

it('should return a web-ext runner otherwise', async () => {
isWslMock.mockResolvedValueOnce(false);
setFakeWxt({
config: {
browser: 'chrome',
Expand Down
Loading