2017-04-26 66 views
0

我有一段时间让它在特拉维斯CI上运行。间歇工作,但往往不是噩梦失败,此错误:特拉维斯噩梦般的噩梦:`噩梦:日志崩溃[{},false]`

nightmare:log did-get-response-details [{},false,"https://fonts.gstatic.com/s/roboto/v16/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2","https://fonts.gstatic.com/s/roboto/v16/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2",200,"GET","https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons",{"accept-ranges":["bytes"],"access-control-allow-origin":["*"],"age":["706260"],"alt-svc":["quic=\":443\"; ma=2592000; v=\"37,36,35\""],"cache-control":["public, max-age=31536000"],"content-length":["14696"],"content-type":["font/woff2"],"date":["Mon, 17 Apr 2017 21:24:49 GMT"],"expires":["Tue, 17 Apr 2018 21:24:49 GMT"],"last-modified":["Tue, 04 Apr 2017 18:34:45 GMT"],"server":["sffe"],"status":["200"],"timing-allow-origin":["*"],"x-content-type-options":["nosniff"],"x-xss-protection":["1; mode=block"]},"other"] +0ms 
    nightmare:log did-stop-loading [{}] +276ms 
    nightmare:log crashed [{},false] +1ms 
    nightmare:actions .wait() for .main-container element or 1000msec +29s 
    nightmare:actions .evaluate() fn on the page +1s 
/home/travis/build/esalter-va/esalter-va.github.io/node_modules/webpack-static-site-generator/render.js:30 
        setTimeout(function() {throw err}) 
              ^
Error: Evaluation timed out after 30000msec. Are you calling done() or resolving your promises? 
    at Timeout._onTimeout (/home/travis/build/esalter-va/esalter-va.github.io/node_modules/nightmare/lib/actions.js:509:10) 
    at ontimeout (timers.js:386:14) 
    at tryOnTimeout (timers.js:250:5) 
    at Timer.listOnTimeout (timers.js:214:5) 

我试图运行使用噩梦的WebPack扩展。代码是here,但我的设置只是如下。

// plugin: index.js 
    if (process.platform === 'linux'){ 
     xvfb.startSync() 
     process.env['DISPLAY'] = ':99.0' 
    } 
    var server = serve(self.outputPath) 
    var port = server.address().port 
    var outputFiles = render(port, self.routes, self.elementToWaitFor) 

    outputFiles.then(files => { 
     for (var i = 0; i < files.length; i++) { 
      var outputFilePath = path.join(self.outputPath, self.routes[i]) 
      var outputFileName = path.join(outputFilePath, 'index.html') 
      fsPath.writeFile(outputFileName, files[i]) 
     } 
     server.close(function() { 
      xvfb.stopSync() 
      done() 
     }) 
    }).catch(err => { 
     setTimeout(function() {throw err}) 
     server.close(function() { 
      xvfb.stopSync() 
      done() 
     }) 
    }) 

// plugin: render.js (where `var outputFiles = render(port, self.routes, self.elementToWaitFor)` goes) 
function render(port, routes, elementToWaitFor) { 

    var nightmare = Nightmare({ 
     show: false, 
     webPreferences: { 
      partition: 'partition-' + Math.random() 
     } 
    }) 

    var baseUrl = `http://localhost:${port}` 

    var pageContents = routes.reduce(function (accumulator, route) { 
     return accumulator.then(function (results) { 
      var url = baseUrl + route 
      return nightmare 
       .goto(url) 
       .wait(elementToWaitFor, 1000) 
       .evaluate(function() { 
        return document.documentElement.innerHTML 
       }) 
       .then(function (content) { 
        results.push(content) 
        return results 
       }) 
       .catch(err => { 
        setTimeout(function() {throw err}) 
       }) 
     }) 
    }, Promise.resolve([])) 

    return pageContents.then(function (values) { 
     return nightmare.end().then(function() { 
      return values 
     }) 
    }).catch(err => { 
     setTimeout(function() {console.log(`Error ${err}`)}) 
    }) 
} 

# .travis.yml (project that uses plugin) 
language: node_js 
node_js: 
    - "node" 
addons: 
    apt: 
    packages: 
     - xvfb 
     - libxss1 
script: 
    - yarn run lint 
    - yarn run build 

// package.json 
    "scripts": { 
    "build": "DEBUG=nightmare:*,electron:* node build/build.js", 
    }, 

构建脚本运行的WebPack,它运行我的噩梦脚本。 Here's a Gist with the full error log

我已经尝试了我可以在网上找到的每个解决方案,但似乎没有任何工作。

一些我试过的东西(我能记得:

  • Nightmare({show: false})
  • Nightmare({webPreferences: {partition: 'partition-' + Math.random()}
  • 添加超时.wait()
  • 添加更多apt包为不同岗位的在线建议
  • 其他的一切,应该写下来。

任何帮助将不胜感激,如果我错过了任何东西,请让我知道!

回答

0

这似乎已通过将sudo: required添加到我的.travis.yml解决。