Skip to content

Commit 3cb9aad

Browse files
alexeykuzmincodebytere
authored andcommitted
build: fix the build with enable_run_as_node disabled (electron#15711)
1 parent ca218b6 commit 3cb9aad

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

atom/app/atom_main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace {
5353
const char kRunAsNode[] = "ELECTRON_RUN_AS_NODE";
5454
#endif
5555

56-
bool IsEnvSet(const char* name) {
56+
ALLOW_UNUSED_TYPE bool IsEnvSet(const char* name) {
5757
#if defined(OS_WIN)
5858
size_t required_size;
5959
getenv_s(&required_size, nullptr, 0, name);

atom/common/api/features.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ bool IsPDFViewerEnabled() {
2323
return BUILDFLAG(ENABLE_PDF_VIEWER);
2424
}
2525

26+
bool IsRunAsNodeEnabled() {
27+
return BUILDFLAG(ENABLE_RUN_AS_NODE);
28+
}
29+
2630
bool IsFakeLocationProviderEnabled() {
2731
return BUILDFLAG(OVERRIDE_LOCATION_PROVIDER);
2832
}
@@ -47,6 +51,7 @@ void Initialize(v8::Local<v8::Object> exports,
4751
dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled);
4852
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
4953
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
54+
dict.SetMethod("isRunAsNodeEnabled", &IsRunAsNodeEnabled);
5055
dict.SetMethod("isFakeLocationProviderEnabled",
5156
&IsFakeLocationProviderEnabled);
5257
dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);

spec/asar-spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const remote = require('electron').remote
1212

1313
const { ipcMain, BrowserWindow } = remote
1414

15+
const features = process.atomBinding('features')
16+
1517
describe('asar package', function () {
1618
const fixtures = path.join(__dirname, 'fixtures')
1719

@@ -844,6 +846,12 @@ describe('asar package', function () {
844846
})
845847

846848
describe('child_process.fork', function () {
849+
before(function () {
850+
if (!features.isRunAsNodeEnabled()) {
851+
this.skip()
852+
}
853+
})
854+
847855
it('opens a normal js file', function (done) {
848856
const child = ChildProcess.fork(path.join(fixtures, 'asar', 'a.asar', 'ping.js'))
849857
child.on('message', function (msg) {
@@ -1040,6 +1048,12 @@ describe('asar package', function () {
10401048
})
10411049

10421050
describe('process.env.ELECTRON_NO_ASAR', function () {
1051+
before(function () {
1052+
if (!features.isRunAsNodeEnabled()) {
1053+
this.skip()
1054+
}
1055+
})
1056+
10431057
it('disables asar support in forked processes', function (done) {
10441058
const forked = ChildProcess.fork(path.join(__dirname, 'fixtures', 'module', 'no-asar.js'), [], {
10451059
env: {
@@ -1205,6 +1219,11 @@ describe('asar package', function () {
12051219
})
12061220

12071221
it('is available in forked scripts', function (done) {
1222+
if (!features.isRunAsNodeEnabled()) {
1223+
this.skip()
1224+
done()
1225+
}
1226+
12081227
const child = ChildProcess.fork(path.join(fixtures, 'module', 'original-fs.js'))
12091228
child.on('message', function (msg) {
12101229
assert.strictEqual(msg, 'object')

spec/modules-spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require('fs')
55
const { remote } = require('electron')
66
const { BrowserWindow } = remote
77
const { closeWindow } = require('./window-helpers')
8+
const features = process.atomBinding('features')
89

910
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
1011

@@ -17,7 +18,12 @@ describe('modules support', () => {
1718
require('runas')
1819
})
1920

20-
it('can be required in node binary', (done) => {
21+
it('can be required in node binary', function (done) {
22+
if (!features.isRunAsNodeEnabled()) {
23+
this.skip()
24+
done()
25+
}
26+
2127
const runas = path.join(fixtures, 'module', 'runas.js')
2228
const child = require('child_process').fork(runas)
2329
child.on('message', (msg) => {

spec/node-spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fs = require('fs')
66
const path = require('path')
77
const os = require('os')
88
const { ipcRenderer, remote } = require('electron')
9+
const features = process.atomBinding('features')
910

1011
const isCI = remote.getGlobal('isCi')
1112
chai.use(dirtyChai)
@@ -14,6 +15,12 @@ describe('node feature', () => {
1415
const fixtures = path.join(__dirname, 'fixtures')
1516

1617
describe('child_process', () => {
18+
beforeEach(function () {
19+
if (!features.isRunAsNodeEnabled()) {
20+
this.skip()
21+
}
22+
})
23+
1724
describe('child_process.fork', () => {
1825
it('works in current process', (done) => {
1926
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
@@ -208,6 +215,12 @@ describe('node feature', () => {
208215
describe('inspector', () => {
209216
let child = null
210217

218+
beforeEach(function () {
219+
if (!features.isRunAsNodeEnabled()) {
220+
this.skip()
221+
}
222+
})
223+
211224
afterEach(() => {
212225
if (child !== null) child.kill()
213226
})
@@ -299,7 +312,7 @@ describe('node feature', () => {
299312

300313
describe('net.connect', () => {
301314
before(function () {
302-
if (process.platform !== 'darwin') {
315+
if (!features.isRunAsNodeEnabled() || process.platform !== 'darwin') {
303316
this.skip()
304317
}
305318
})

0 commit comments

Comments
 (0)