Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add isElectronMain env test #13

Merged
merged 11 commits into from
Sep 19, 2019
2 changes: 2 additions & 0 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const isElectron = require('is-electron')
const IS_ENV_WITH_DOM = typeof window === 'object' && typeof document === 'object' && document.nodeType === 9
const IS_ELECTRON = isElectron()
const IS_BROWSER = IS_ENV_WITH_DOM && !IS_ELECTRON
const IS_ELECTRON_MAIN = IS_ELECTRON && !IS_ENV_WITH_DOM
const IS_ELECTRON_RENDERER = IS_ELECTRON && IS_ENV_WITH_DOM
const IS_NODE = typeof require === 'function' && typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node' && !IS_ELECTRON
// eslint-disable-next-line no-undef
Expand All @@ -13,6 +14,7 @@ const IS_TEST = typeof process !== 'undefined' && typeof process.env !== 'undefi
module.exports = {
isTest: IS_TEST,
isElectron: IS_ELECTRON,
isElectronMain: IS_ELECTRON_MAIN,
isElectronRenderer: IS_ELECTRON_RENDERER,
isNode: IS_NODE,
/**
Expand Down
27 changes: 27 additions & 0 deletions test/env.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe('env', function () {
if (env.isElectron) {
return expect(env.isElectron).to.be.true()
}
if (env.isElectronMain) {
return expect(env.isElectron).to.be.true()
}
if (env.isElectronRenderer) {
return expect(env.isElectron).to.be.true()
}
Expand All @@ -27,13 +30,37 @@ describe('env', function () {
}
})

it('isElectronMain should have the correct value in each env', function () {
if (env.isElectron && !env.isElectronRenderer) {
return expect(env.isElectronMain).to.be.true()
}
if (env.isElectronMain) {
return expect(env.isElectronMain).to.be.true()
hugomrdias marked this conversation as resolved.
Show resolved Hide resolved
}
if (env.isElectronRenderer) {
return expect(env.isElectronMain).to.be.false()
}
if (env.isBrowser) {
return expect(env.isElectronMain).to.be.false()
}
if (env.isNode) {
return expect(env.isElectronMain).to.be.false()
}
if (env.isWebWorker) {
return expect(env.isElectronMain).to.be.false()
}
})

it('isElectronRenderer should have the correct value in each env', function () {
if (env.isElectron && !env.isElectronRenderer) {
return expect(env.isElectronRenderer).to.be.false()
}
if (env.isElectronRenderer) {
return expect(env.isElectronRenderer).to.be.true()
}
if (env.isElectronMain) {
return expect(env.isElectronRenderer).to.be.false()
}
if (env.isBrowser) {
return expect(env.isElectronRenderer).to.be.false()
}
Expand Down