-
Notifications
You must be signed in to change notification settings - Fork 10
/
runners.coffee
91 lines (74 loc) · 2.09 KB
/
runners.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Sandbox = require "./lib/sandbox"
{html, testScripts} = Packager = require "./packager"
{executePackageWrapper} = require "require"
documenter = require "md"
module.exports = (I={}, self) ->
runningInstances = []
self.extend
runPackageInAppWindow: (pkg, popup) ->
navigateToBlobURL popup, html(pkg, executePackageWrapper)
run: ->
popup = Sandbox()
self.build()
.then (pkg) ->
self.runPackageInAppWindow(pkg, popup)
runDocs: ({file}) ->
file ?= "index"
Runner.openWindowWithContent docsConfig,
self.build()
.then (pkg) ->
documenter.documentAll(pkg)
.then (docs) ->
script = docs.first()
path = script.path.split("/")
path.pop()
path.push("#{file}.html")
path = path.join("/")
if file = findFile(path, docs)
file.content + "<script>#{script.content}<\/script>"
else
"Failed to find file at #{path}"
test: ->
popup = Sandbox()
self.build()
.then (pkg) ->
testScripts(pkg)
.then (testScripts) ->
navigateToBlobURL popup, testsHtml(testScripts)
navigateToBlobURL = (popup, htmlSource) ->
blob = new Blob [htmlSource],
type: "text/html; charset=utf-8"
url = URL.createObjectURL(blob)
popup.location.href = url
docsConfig =
width: 1280
height: 800
index = (files) ->
files.filter (file) ->
/index\.html$/.test file.path
.first()
findFile = (path, files) ->
files.filter (file) ->
file.path is path
.first()
testsHtml = (testScripts) -> """
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="https://distri.github.io/tests/assert.js"><\/script>
<script src="https://unpkg.com/[email protected]/mocha.js"><\/script>
<script>mocha.setup('bdd')<\/script>
#{testScripts}
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
<\/script>
</body>
</html>
"""