mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
116 lines
3.2 KiB
CoffeeScript
116 lines
3.2 KiB
CoffeeScript
![]() |
util = require "util"
|
||
|
|
||
|
async = require "async"
|
||
|
request = require "request"
|
||
|
zombie = require "zombie"
|
||
|
|
||
|
{CSSLint} = require "csslint"
|
||
|
|
||
|
rules = CSSLint.getRules().filter (rule) -> rule.id is "errors"
|
||
|
CSSLint.clearRules()
|
||
|
CSSLint.addRule r for r in rules
|
||
|
|
||
|
validateCSS = CSSLint.verify
|
||
|
|
||
|
servers =
|
||
|
development: 7000
|
||
|
production: 7001
|
||
|
|
||
|
|
||
|
for type, port of servers then do (type, port) ->
|
||
|
|
||
|
fetchPage = (path) -> ->
|
||
|
jasmine.asyncSpecWait()
|
||
|
@browser = new zombie.Browser()
|
||
|
@httpRoot = "http://localhost:#{ port }"
|
||
|
@browser.visit @httpRoot + path, (err, browser) ->
|
||
|
throw err if err
|
||
|
jasmine.asyncSpecDone()
|
||
|
|
||
|
describe "JS assets in #{ type } server", ->
|
||
|
|
||
|
beforeEach fetchPage "/"
|
||
|
|
||
|
it "Can share plain js files from fs", ->
|
||
|
expect(@browser.window["js fs"]).toEqual true
|
||
|
|
||
|
it "can share raw js strings", ->
|
||
|
expect(@browser.window["raw js"]).toEqual true
|
||
|
|
||
|
it "has no namespaced raw js here", ->
|
||
|
expect(@browser.window["raw namespace js"]).toBeUndefined()
|
||
|
|
||
|
it "Coffee script files get compiled transparently", ->
|
||
|
expect(@browser.window["coffee fs"]).toEqual true
|
||
|
|
||
|
it "addOb adds global variables", ->
|
||
|
expect(@browser.window["addOb global"]).toEqual true
|
||
|
|
||
|
it "addOb does not override namespace objects", ->
|
||
|
expect(@browser.window.namespaceob.second).toEqual true, "second addOb missing"
|
||
|
expect(@browser.window.namespaceob.first).toEqual true, "first addOb missing"
|
||
|
|
||
|
it "js.addExec gets executed", ->
|
||
|
expect(@browser.window["js exec"]).toEqual true
|
||
|
|
||
|
it "addUrl can load assets from remote servers", ->
|
||
|
expect(@browser.window["remote script"]).toEqual true
|
||
|
|
||
|
it "No namespaced js here", ->
|
||
|
expect(@browser.window["namespace"]).toBeUndefined()
|
||
|
|
||
|
|
||
|
describe "Namespaced JS assets in #{ type } server", ->
|
||
|
|
||
|
beforeEach fetchPage "/namespace"
|
||
|
|
||
|
it "We have namaspaced js here", ->
|
||
|
expect(@browser.window["namespace"]).toEqual true
|
||
|
|
||
|
it "We have also global js", ->
|
||
|
expect(@browser.window["js fs"]).toEqual true
|
||
|
|
||
|
it "namespaced js.addExec gets executed", ->
|
||
|
expect(@browser.window["namespace js exec"]).toEqual true
|
||
|
|
||
|
it "can share raw js strings in namespaces", ->
|
||
|
expect(@browser.window["raw namespace js"]).toEqual true
|
||
|
|
||
|
describe "CSS assets in #{ type } server", ->
|
||
|
|
||
|
beforeEach fetchPage "/"
|
||
|
|
||
|
it "We have css links", ->
|
||
|
$ = @browser.window.jQuery
|
||
|
expect($("link[rel='stylesheet']").size()).toBeGreaterThan 0
|
||
|
|
||
|
it "has valid CSS", ->
|
||
|
$ = @browser.window.jQuery
|
||
|
|
||
|
cssUrls = $("link[rel='stylesheet']").map -> this.href
|
||
|
|
||
|
jasmine.asyncSpecWait()
|
||
|
|
||
|
async.reduce cssUrls, "", (memo, path, cb) =>
|
||
|
request @httpRoot + path, (err, res, body) ->
|
||
|
# console.log res.statusCode, path
|
||
|
expect(res.statusCode).toBe 200, "#{ path } is missing"
|
||
|
return cb err if err
|
||
|
cb null, memo + body
|
||
|
, (err, css) ->
|
||
|
expect(err).toBeFalsy()
|
||
|
|
||
|
# Just use csslint to validate that we have sane css here until we come
|
||
|
# up with something better. This will at least confirm that
|
||
|
# preprocessors work.
|
||
|
result = validateCSS css,rules
|
||
|
expect(result.messages.length).toBe 0, "#{ util.inspect result.messages }"
|
||
|
jasmine.asyncSpecDone()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|