Skip to content

Commit

Permalink
chore: run prettier formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Nov 27, 2024
1 parent 93a99f5 commit 2a91f51
Show file tree
Hide file tree
Showing 39 changed files with 161 additions and 154 deletions.
3 changes: 1 addition & 2 deletions build/webpack/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const base = {
// new webpack.EnvironmentPlugin({
// NODE_ENV: 'production',
// }),

],
}

module.exports = base
module.exports = base
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"start:skip-build": "cross-env SHELL_DEBUG=true DEBUG='electron-chrome-extensions*' yarn --cwd ./packages/shell start",
"test": "yarn test:extensions",
"test:extensions": "yarn --cwd ./packages/electron-chrome-extensions test",
"prepare": "husky"
"prepare": "husky",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css}\""
},
"license": "GPL-3.0",
"author": "Samuel Maddock <[email protected]>",
Expand All @@ -41,7 +42,6 @@
"prettier": {
"printWidth": 100,
"singleQuote": true,
"jsonEnable": false,
"semi": false,
"endOfLine": "lf"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-chrome-context-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface ChromeContextMenuOptions {
openLink: (
url: string,
disposition: 'default' | 'foreground-tab' | 'background-tab' | 'new-window',
params: Electron.ContextMenuParams
params: Electron.ContextMenuParams,
) => void

/** Chrome extension menu items. */
Expand Down
77 changes: 39 additions & 38 deletions packages/electron-chrome-extensions/script/spec-runner.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
#!/usr/bin/env node

const childProcess = require('child_process');
const path = require('path');
const unknownFlags = [];
const childProcess = require('child_process')
const path = require('path')
const unknownFlags = []

require('colors');
const pass = '✓'.green;
const fail = '✗'.red;
require('colors')
const pass = '✓'.green
const fail = '✗'.red

const args = require('minimist')(process.argv, {
string: ['target'],
unknown: arg => unknownFlags.push(arg)
});
unknown: (arg) => unknownFlags.push(arg),
})

const unknownArgs = [];
const unknownArgs = []
for (const flag of unknownFlags) {
unknownArgs.push(flag);
const onlyFlag = flag.replace(/^-+/, '');
unknownArgs.push(flag)
const onlyFlag = flag.replace(/^-+/, '')
if (args[onlyFlag]) {
unknownArgs.push(args[onlyFlag]);
unknownArgs.push(args[onlyFlag])
}
}

async function main () {
await runElectronTests();
async function main() {
await runElectronTests()
}

async function runElectronTests () {
const errors = [];
async function runElectronTests() {
const errors = []

const testResultsDir = process.env.ELECTRON_TEST_RESULTS_DIR;
const testResultsDir = process.env.ELECTRON_TEST_RESULTS_DIR

try {
console.info('\nRunning:');
console.info('\nRunning:')
if (testResultsDir) {
process.env.MOCHA_FILE = path.join(testResultsDir, `test-results.xml`);
process.env.MOCHA_FILE = path.join(testResultsDir, `test-results.xml`)
}
await runMainProcessElectronTests();
await runMainProcessElectronTests()
} catch (err) {
errors.push([err]);
errors.push([err])
}

if (errors.length !== 0) {
for (const err of errors) {
console.error('\n\nRunner Failed:', err[0]);
console.error(err[1]);
console.error('\n\nRunner Failed:', err[0])
console.error(err[1])
}
console.log(`${fail} Electron test runners have failed`);
process.exit(1);
console.log(`${fail} Electron test runners have failed`)
process.exit(1)
}
}

async function runMainProcessElectronTests () {
let exe = require('electron');
const runnerArgs = ['spec', ...unknownArgs.slice(2)];
async function runMainProcessElectronTests() {
let exe = require('electron')
const runnerArgs = ['spec', ...unknownArgs.slice(2)]

const { status, signal } = childProcess.spawnSync(exe, runnerArgs, {
cwd: path.resolve(__dirname, '..'),
env: process.env,
stdio: 'inherit'
});
stdio: 'inherit',
})
if (status !== 0) {
if (status) {
const textStatus = process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString();
console.log(`${fail} Electron tests failed with code ${textStatus}.`);
const textStatus =
process.platform === 'win32' ? `0x${status.toString(16)}` : status.toString()
console.log(`${fail} Electron tests failed with code ${textStatus}.`)
} else {
console.log(`${fail} Electron tests failed with kill signal ${signal}.`);
console.log(`${fail} Electron tests failed with kill signal ${signal}.`)
}
process.exit(1);
process.exit(1)
}
console.log(`${pass} Electron main process tests passed.`);
console.log(`${pass} Electron main process tests passed.`)
}

main().catch((error) => {
console.error('An error occurred inside the spec runner:', error);
process.exit(1);
});
console.error('An error occurred inside the spec runner:', error)
process.exit(1)
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('chrome.browserAction', () => {
partition: string,
webContents: WebContents,
extension: Extension,
tabId: number = -1
tabId: number = -1,
) => {
const details = {
eventType: 'click',
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('chrome.browserAction', () => {
const [popup] = await popupPromise
await popup.whenReady()
expect(popup.browserWindow.webContents.getURL()).to.equal(
`chrome-extension://${browser.extension.id}/${popupPath}`
`chrome-extension://${browser.extension.id}/${popupPath}`,
)
})
})
Expand All @@ -171,7 +171,7 @@ describe('chrome.browserAction', () => {
})

const getExtensionActionIds = async (
webContents: Electron.WebContents = browser.webContents
webContents: Electron.WebContents = browser.webContents,
) => {
// Await update propagation to avoid flaky tests
await new Promise((resolve) => setTimeout(resolve, 10))
Expand All @@ -182,7 +182,7 @@ describe('chrome.browserAction', () => {
const actions = list.shadowRoot!.querySelectorAll('.action')
const ids = Array.from(actions).map((elem) => elem.id)
return ids
}})();`
}})();`,
)
}

Expand All @@ -204,7 +204,7 @@ describe('chrome.browserAction', () => {
const list = document.createElement('browser-action-list')
list.setAttribute('partition', partition)
document.body.appendChild(list)
}})('${browser.partition}');`
}})('${browser.partition}');`,
)

const extensionIds = await getExtensionActionIds(remoteTab)
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-chrome-extensions/spec/crx-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const isBackgroundHostSupported = (extension: Electron.Extension) =>

export const waitForBackgroundPage = async (
extension: Electron.Extension,
session: Electron.Session
session: Electron.Session,
) => {
if (!isBackgroundHostSupported(extension)) return

Expand Down Expand Up @@ -76,7 +76,7 @@ export const waitForBackgroundPage = async (

export async function waitForBackgroundScriptEvaluated(
extension: Electron.Extension,
session: Electron.Session
session: Electron.Session,
) {
if (!isBackgroundHostSupported(extension)) return

Expand Down
6 changes: 3 additions & 3 deletions packages/electron-chrome-extensions/spec/events-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const waitForEvent = (target: EventTarget, eventName: string) => {
export const emittedOnce = (
emitter: NodeJS.EventEmitter,
eventName: string,
trigger?: () => void
trigger?: () => void,
) => {
return emittedNTimes(emitter, eventName, 1, trigger).then(([result]) => result)
}
Expand All @@ -52,7 +52,7 @@ export const emittedNTimes = async (
emitter: NodeJS.EventEmitter,
eventName: string,
times: number,
trigger?: () => void
trigger?: () => void,
) => {
const events: any[][] = []
const p = new Promise<any[][]>((resolve) => {
Expand All @@ -74,7 +74,7 @@ export const emittedNTimes = async (
export const emittedUntil = async (
emitter: NodeJS.EventEmitter,
eventName: string,
untilFn: Function
untilFn: Function,
) => {
const p = new Promise<any[]>((resolve) => {
const handler = (...args: any[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Extensions', () => {
const testSession = session.fromPartition('test-extensions')
const extensions = new ElectronChromeExtensions({
license: 'internal-license-do-not-use' as any,
session: testSession
session: testSession,
})

it('retrieves the instance with fromSession()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"manifest_version": 2,
"browser_action": {
"default_icon": {
"16": "icon_16.png",
"32": "icon_32.png"
"16": "icon_16.png",
"32": "icon_32.png"
},
"default_popup": "popup.html",
"default_title": "browserAction Popup"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const logEvent = (eventName) => {
if (eventName) eventLog.push(eventName)
if (typeof activeTabId === 'undefined') return

eventLog.forEach(eventName => {
eventLog.forEach((eventName) => {
chrome.tabs.sendMessage(activeTabId, { name: 'logEvent', args: eventName })
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function exec(action) {
break
} catch (e) {
console.error(e)
await new Promise(resolve => setTimeout(resolve, 100)) // sleep
await new Promise((resolve) => setTimeout(resolve, 100)) // sleep
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/electron-chrome-extensions/spec/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useServer = () => {
server.listen(0, '127.0.0.1', () => {
url = `http://127.0.0.1:${(server.address() as AddressInfo).port}/`
resolve()
})
}),
)
})
after(() => {
Expand Down Expand Up @@ -139,7 +139,7 @@ export const useExtensionBrowser = (opts: {
async eventOnce(eventName: string) {
const p = emittedOnce(ipcMain, 'success')
await w.webContents.executeJavaScript(
`exec('${JSON.stringify({ type: 'event-once', name: eventName })}')`
`exec('${JSON.stringify({ type: 'event-once', name: eventName })}')`,
)
const [, results] = await p

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-chrome-extensions/spec/spec-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class RemoteControlApp {
resolve(ret.result)
}
})
}
},
)
req.write(js)
req.end()
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-chrome-extensions/spec/window-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function ensureWindowIsClosed(window: BrowserWindow | null) {

export const closeWindow = async (
window: BrowserWindow | null = null,
{ assertNotWindows } = { assertNotWindows: true }
{ assertNotWindows } = { assertNotWindows: true },
) => {
await ensureWindowIsClosed(window)

Expand Down
8 changes: 4 additions & 4 deletions packages/electron-chrome-extensions/src/browser-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const injectBrowserAction = () => {
const DEFAULT_PARTITION = '_self'

// Access from globalThis to prevent accessing incorrect minified variable.
const browserAction: typeof __browserAction__ = (globalThis as any).browserAction;
const browserAction: typeof __browserAction__ = (globalThis as any).browserAction

class BrowserActionElement extends HTMLButtonElement {
private updateId?: number
Expand Down Expand Up @@ -356,7 +356,7 @@ export const injectBrowserAction = () => {
await browserAction.getState(this.partition || DEFAULT_PARTITION)
} catch {
console.error(
`browser-action-list failed to update [tab: ${this.tab}, partition: '${this.partition}']`
`browser-action-list failed to update [tab: ${this.tab}, partition: '${this.partition}']`,
)
}
}
Expand All @@ -368,7 +368,7 @@ export const injectBrowserAction = () => {
// Create or update action buttons
for (const action of state.actions) {
let browserActionNode = this.shadowRoot?.querySelector(
`[id=${action.id}]`
`[id=${action.id}]`,
) as BrowserActionElement

if (!browserActionNode) {
Expand All @@ -388,7 +388,7 @@ export const injectBrowserAction = () => {

// Remove any actions no longer in use
const actionNodes = Array.from(
this.shadowRoot?.querySelectorAll('.action') as any
this.shadowRoot?.querySelectorAll('.action') as any,
) as BrowserActionElement[]
for (const actionNode of actionNodes) {
if (!state.actions.some((action: any) => action.id === actionNode.id)) {
Expand Down
Loading

0 comments on commit 2a91f51

Please sign in to comment.