@@ -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
378380task ' 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
0 commit comments