Skip to content

原文地址:https://zhuanlan.zhihu.com/p/156771848

********

[child_process](https://link.zhihu.com/?target=https%3A//nodejs.org/docs/latest-v10.x/api/child_process.html)****

********************

****

****

************Why does ENOENT mean “No such file or directory”?****

****

[karma](https://link.zhihu.com/?target=https%3A//karma-runner.github.io/5.0/index.html)****

************

****[nvm](https://link.zhihu.com/?target=https%3A//github.com/coreybutler/nvm-windows)

[github issues](https://link.zhihu.com/?target=https%3A//github.com/coreybutler/nvm-windows/issues/548)

************

淘宝注册源

[stack overflow](https://link.zhihu.com/?target=https%3A//stackoverflow.com/questions/27688804/how-do-i-debug-error-spawn-enoent-on-node-js)[cross-spawn](https://link.zhihu.com/?target=https%3A//github.com/moxystudio/node-cross-spawn)************

****************

javascript
'use strict'
// var spawn = require('child_process').spawn
const spawn = require('cross-spawn');
// const exec = require('child_process').exec;
var https = require('https')
var fs = require('fs')
var path = require('path')

var server = https.createServer({
  key: fs.readFileSync(path.join(__dirname, '/ssl/server.key')),
  cert: fs.readFileSync(path.join(__dirname, '/ssl/server.crt')),
  ca: fs.readFileSync(path.join(__dirname, '/ssl/ca.crt')),
  requestCert: true,
  rejectUnauthorized: false
}, function (req, res) {
  // Set CORS header, since that is something we are testing.
  res.setHeader('Access-Control-Allow-Origin', '*')
  res.writeHead(200)
  res.end('Can you hear the sound of an enormous door slamming in the depths of hell?\n')
})
server.listen(0, function () {
  var port = this.address().port
  console.log('Started https server for karma tests on port ' + port)
  // Spawn process for karma.
  var c = spawn('karma', [
    'start',
    path.join(__dirname, '/karma.conf.js'),
    'https://localhost:' + port
  ])
  // const command = 'karma start ' + path.join(__dirname, '/karma.conf.js') + ' http://localhost:' + port
  // exec(command, function(error, stdout, stderr) {
  //   if(error || stderr) console.log(error || stderr);
  //   else console.log(stdout);
  // })
  c.stdout.pipe(process.stdout)
  c.stderr.pipe(process.stderr)
  c.on('exit', function (c) {
    // Exit process with karma exit code.
    if (c !== 0) {
      throw new Error('Karma exited with status code ' + c)
    }
    server.close()
  })
})
********************