You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.5 KiB

8 months ago
  1. #!/usr/bin/env node
  2. var lint = require("./lint");
  3. var files = new (require('node-static').Server)();
  4. var server = require('http').createServer(function (req, res) {
  5. req.addListener('end', function () {
  6. files.serve(req, res, function (err/*, result */) {
  7. if (err) {
  8. console.error(err);
  9. process.exit(1);
  10. }
  11. });
  12. }).resume();
  13. }).addListener('error', function (err) {
  14. throw err;
  15. }).listen(3000,(async () => {
  16. const puppeteer = require('puppeteer');
  17. const browser = await puppeteer.launch({args: ["--no-sandbox", "--disable-setuid-sandbox"]})
  18. const page = await browser.newPage()
  19. page.on('console', msg => console.log("console:", msg.text()))
  20. page.on('dialog', async dialog => {
  21. console.log(dialog.message())
  22. await dialog.dismiss()
  23. })
  24. page.evaluateOnNewDocument(() => window.automatedTests = true)
  25. await page.goto('http://localhost:3000/test/index.html#' + (process.argv[2] || ""))
  26. while(1) {
  27. if (await page.evaluate(() => window.done)) break
  28. await sleep(200)
  29. }
  30. let [failed, errors] = await page.evaluate(() => [window.failed, window.errored])
  31. for (let error of errors) console.log(error)
  32. console.log(await page.evaluate(() => document.getElementById('output').innerText + "\n" +
  33. document.getElementById('status').innerText))
  34. process.exit(failed > 0 || errors.length || !lint.ok ? 1 : 0)
  35. await browser.close()
  36. })())
  37. function sleep(n) { return new Promise(acc => setTimeout(acc, n)) }