Run browser tests in headless Chrome; replace Travis and AppVeyor with GitHub Actions (#5298)

This commit is contained in:
Geoffrey Booth 2020-05-25 21:03:49 -07:00 committed by GitHub
parent 75d376f2ef
commit 389ce89555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1244 additions and 966 deletions

View File

@ -0,0 +1,46 @@
# Based on https://github.com/actions/starter-workflows/blob/master/ci/node.js.yml
name: Build and Test
on:
push
jobs:
ci:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, macos-latest, windows-latest]
node-version: [6.x, 8.x, 10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# Puppeteer runs an install script that requires Node 10+.
# Also, the `npm ci` command doesnt exist on the version of npm that shipped with Node 6.
- run: node --eval "pjson = JSON.parse(require('fs').readFileSync('./package.json')); delete pjson.devDependencies.puppeteer; require('fs').writeFileSync('./package.json', JSON.stringify(pjson), 'utf8')"
if: matrix.node-version == '6.x' || matrix.node-version == '8.x'
- run: npm install
if: matrix.node-version == '6.x'
- run: npm ci
if: matrix.node-version != '6.x'
- run: node ./bin/cake test
- run: node --harmony ./bin/cake test
- run: node ./bin/cake test:browser
if: matrix.node-version != '6.x' && matrix.node-version != '8.x'
- run: node ./bin/cake test:browser:node
- run: node ./bin/cake test:integrations
- run: node ./bin/cake build:except-parser
- run: node ./bin/cake build:parser
- run: node ./bin/cake build:full
- run: node ./bin/cake build:browser

View File

@ -1,22 +0,0 @@
language: node_js
node_js:
- 6
- 8
- 10
- 12
- node # Latest
cache:
directories:
- node_modules
script:
- node ./bin/cake test
- node --harmony ./bin/cake test
- node ./bin/cake test:browser
- node ./bin/cake test:integrations
- node ./bin/cake build:except-parser
- node ./bin/cake build:parser
- node ./bin/cake build:full
- node ./bin/cake build:browser

View File

@ -368,11 +368,13 @@ task 'release', 'build and test the CoffeeScript source, and build the documenta
execSync '''
cake build:full
cake build:browser
cake doc:test
cake test:browser:node
cake test:browser
cake test:integrations
cake doc:site
cake doc:test
cake doc:source''', stdio: 'inherit'
cake doc:source
''', stdio: 'inherit'
task 'bench', 'quick benchmark of compilation time', ->
@ -495,7 +497,65 @@ task 'test', 'run the CoffeeScript language test suite', ->
runTests(CoffeeScript).catch -> process.exit 1
task 'test:browser', 'run the test suite against the merged browser script', ->
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. Theres 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 doesnt 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) ->
res.statusCode = 200
res.setHeader 'Content-Type', mimeType
fs.createReadStream(fileToServe).pipe res
server = http.createServer (req, res) ->
if req.url is '/'
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'test.html'), 'text/html'
else if req.url is '/browser-compiler-modern/coffeescript.js'
# The `text/javascript` MIME type is required for an ES module file to be
# loaded in a browser.
serveFile res, path.join(__dirname, 'docs', "v#{majorVersion}", 'browser-compiler-modern', 'coffeescript.js'), 'text/javascript'
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.waitFor '#result',
visible: yes
polling: 'mutation'
).then((element) ->
page.evaluate ((el) => el.textContent), element
).then((elementText) ->
result = elementText
).finally(->
browser.close()
).finally ->
server.close()
if result and 'failed' not in result
log result, green
else
log result, red
process.exit 1
task 'test:browser:node', 'run the test suite against the legacy browser compiler in Node', ->
source = fs.readFileSync "lib/coffeescript-browser-compiler-legacy/coffeescript.js", 'utf-8'
result = {}
global.testingBrowser = yes

View File

@ -1,30 +0,0 @@
environment:
matrix:
- nodejs_version: '6'
- nodejs_version: '8'
- nodejs_version: '10'
- nodejs_version: '12'
- nodejs_version: '' # Latest
install:
- ps: Install-Product node $env:nodejs_version
- node --version
- npm --version
- npm install
cache:
- node_modules
test_script:
- node ./bin/cake test
- node --harmony ./bin/cake test
- node ./bin/cake test:browser
- node ./bin/cake test:integrations
- node ./bin/cake build:except-parser
- node ./bin/cake build:parser
- node ./bin/cake build:full
- node ./bin/cake build:browser
build: off
version: "{build}"

View File

@ -50,9 +50,10 @@ start = new Date
@currentFile = ''
@passedTests = failedTests = total = done = 0
say = (msg, className) ->
say = (msg, className, id) ->
div = document.createElement 'div'
div.className = className if className?
div.id = id if id?
div.appendChild document.createTextNode msg
stdout.appendChild div
msg
@ -219,7 +220,7 @@ done = ->
sec = (new Date - start) / 1000
msg = "passed #{passedTests} tests in #{sec.toFixed 2} seconds"
msg = "failed #{total - passedTests} tests and #{msg}" unless yay
say msg, (if yay then 'good' else 'bad')
say msg, (if yay then 'good' else 'bad'), 'result'
gtag 'event', 'tests_complete',
event_category: 'tests'

View File

@ -50,9 +50,10 @@ start = new Date
@currentFile = ''
@passedTests = failedTests = total = done = 0
say = (msg, className) ->
say = (msg, className, id) ->
div = document.createElement 'div'
div.className = className if className?
div.id = id if id?
div.appendChild document.createTextNode msg
stdout.appendChild div
msg
@ -137,7 +138,7 @@ done = ->
sec = (new Date - start) / 1000
msg = "passed #{passedTests} tests in #{sec.toFixed 2} seconds"
msg = "failed #{total - passedTests} tests and #{msg}" unless yay
say msg, (if yay then 'good' else 'bad')
say msg, (if yay then 'good' else 'bad'), 'result'
gtag 'event', 'tests_complete',
event_category: 'tests'

2019
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -40,16 +40,17 @@
"url": "git://github.com/jashkenas/coffeescript.git"
},
"devDependencies": {
"@babel/core": "7.7.7",
"@babel/preset-env": "7.7.7",
"babel-preset-minify": "^0.5.1",
"codemirror": "^5.52.0",
"@babel/core": "~7.7.7",
"@babel/preset-env": "~7.7.7",
"babel-preset-minify": "~0.5.1",
"codemirror": "~5.52.0",
"docco": "~0.8.0",
"highlight.js": "^9.18.1",
"jison": "^0.4.18",
"highlight.js": "~9.18.1",
"jison": "~0.4.18",
"markdown-it": "~10.0.0",
"underscore": "^1.9.2",
"webpack": "^4.42.0"
"puppeteer": "~3.1.0",
"underscore": "~1.9.2",
"webpack": "~4.42.0"
},
"dependencies": {}
}