Skip to content

Commit 389ce89

Browse files
Run browser tests in headless Chrome; replace Travis and AppVeyor with GitHub Actions (#5298)
1 parent 75d376f commit 389ce89

File tree

8 files changed

+1246
-968
lines changed

8 files changed

+1246
-968
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Based on https://github.com/actions/starter-workflows/blob/master/ci/node.js.yml
2+
3+
name: Build and Test
4+
5+
on:
6+
push
7+
8+
jobs:
9+
ci:
10+
runs-on: ${{ matrix.operating-system }}
11+
12+
strategy:
13+
matrix:
14+
operating-system: [ubuntu-latest, macos-latest, windows-latest]
15+
node-version: [6.x, 8.x, 10.x, 12.x, 14.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
24+
# Puppeteer runs an install script that requires Node 10+.
25+
# Also, the `npm ci` command doesn’t exist on the version of npm that shipped with Node 6.
26+
- run: node --eval "pjson = JSON.parse(require('fs').readFileSync('./package.json')); delete pjson.devDependencies.puppeteer; require('fs').writeFileSync('./package.json', JSON.stringify(pjson), 'utf8')"
27+
if: matrix.node-version == '6.x' || matrix.node-version == '8.x'
28+
- run: npm install
29+
if: matrix.node-version == '6.x'
30+
- run: npm ci
31+
if: matrix.node-version != '6.x'
32+
33+
- run: node ./bin/cake test
34+
- run: node --harmony ./bin/cake test
35+
36+
- run: node ./bin/cake test:browser
37+
if: matrix.node-version != '6.x' && matrix.node-version != '8.x'
38+
39+
- run: node ./bin/cake test:browser:node
40+
41+
- run: node ./bin/cake test:integrations
42+
43+
- run: node ./bin/cake build:except-parser
44+
- run: node ./bin/cake build:parser
45+
- run: node ./bin/cake build:full
46+
- run: node ./bin/cake build:browser

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

Cakefile

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,13 @@ task 'release', 'build and test the CoffeeScript source, and build the documenta
368368
execSync '''
369369
cake build:full
370370
cake build:browser
371+
cake doc:test
372+
cake test:browser:node
371373
cake test:browser
372374
cake test:integrations
373375
cake doc:site
374-
cake doc:test
375-
cake doc:source''', stdio: 'inherit'
376+
cake doc:source
377+
''', stdio: 'inherit'
376378

377379

378380
task 'bench', 'quick benchmark of compilation time', ->
@@ -495,7 +497,65 @@ task 'test', 'run the CoffeeScript language test suite', ->
495497
runTests(CoffeeScript).catch -> process.exit 1
496498

497499

498-
task 'test:browser', 'run the test suite against the merged browser script', ->
500+
task 'test:browser', 'run the test suite against the modern browser compiler in a headless browser', ->
501+
# This test uses Puppeteer to launch headless Chrome to test the ES module
502+
# version of the browser compiler. There’s no reason to run this test in old
503+
# versions of Node (the runtime is the headless Chrome browser, not Node),
504+
# and Puppeteer 3 only supports Node >= 10.18.1, so limit this test to those
505+
# versions. The code below uses `Promise.prototype.finally` because the
506+
# CoffeeScript codebase currently maintains compatibility with Node 6, which
507+
# did not support `async`/`await` syntax. Even though this test doesn’t run
508+
# in Node 6, it needs to still _parse_ in Node 6 so that this file can load.
509+
[major, minor, build] = process.versions.node.split('.').map (n) -> parseInt(n, 10)
510+
return if major < 10 or (major is 10 and minor < 18) or (major is 10 and minor is 18 and build < 1)
511+
512+
# Create very simple web server to serve the two files we need.
513+
http = require 'http'
514+
serveFile = (res, fileToServe, mimeType) ->
515+
res.statusCode = 200
516+
res.setHeader 'Content-Type', mimeType
517+
fs.createReadStream(fileToServe).pipe res
518+
server = http.createServer (req, res) ->
519+
if req.url is '/'
520+
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'test.html'), 'text/html'
521+
else if req.url is '/browser-compiler-modern/coffeescript.js'
522+
# The `text/javascript` MIME type is required for an ES module file to be
523+
# loaded in a browser.
524+
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'browser-compiler-modern', 'coffeescript.js'), 'text/javascript'
525+
else
526+
res.statusCode = 404
527+
res.end()
528+
server.listen 8080
529+
530+
puppeteer = require 'puppeteer'
531+
browser = page = result = null
532+
puppeteer.launch()
533+
.then((browserHandle) ->
534+
browser = browserHandle
535+
browser.newPage()
536+
).then((pageHandle) ->
537+
page = pageHandle
538+
page.goto 'http://localhost:8080/'
539+
).then(->
540+
page.waitFor '#result',
541+
visible: yes
542+
polling: 'mutation'
543+
).then((element) ->
544+
page.evaluate ((el) => el.textContent), element
545+
).then((elementText) ->
546+
result = elementText
547+
).finally(->
548+
browser.close()
549+
).finally ->
550+
server.close()
551+
if result and 'failed' not in result
552+
log result, green
553+
else
554+
log result, red
555+
process.exit 1
556+
557+
558+
task 'test:browser:node', 'run the test suite against the legacy browser compiler in Node', ->
499559
source = fs.readFileSync "lib/coffeescript-browser-compiler-legacy/coffeescript.js", 'utf-8'
500560
result = {}
501561
global.testingBrowser = yes

appveyor.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/v2/test.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ <h1>CoffeeScript Test Suite</h1>
5050
@currentFile = ''
5151
@passedTests = failedTests = total = done = 0
5252

53-
say = (msg, className) ->
53+
say = (msg, className, id) ->
5454
div = document.createElement 'div'
5555
div.className = className if className?
56+
div.id = id if id?
5657
div.appendChild document.createTextNode msg
5758
stdout.appendChild div
5859
msg
@@ -219,7 +220,7 @@ <h1>CoffeeScript Test Suite</h1>
219220
sec = (new Date - start) / 1000
220221
msg = "passed #{passedTests} tests in #{sec.toFixed 2} seconds"
221222
msg = "failed #{total - passedTests} tests and #{msg}" unless yay
222-
say msg, (if yay then 'good' else 'bad')
223+
say msg, (if yay then 'good' else 'bad'), 'result'
223224

224225
gtag 'event', 'tests_complete',
225226
event_category: 'tests'

documentation/site/test.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ <h1>CoffeeScript Test Suite</h1>
5050
@currentFile = ''
5151
@passedTests = failedTests = total = done = 0
5252

53-
say = (msg, className) ->
53+
say = (msg, className, id) ->
5454
div = document.createElement 'div'
5555
div.className = className if className?
56+
div.id = id if id?
5657
div.appendChild document.createTextNode msg
5758
stdout.appendChild div
5859
msg
@@ -137,7 +138,7 @@ <h1>CoffeeScript Test Suite</h1>
137138
sec = (new Date - start) / 1000
138139
msg = "passed #{passedTests} tests in #{sec.toFixed 2} seconds"
139140
msg = "failed #{total - passedTests} tests and #{msg}" unless yay
140-
say msg, (if yay then 'good' else 'bad')
141+
say msg, (if yay then 'good' else 'bad'), 'result'
141142

142143
gtag 'event', 'tests_complete',
143144
event_category: 'tests'

0 commit comments

Comments
 (0)