Skip to content

Commit

Permalink
test: add new openExternal specs for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 22, 2018
1 parent 71dc30b commit 5753a72
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/api/shell.md
Expand Up @@ -36,7 +36,7 @@ Open the given file in the desktop's default manner.

### `shell.openExternalSync(url[, options])`

* `url` String - Max 2081 characters on windows, or the function returns false.
* `url` String - Max 2081 characters on Windows, or the function returns false.
* `options` Object (optional)
* `activate` Boolean (optional) - `true` to bring the opened application to the
foreground. The default is `true`. _macOS_
Expand All @@ -48,13 +48,13 @@ Open the given external protocol URL in the desktop's default manner. (For examp

### `shell.openExternal(url[, options])`

* `url` String - Max 2081 characters on windows, or the function returns false.
* `url` String - Max 2081 characters on windows.
* `options` Object (optional)
* `activate` Boolean (optional) - `true` to bring the opened application to the
foreground. The default is `true`. _macOS_
* `workingDirectory` String (optional) - The working directory. _Windows_

Returns `Promise<Any>`
Returns `Promise<void>`

Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).

Expand Down
4 changes: 3 additions & 1 deletion script/prepare-release.js
Expand Up @@ -60,7 +60,9 @@ async function getReleaseNotes (currentBranch) {
}
console.log(`Generating release notes for ${currentBranch}.`)
const releaseNotes = await releaseNotesGenerator(currentBranch)
if (releaseNotes.warning) console.warn(releaseNotes.warning)
if (releaseNotes.warning) {
console.warn(releaseNotes.warning)
}
return releaseNotes
}

Expand Down
45 changes: 40 additions & 5 deletions spec/api-shell-spec.js
Expand Up @@ -16,14 +16,45 @@ describe('shell module', () => {
iconIndex: 1
}

// (alexeykuzmin): `.skip()` in `before` doesn't work for nested `describe`s.
beforeEach(function () {
if (process.platform !== 'win32') {
this.skip()
}
describe('shell.openExternal()', () => {
it('opens an external link', function (done) {
if (process.platform !== 'linux') this.skip()

// set env vars for xdg-open
const url = 'http://www.example.com'
process.env.DE = 'generic'
process.env.BROWSER = '/bin/true'
process.env.DISPLAY = ''

shell.openExternal(url).then(() => done())
})
})

describe('shell.openExternalSync()', () => {
it('opens an external link', function () {
if (process.platform !== 'linux') this.skip()

process.env.DE = 'generic'
process.env.DISPLAY = ''
const tests = [
{ BROWSER: '/bin/true', expected: true },
{ BROWSER: '/bin/false', expected: false }
]

for (const test of tests) {
const { BROWSER, expected } = test
process.env.BROWSER = BROWSER
const actual = shell.openExternalSync('http://www.example.com')
assert.strictEqual(expected, actual)
}
})
})

describe('shell.readShortcutLink(shortcutPath)', () => {
beforeEach(function () {
if (process.platform !== 'win32') this.skip()
})

it('throws when failed', () => {
assert.throws(() => {
shell.readShortcutLink('not-exist')
Expand All @@ -37,6 +68,10 @@ describe('shell module', () => {
})

describe('shell.writeShortcutLink(shortcutPath[, operation], options)', () => {
beforeEach(function () {
if (process.platform !== 'win32') this.skip()
})

const tmpShortcut = path.join(os.tmpdir(), `${Date.now()}.lnk`)

afterEach(() => {
Expand Down

0 comments on commit 5753a72

Please sign in to comment.