Files
cypress/packages/server/test/unit/util/open_spec.js
Tim Griesser e4442ab7ac refactor: remove global.root & usage in require (#19336)
* refactor: remove global.root & use in requires

* fix types
2021-12-11 14:06:49 -05:00

49 lines
1.0 KiB
JavaScript

require('../../spec_helper')
const cp = require('child_process')
const open = require(`../../../lib/util/open`)
const platform = (p) => {
return Object.defineProperty(process, 'platform', {
value: p,
})
}
describe('lib/util/open', () => {
beforeEach(function () {
this.platform = process.platform
const cpStub = sinon.stub({
once () {},
unref () {},
})
cpStub.once.withArgs('close').yieldsAsync(0)
return sinon.stub(cp, 'spawn').returns(cpStub)
})
afterEach(function () {
// reset the platform
return platform(this.platform)
})
it('spawns process with osx args', () => {
platform('darwin')
return open.opn('../foo', { args: '-R' })
.then(() => {
expect(cp.spawn).to.be.calledWith('open', ['-W', '-R', '../foo'])
})
})
it('spawns process with linux args', () => {
platform('linux')
return open.opn('../foo', { args: '-R' })
.then(() => {
expect(cp.spawn).to.be.calledWithMatch('xdg-open', ['../foo'])
})
})
})