Skip to content

Commit

Permalink
refactor openExterna spec to fix side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 22, 2018
1 parent c6b798e commit 4ae0b27
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions spec/api-shell-spec.js
Expand Up @@ -17,7 +17,24 @@ describe('shell module', () => {
}

describe('shell.openExternal()', () => {
it('opens an external link', function (done) {
let envVars = {}

beforeEach(() => {
// keep original process.env values to prevent side effect
envVars = {
display: process.env.DISPLAY,
de: process.env.DE,
browser: process.env.BROWSER
}
})

afterEach(() => {
process.env.BROWSER = envVars.browser
process.env.DE = envVars.de
process.env.DISPLAY = envVars.browser
})

it('opens an external link asynchronously', function (done) {
if (process.platform !== 'linux') this.skip()

// set env vars for xdg-open
Expand All @@ -28,25 +45,18 @@ describe('shell module', () => {

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

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

// set env vars for xdg-open
const url = 'http://www.example.com'
process.env.DE = 'generic'
const tests = [
{ BROWSER: '/bin/true', expected: true },
{ BROWSER: '/bin/false', expected: false }
]

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

const success = shell.openExternalSync(url)
assert.strictEqual(true, success)
})
})

Expand Down

0 comments on commit 4ae0b27

Please sign in to comment.