watcher.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const pti = require('puppeteer-to-istanbul')
  2. const puppeteer = require('puppeteer');
  3. var fs = require('fs');
  4. var util = require('util');
  5. var logFile = fs.createWriteStream('log.txt', { flags: 'w' });
  6. // Or 'w' to truncate the file every time the process starts.
  7. var logStdout = process.stdout;
  8. console.log = function () {
  9. logFile.write(util.format.apply(null, arguments) + '\n');
  10. logStdout.write(util.format.apply(null, arguments) + '\n');
  11. }
  12. console.error = console.log;
  13. (async () => {
  14. const browser = await puppeteer.launch({args: ['--no-proxy-server', '--no-sandbox', '--disable-setuid-sandbox']});
  15. const page = await browser.newPage();
  16. page.on('console', async function (msg) {
  17. var text = msg.text();
  18. if (text.startsWith('[test-result]')) {
  19. console.log('==[TESTING-ENDS]==')
  20. const details = JSON.parse(text.replace('[test-result]', ''))
  21. console.log(details)
  22. const jsCoverage = await page.coverage.stopJSCoverage();
  23. pti.write(jsCoverage, { includeHostname: true , storagePath: './.nyc_output' })
  24. await browser.close()
  25. } else {
  26. console.log(msg.text())
  27. }
  28. });
  29. await page.coverage.startJSCoverage();
  30. await page.goto('http://127.0.0.1:3000/test');
  31. })()