-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Disable opening browser automatically during dev mode (#136)
- Loading branch information
Showing
11 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { createExtensionRunner } from '..'; | ||
import { fakeInternalConfig } from '../../../testing/fake-objects'; | ||
import { mock } from 'vitest-mock-extended'; | ||
import { createSafariRunner } from '../safari'; | ||
import { ExtensionRunner } from '../extension-runner'; | ||
import { createWslRunner } from '../wsl'; | ||
import { createManualRunner } from '../manual'; | ||
import { isWsl } from '../../utils/wsl'; | ||
import { createWebExtRunner } from '../web-ext'; | ||
|
||
vi.mock('../../utils/wsl'); | ||
const isWslMock = vi.mocked(isWsl); | ||
|
||
vi.mock('../safari'); | ||
const createSafariRunnerMock = vi.mocked(createSafariRunner); | ||
|
||
vi.mock('../wsl'); | ||
const createWslRunnerMock = vi.mocked(createWslRunner); | ||
|
||
vi.mock('../manual'); | ||
const createManualRunnerMock = vi.mocked(createManualRunner); | ||
|
||
vi.mock('../web-ext'); | ||
const createWebExtRunnerMock = vi.mocked(createWebExtRunner); | ||
|
||
describe('createExtensionRunner', () => { | ||
it('should return a Safari runner when browser is "safari"', async () => { | ||
const config = fakeInternalConfig({ | ||
browser: 'safari', | ||
}); | ||
const safariRunner = mock<ExtensionRunner>(); | ||
createSafariRunnerMock.mockReturnValue(safariRunner); | ||
|
||
await expect(createExtensionRunner(config)).resolves.toBe(safariRunner); | ||
}); | ||
|
||
it('should return a WSL runner when `is-wsl` is true', async () => { | ||
isWslMock.mockResolvedValueOnce(true); | ||
const config = fakeInternalConfig({ | ||
browser: 'chrome', | ||
}); | ||
const wslRunner = mock<ExtensionRunner>(); | ||
createWslRunnerMock.mockReturnValue(wslRunner); | ||
|
||
await expect(createExtensionRunner(config)).resolves.toBe(wslRunner); | ||
}); | ||
|
||
it('should return a manual runner when `runner.disabled` is true', async () => { | ||
isWslMock.mockResolvedValueOnce(false); | ||
const config = fakeInternalConfig({ | ||
browser: 'chrome', | ||
runnerConfig: { | ||
config: { | ||
disabled: true, | ||
}, | ||
}, | ||
}); | ||
const manualRunner = mock<ExtensionRunner>(); | ||
createManualRunnerMock.mockReturnValue(manualRunner); | ||
|
||
await expect(createExtensionRunner(config)).resolves.toBe(manualRunner); | ||
}); | ||
|
||
it('should return a web-ext runner otherwise', async () => { | ||
const config = fakeInternalConfig({ | ||
browser: 'chrome', | ||
runnerConfig: { | ||
config: { | ||
disabled: undefined, | ||
}, | ||
}, | ||
}); | ||
const manualRunner = mock<ExtensionRunner>(); | ||
createWebExtRunnerMock.mockReturnValue(manualRunner); | ||
|
||
await expect(createExtensionRunner(config)).resolves.toBe(manualRunner); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ExtensionRunner } from './extension-runner'; | ||
import { relative } from 'node:path'; | ||
|
||
/** | ||
* The manual runner tells the user to load the unpacked extension manually. | ||
*/ | ||
export function createManualRunner(): ExtensionRunner { | ||
return { | ||
async openBrowser(config) { | ||
config.logger.info( | ||
`Load "${relative( | ||
process.cwd(), | ||
config.outDir, | ||
)}" as an unpacked extension manually`, | ||
); | ||
}, | ||
async closeBrowser() { | ||
// noop | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Returns true when running on WSL or WSL2. | ||
*/ | ||
export async function isWsl(): Promise<boolean> { | ||
const { default: isWsl } = await import('is-wsl'); // ESM only, requires dynamic import | ||
return isWsl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
.output | ||
stats.html | ||
.wxt | ||
web-ext.config.ts | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
.output | ||
stats.html | ||
.wxt | ||
web-ext.config.ts | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
.output | ||
stats.html | ||
.wxt | ||
web-ext.config.ts | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
.output | ||
stats.html | ||
.wxt | ||
web-ext.config.ts | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
.output | ||
stats.html | ||
.wxt | ||
web-ext.config.ts | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|