Browse Source

Add basic test of spawned ELECTRON_RUN_AS_NODE process

Kevin Sawicki 8 years ago
parent
commit
e899050500
2 changed files with 28 additions and 0 deletions
  1. 5 0
      spec/fixtures/module/run-as-node.js
  2. 23 0
      spec/node-spec.js

+ 5 - 0
spec/fixtures/module/run-as-node.js

@@ -0,0 +1,5 @@
+console.log(JSON.stringify({
+  processLog: typeof process.log,
+  processType: typeof process.type,
+  window: typeof window
+}))

+ 23 - 0
spec/node-spec.js

@@ -92,6 +92,29 @@ describe('node feature', function () {
         })
       })
     })
+
+    describe('child_process.spawn', function () {
+      it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', function (done) {
+        const child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
+          env: {
+            ELECTRON_RUN_AS_NODE: true
+          }
+        })
+
+        let output = ''
+        child.stdout.on('data', function (data) {
+          output += data
+        })
+        child.stdout.on('close', function () {
+          assert.deepEqual(JSON.parse(output), {
+            processLog: process.platform === 'win32' ? 'function' : 'undefined',
+            processType: 'undefined',
+            window: 'undefined'
+          })
+          done()
+        })
+      })
+    })
   })
 
   describe('contexts', function () {