-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test-utils): add webx-launch command (#10)
- Loading branch information
Showing
7 changed files
with
72 additions
and
4 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,5 @@ | ||
--- | ||
"@webx-kit/test-utils": patch | ||
--- | ||
|
||
feat(test-utils): add webx-launch command |
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,8 @@ | ||
{ | ||
"extends": ["../tsconfig.json"], | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "ES2020", | ||
"noEmit": true | ||
} | ||
} |
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,47 @@ | ||
#!/usr/bin/env node | ||
|
||
// @ts-check | ||
/// <reference types="@webx-kit/chrome-types" /> | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { chalk, fs, findMonorepoRoot } from '@modern-js/utils'; | ||
import commander from '@modern-js/utils/commander'; | ||
import { chromium } from '@playwright/test'; | ||
|
||
commander.program.option('--path <path>', 'extension path', 'dist'); | ||
|
||
const opts = commander.program.parse(process.argv).opts(); | ||
|
||
const extensionPath = path.resolve(opts.path); | ||
if (!fs.existsSync(extensionPath)) throw new Error(`\`${extensionPath}\` does not exist`); | ||
if (!fs.statSync(extensionPath).isDirectory()) throw new Error(`\`${extensionPath}\` is not a directory`); | ||
|
||
const dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
const monorepoRoot = findMonorepoRoot(dirname); | ||
const userDataDir = path.resolve( | ||
monorepoRoot || path.resolve(dirname, '..'), | ||
'node_modules/.cache/webx-browser-user-dir' | ||
); | ||
|
||
// it must be "persisted", otherwise the browser will enable incognito mode | ||
chromium | ||
.launchPersistentContext(userDataDir, { | ||
headless: false, | ||
colorScheme: 'no-preference', | ||
viewport: null, | ||
ignoreDefaultArgs: ['--disable-extensions', '--enable-automation'], | ||
args: ['--hide-crash-restore-bubble', `--load-extension=${extensionPath}`], | ||
}) | ||
.then(async (context) => { | ||
console.log(chalk.green`Start successfully`); | ||
|
||
const outdatedPages = context.pages(); | ||
const page = await context.newPage(); | ||
await Promise.all(outdatedPages.map((page) => page.close())); | ||
await page.goto(`chrome://extensions/`); | ||
|
||
await page.evaluate(() => chrome.developerPrivate.updateProfileConfiguration({ inDeveloperMode: true })); | ||
}) | ||
.catch((err) => { | ||
console.log(chalk.red`Start failed`, err); | ||
}); |
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 |
---|---|---|
|
@@ -3,5 +3,7 @@ | |
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
} | ||
"noEmit": false | ||
}, | ||
"include": ["./src"] | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.