Skip to content

Report browser test errors #5408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,6 @@ task 'test', 'run the CoffeeScript language test suite', ->


task 'test:browser', 'run the test suite against the modern browser compiler in a headless browser', ->
# This test uses Puppeteer to launch headless Chrome to test the ES module
# version of the browser compiler. There’s no reason to run this test in old
# versions of Node (the runtime is the headless Chrome browser, not Node),
# and Puppeteer 3 only supports Node >= 10.18.1, so limit this test to those
# versions. The code below uses `Promise.prototype.finally` because the
# CoffeeScript codebase currently maintains compatibility with Node 6, which
# did not support `async`/`await` syntax. Even though this test doesn’t run
# in Node 6, it needs to still _parse_ in Node 6 so that this file can load.
[major, minor, build] = process.versions.node.split('.').map (n) -> parseInt(n, 10)
return if major < 10 or (major is 10 and minor < 18) or (major is 10 and minor is 18 and build < 1)

# Create very simple web server to serve the two files we need.
http = require 'http'
serveFile = (res, fileToServe, mimeType) ->
Expand All @@ -526,29 +515,28 @@ task 'test:browser', 'run the test suite against the modern browser compiler in
else
res.statusCode = 404
res.end()
server.listen 8080

puppeteer = require 'puppeteer'
browser = page = result = null
puppeteer.launch()
.then((browserHandle) ->
browser = browserHandle
browser.newPage()
).then((pageHandle) ->
page = pageHandle
page.goto 'http://localhost:8080/'
).then(->
page.waitForSelector '#result',
visible: yes
polling: 'mutation'
).then((element) ->
page.evaluate ((el) => el.textContent), element
).then((elementText) ->
result = elementText
).finally(->
browser.close()
).finally ->
server.close()

server.listen 8080, ->
puppeteer = require 'puppeteer'
browser = await puppeteer.launch()
page = await browser.newPage()
result = ""

try
await page.goto 'http://localhost:8080/'

element = await page.waitForSelector '#result',
visible: yes
polling: 'mutation'
timeout: 60000

result = await page.evaluate ((el) => el.textContent), element
catch e
log e, red
finally
try browser.close()
server.close()

if result and not result.includes('failed')
log result, green
else
Expand Down