From 7f5995eb64a64928b45e6c2db187234ea8668d54 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 20 Mar 2023 15:08:27 +0700 Subject: [PATCH] Require Node.js 14 and move to ESM --- .github/workflows/main.yml | 7 +- index.d.ts | 224 +++++++++++++++++-------------------- index.js | 96 +++++++--------- index.test-d.ts | 11 +- package.json | 24 ++-- readme.md | 77 ++++++------- test.js | 21 ++-- 7 files changed, 210 insertions(+), 250 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 41fe626..d50ada6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,11 +10,12 @@ jobs: fail-fast: false matrix: node-version: + - 18 + - 16 - 14 - - 12 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index f82d502..e62feaf 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,171 +1,157 @@ -import {ChildProcess} from 'child_process'; +import {type ChildProcess} from 'node:child_process'; -declare namespace open { - interface Options { - /** - Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app. - - Note that it waits for the app to exit, not just for the window to close. - - On Windows, you have to explicitly specify an app for it to be able to wait. +export type Options = { + /** + Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app. - @default false - */ - readonly wait?: boolean; + Note that it waits for the app to exit, not just for the window to close. - /** - __macOS only__ + On Windows, you have to explicitly specify an app for it to be able to wait. - Do not bring the app to the foreground. + @default false + */ + readonly wait?: boolean; - @default false - */ - readonly background?: boolean; + /** + __macOS only__ - /** - __macOS only__ + Do not bring the app to the foreground. - Open a new instance of the app even it's already running. + @default false + */ + readonly background?: boolean; - A new instance is always opened on other platforms. + /** + __macOS only__ - @default false - */ - readonly newInstance?: boolean; + Open a new instance of the app even it's already running. - /** - Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown. + A new instance is always opened on other platforms. - The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use. + @default false + */ + readonly newInstance?: boolean; - You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome. + /** + Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown. - The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts. - */ - readonly app?: App | readonly App[]; + The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use `apps` which auto-detects the correct binary to use. - /** - Allow the opened app to exit with nonzero exit code when the `wait` option is `true`. + You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome. - We do not recommend setting this option. The convention for success is exit code zero. + The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts. + */ + readonly app?: App | readonly App[]; - @default false - */ - readonly allowNonzeroExitCode?: boolean; - } + /** + Allow the opened app to exit with nonzero exit code when the `wait` option is `true`. - interface OpenAppOptions extends Omit { - /** - Arguments passed to the app. + We do not recommend setting this option. The convention for success is exit code zero. - These arguments are app dependent. Check the app's documentation for what arguments it accepts. - */ - readonly arguments?: readonly string[]; - } + @default false + */ + readonly allowNonzeroExitCode?: boolean; +}; - type AppName = - | 'chrome' - | 'firefox' - | 'edge' - | 'browser' - | 'browserPrivate'; +export type OpenAppOptions = { + /** + Arguments passed to the app. - type App = { - name: string | readonly string[]; - arguments?: readonly string[]; - }; -} + These arguments are app dependent. Check the app's documentation for what arguments it accepts. + */ + readonly arguments?: readonly string[]; +} & Omit; + +export type AppName = + | 'chrome' + | 'firefox' + | 'edge' + | 'browser' + | 'browserPrivate'; + +export type App = { + name: string | readonly string[]; + arguments?: readonly string[]; +}; /** An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences. @example ``` -import open from 'open'; +import open, {apps} from 'open'; await open('https://google.com', { app: { - name: open.apps.chrome + name: apps.chrome } }); ``` */ -declare const apps: Record; +export const apps: Record; -// eslint-disable-next-line no-redeclare -declare const open: { - /** - Open stuff like URLs, files, executables. Cross-platform. - - Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms. +/** +Open stuff like URLs, files, executables. Cross-platform. - There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`. +Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms. - @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser. - @returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process. +There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`. - @example - ``` - import open from 'open'; +@param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser. +@returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process. - // Opens the image in the default image viewer. - await open('unicorn.png', {wait: true}); - console.log('The image viewer app quit'); +@example +``` +import open, {apps} from 'open'; - // Opens the URL in the default browser. - await open('https://sindresorhus.com'); +// Opens the image in the default image viewer. +await open('unicorn.png', {wait: true}); +console.log('The image viewer app quit'); - // Opens the URL in a specified browser. - await open('https://sindresorhus.com', {app: {name: 'firefox'}}); +// Opens the URL in the default browser. +await open('https://sindresorhus.com'); - // Specify app arguments. - await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}}); +// Opens the URL in a specified browser. +await open('https://sindresorhus.com', {app: {name: 'firefox'}}); - // Opens the URL in the default browser in incognito mode. - await open('https://sindresorhus.com', {app: {name: open.apps.browserPrivate}}); - ``` - */ - ( - target: string, - options?: open.Options - ): Promise; +// Specify app arguments. +await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}}); - /** - An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences. - */ - apps: typeof apps; - - /** - Open an app. Cross-platform. +// Opens the URL in the default browser in incognito mode. +await open('https://sindresorhus.com', {app: {name: apps.browserPrivate}}); +``` +*/ +export default function open( + target: string, + options?: Options +): Promise; - Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms. +/** +Open an app. Cross-platform. - @param name - The app you want to open. Can be either builtin supported `open.apps` names or other name supported in platform. - @returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process. +Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms. - @example - ``` - import open from 'open'; - const {apps, openApp} = open; +@param name - The app you want to open. Can be either builtin supported `apps` names or other name supported in platform. +@returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process. - // Open Firefox. - await openApp(apps.firefox); +@example +``` +import open, {openApp, apps} from 'open'; - // Open Chrome in incognito mode. - await openApp(apps.chrome, {arguments: ['--incognito']}); +// Open Firefox. +await openApp(apps.firefox); - // Open default browser. - await openApp(apps.browser); +// Open Chrome in incognito mode. +await openApp(apps.chrome, {arguments: ['--incognito']}); - // Open default browser in incognito mode. - await openApp(apps.browserPrivate); +// Open default browser. +await openApp(apps.browser); - // Open Xcode. - await openApp('xcode'); - ``` - */ - openApp: (name: open.App['name'], options?: open.OpenAppOptions) => Promise; -}; +// Open default browser in incognito mode. +await openApp(apps.browserPrivate); -export {apps}; -export default open; +// Open Xcode. +await openApp('xcode'); +``` +*/ +export function openApp(name: App['name'], options?: OpenAppOptions): Promise; diff --git a/index.js b/index.js index aef1558..c79501e 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,14 @@ -import path from 'path'; -import {fileURLToPath} from 'url'; -import childProcess from 'child_process'; -import {promises as fs, constants as fsConstants} from 'fs'; +import process from 'node:process'; +import {Buffer} from 'node:buffer'; +import path from 'node:path'; +import {fileURLToPath} from 'node:url'; +import childProcess from 'node:child_process'; +import fs from 'node:fs/promises'; +import {constants as fsConstants} from 'node:fs'; // TODO: Move this to the above import when targeting Node.js 18. import isWsl from 'is-wsl'; -import isDocker from 'is-docker'; import defineLazyProperty from 'define-lazy-prop'; import defaultBrowser from 'default-browser'; +import isInsideContainer from 'is-inside-container'; // Path to included `xdg-open`. const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -13,25 +16,6 @@ const localXdgOpenPath = path.join(__dirname, 'xdg-open'); const {platform, arch} = process; -// Podman detection -const hasContainerEnv = () => { - try { - fs.statSync('/run/.containerenv'); - return true; - } catch { - return false; - } -}; - -let cachedResult; -function isInsideContainer() { - if (cachedResult === undefined) { - cachedResult = hasContainerEnv() || isDocker(); - } - - return cachedResult; -} - /** Get the mount point for fixed drives in WSL. @@ -97,17 +81,17 @@ const baseOpen = async options => { background: false, newInstance: false, allowNonzeroExitCode: false, - ...options + ...options, }; if (Array.isArray(options.app)) { return pTryEach(options.app, singleApp => baseOpen({ ...options, - app: singleApp + app: singleApp, })); } - let {name: app, arguments: appArguments = []} = options.app || {}; + let {name: app, arguments: appArguments = []} = options.app ?? {}; appArguments = [...appArguments]; if (Array.isArray(app)) { @@ -115,8 +99,8 @@ const baseOpen = async options => { ...options, app: { name: appName, - arguments: appArguments - } + arguments: appArguments, + }, })); } @@ -129,14 +113,14 @@ const baseOpen = async options => { 'firefox.desktop': 'firefox', 'com.microsoft.msedge': 'edge', 'com.microsoft.edge': 'edge', - 'microsoft-edge.desktop': 'edge' + 'microsoft-edge.desktop': 'edge', }; - // Incognito flags for each browser in open.apps + // Incognito flags for each browser in `apps`. const flags = { chrome: '--incognito', firefox: '--private-window', - edge: '--inPrivate' + edge: '--inPrivate', }; const browser = await defaultBrowser(); @@ -150,9 +134,9 @@ const baseOpen = async options => { return baseOpen({ ...options, app: { - name: open.apps[browserName], - arguments: appArguments - } + name: apps[browserName], + arguments: appArguments, + }, }); } @@ -184,16 +168,16 @@ const baseOpen = async options => { } else if (platform === 'win32' || (isWsl && !isInsideContainer() && !app)) { const mountPoint = await getWslDrivesMountPoint(); - command = isWsl ? - `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` : - `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`; + command = isWsl + ? `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` + : `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`; cliArguments.push( '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', - '-EncodedCommand' + '-EncodedCommand', ); if (!isWsl) { @@ -238,8 +222,8 @@ const baseOpen = async options => { exeLocalXdgOpen = true; } catch {} - const useSystemXdgOpen = process.versions.electron || - platform === 'android' || isBundled || !exeLocalXdgOpen; + const useSystemXdgOpen = process.versions.electron + ?? (platform === 'android' || isBundled || !exeLocalXdgOpen); command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath; } @@ -292,16 +276,16 @@ const open = (target, options) => { return baseOpen({ ...options, - target + target, }); }; -const openApp = (name, options) => { +export const openApp = (name, options) => { if (typeof name !== 'string') { throw new TypeError('Expected a `name`'); } - const {arguments: appArguments = []} = options || {}; + const {arguments: appArguments = []} = options ?? {}; if (appArguments !== undefined && appArguments !== null && !Array.isArray(appArguments)) { throw new TypeError('Expected `appArguments` as Array type'); } @@ -310,8 +294,8 @@ const openApp = (name, options) => { ...options, app: { name, - arguments: appArguments - } + arguments: appArguments, + }, }); }; @@ -341,41 +325,37 @@ function detectPlatformBinary({[platform]: platformBinary}, {wsl}) { return detectArchBinary(platformBinary); } -const apps = {}; +export const apps = {}; defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({ darwin: 'google chrome', win32: 'chrome', - linux: ['google-chrome', 'google-chrome-stable', 'chromium'] + linux: ['google-chrome', 'google-chrome-stable', 'chromium'], }, { wsl: { ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe', - x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'] - } + x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'], + }, })); defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({ darwin: 'firefox', win32: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe', - linux: 'firefox' + linux: 'firefox', }, { - wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe' + wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe', })); defineLazyProperty(apps, 'edge', () => detectPlatformBinary({ darwin: 'microsoft edge', win32: 'msedge', - linux: ['microsoft-edge', 'microsoft-edge-dev'] + linux: ['microsoft-edge', 'microsoft-edge-dev'], }, { - wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe' + wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', })); defineLazyProperty(apps, 'browser', () => 'browser'); defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate'); -open.apps = apps; -open.openApp = openApp; - -export {apps}; export default open; diff --git a/index.test-d.ts b/index.test-d.ts index fb1649a..90d9b18 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,17 +1,14 @@ +import {type ChildProcess} from 'node:child_process'; import {expectType} from 'tsd'; -import {ChildProcess} from 'child_process'; -import open from '.'; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const options: open.Options = {}; +import open from './index.js'; expectType>(open('foo')); expectType>(open('foo', {app: { - name: 'bar' + name: 'bar', }})); expectType>(open('foo', {app: { name: 'bar', - arguments: ['--arg'] + arguments: ['--arg'], }})); expectType>(open('foo', {wait: true})); expectType>(open('foo', {background: true})); diff --git a/package.json b/package.json index 38b864d..ae40521 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "open", "version": "8.4.0", - "type": "module", "description": "Open stuff like URLs, files, executables. Cross-platform.", "license": "MIT", "repository": "sindresorhus/open", @@ -11,8 +10,13 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, "engines": { - "node": ">=12" + "node": ">=14.16" }, "scripts": { "test": "xo && tsd" @@ -49,15 +53,15 @@ "file" ], "dependencies": { - "define-lazy-prop": "^2.0.0", - "is-docker": "^2.1.1", - "is-wsl": "^2.2.0", - "default-browser": "^3.1.0" + "default-browser": "^3.1.0", + "define-lazy-prop": "^3.0.0", + "is-inside-container": "^1.0.0", + "is-wsl": "^2.2.0" }, "devDependencies": { - "@types/node": "^15.0.0", - "ava": "^3.15.0", - "tsd": "^0.14.0", - "xo": "^0.39.1" + "@types/node": "^18.15.3", + "ava": "^5.2.0", + "tsd": "^0.28.0", + "xo": "^0.53.1" } } diff --git a/readme.md b/readme.md index aa9cbd8..610e3a4 100644 --- a/readme.md +++ b/readme.md @@ -23,10 +23,12 @@ This package does not make any security guarantees. If you pass in untrusted inp npm install open ``` +**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM. + ## Usage ```js -import open from 'open'; +import open, {openApp, apps} from 'open'; // Opens the image in the default image viewer and waits for the opened app to quit. await open('unicorn.png', {wait: true}); @@ -42,13 +44,13 @@ await open('https://sindresorhus.com', {app: {name: 'firefox'}}); await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}}); // Opens the URL in the default browser in incognito mode. -await open('https://sindresorhus.com', {app: {name: open.apps.browserPrivate}}); +await open('https://sindresorhus.com', {app: {name: apps.browserPrivate}}); // Open an app. -await open.openApp('xcode'); +await openApp('xcode'); // Open an app with arguments. -await open.openApp(open.apps.chrome, {arguments: ['--incognito']}); +await openApp(apps.chrome, {arguments: ['--incognito']}); ``` ## API @@ -104,7 +106,7 @@ Type: `{name: string | string[], arguments?: string[]} | Array<{name: string | s Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown. -The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use. +The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`apps`](#apps) which auto-detects the correct binary to use. You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome. @@ -119,42 +121,7 @@ Allow the opened app to exit with nonzero exit code when the `wait` option is `t We do not recommend setting this option. The convention for success is exit code zero. -### open.apps / apps - -An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app). - -```js -// Using default export. -import open from 'open'; - -await open('https://google.com', { - app: { - name: open.apps.chrome - } -}); - -// Using named export. -import open, {apps} from 'open'; - -await open('https://firefox.com', { - app: { - name: apps.browserPrivate - } -}); -``` -`browser` and `browserPrivate` can also be used to access the user's default browser through [`default-browser`](https://github.com/sindresorhus/default-browser). - -#### Supported apps - -- [`chrome`](https://www.google.com/chrome) - Web browser -- [`firefox`](https://www.mozilla.org/firefox) - Web browser -- [`edge`](https://www.microsoft.com/edge) - Web browser -- `browser` - Default web browser -- `browserPrivate` - Default web browser in incognito mode - -`browser` and `browserPrivate` only supports `chrome`, `firefox` and `edge`. - -### open.openApp(name, options?) +### openApp(name, options?) Open an app. @@ -164,7 +131,7 @@ Returns a promise for the [spawned child process](https://nodejs.org/api/child_p Type: `string` -The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use. +The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`apps`](#apps) which auto-detects the correct binary to use. You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome. @@ -183,6 +150,32 @@ Arguments passed to the app. These arguments are app dependent. Check the app's documentation for what arguments it accepts. +### apps + +An object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app). + +```js +import open, {apps} from 'open'; + +await open('https://google.com', { + app: { + name: apps.chrome + } +}); +``` + +`browser` and `browserPrivate` can also be used to access the user's default browser through [`default-browser`](https://github.com/sindresorhus/default-browser). + +#### Supported apps + +- [`chrome`](https://www.google.com/chrome) - Web browser +- [`firefox`](https://www.mozilla.org/firefox) - Web browser +- [`edge`](https://www.microsoft.com/edge) - Web browser +- `browser` - Default web browser +- `browserPrivate` - Default web browser in incognito mode + +`browser` and `browserPrivate` only supports `chrome`, `firefox`, and `edge`. + ## Related - [open-cli](https://github.com/sindresorhus/open-cli) - CLI for this module diff --git a/test.js b/test.js index af37e70..e7d376c 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,5 @@ import test from 'ava'; -import open from './index.js'; -const {openApp} = open; +import open, {openApp, apps} from './index.js'; // Tests only checks that opening doesn't return an error // it has no way make sure that it actually opened anything. @@ -24,13 +23,13 @@ test('open URL in default app', async t => { }); test('open URL in specified app', async t => { - await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: open.apps.chrome}})); + await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: apps.chrome}})); }); test('open URL in specified app with arguments', async t => { await t.notThrowsAsync(async () => { - const proc = await open('https://sindresorhus.com', {app: {name: open.apps.chrome, arguments: ['--incognito']}}); - t.deepEqual(proc.spawnargs, ['open', '-a', open.apps.chrome, 'https://sindresorhus.com', '--args', '--incognito']); + const proc = await open('https://sindresorhus.com', {app: {name: apps.chrome, arguments: ['--incognito']}}); + t.deepEqual(proc.spawnargs, ['open', '-a', apps.chrome, 'https://sindresorhus.com', '--args', '--incognito']); }); }); @@ -72,25 +71,25 @@ test('open URL with query strings and URL reserved characters with `url` option' }); test('open Firefox without arguments', async t => { - await t.notThrowsAsync(openApp(open.apps.firefox)); + await t.notThrowsAsync(openApp(apps.firefox)); }); test('open Chrome in incognito mode', async t => { - await t.notThrowsAsync(openApp(open.apps.chrome, {arguments: ['--incognito'], newInstance: true})); + await t.notThrowsAsync(openApp(apps.chrome, {arguments: ['--incognito'], newInstance: true})); }); test('open URL with default browser argument', async t => { - await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: open.apps.browser}})); + await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: apps.browser}})); }); test('open URL with default browser in incognito mode', async t => { - await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: open.apps.browserPrivate}})); + await t.notThrowsAsync(open('https://sindresorhus.com', {app: {name: apps.browserPrivate}})); }); test('open default browser', async t => { - await t.notThrowsAsync(openApp(open.apps.browser, {newInstance: true})); + await t.notThrowsAsync(openApp(apps.browser, {newInstance: true})); }); test('open default browser in incognito mode', async t => { - await t.notThrowsAsync(openApp(open.apps.browserPrivate, {newInstance: true})); + await t.notThrowsAsync(openApp(apps.browserPrivate, {newInstance: true})); });