Skip to content

Commit 0c39954

Browse files
author
Christoph Burgmer
committedMar 6, 2014
Introduce script loader
1 parent a14df83 commit 0c39954

File tree

5 files changed

+52
-27
lines changed

5 files changed

+52
-27
lines changed
 

‎Gruntfile.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ module.exports = function (grunt) {
77
},
88
jasmine: {
99
src: [
10-
'node_modules/rasterizehtml/dist/rasterizeHTML.allinone.js',
11-
'node_modules/imagediff/imagediff.js',
1210
'node_modules/jssha/src/sha.js',
13-
'src/utils.js',
14-
'src/phantomjsrenderer.js',
15-
'src/browserrenderer.js',
16-
'src/domstorage.js',
17-
'src/<%= pkg.name %>.js',
18-
'src/basichtmlreporter.js',
11+
'csscritic.js',
1912
'src/terminalreporter.js',
2013
'src/signoffreporter.js'
2114
],

‎RegressionRunner.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
<title>Regression Runner</title>
55
<meta charset="utf-8"/>
66

7-
<link rel="stylesheet" type="text/css" href="dist/csscritic.min.css">
7+
<script src="csscritic.js"></script>
88

9-
<script type="text/javascript" src="dist/csscritic.allinone.js"></script>
10-
11-
<script type="text/javascript">
9+
<script>
1210
window.onload = function() {
1311
csscritic.addReporter(csscritic.BasicHTMLReporter());
1412
csscritic.add('test/ui/failingTest.html');
@@ -25,9 +23,7 @@
2523
csscritic.execute();
2624
};
2725
</script>
28-
2926
</head>
30-
3127
<body>
3228
</body>
3329
</html>

‎csscritic.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* CSS Critic loader
3+
*
4+
* Just include
5+
* <script src="csscritic.js"></script>
6+
* and you are good to go.
7+
*/
8+
(function () {
9+
var thisFileName = 'csscritic.js',
10+
cssDependencies = [
11+
'src/basichtmlreporter.css'
12+
],
13+
jsDependencies = [
14+
'node_modules/rasterizehtml/dist/rasterizeHTML.allinone.js',
15+
'node_modules/imagediff/imagediff.js',
16+
'src/utils.js',
17+
'src/basichtmlreporter.js',
18+
'src/browserrenderer.js',
19+
'src/domstorage.js',
20+
'src/csscritic.js'
21+
];
22+
23+
var getBasePath = function () {
24+
var script = document.querySelector('script[src*="' + thisFileName + '"]'),
25+
src = script.attributes.src.value;
26+
27+
return src.substring(0, src.indexOf(thisFileName));
28+
};
29+
30+
var loadCssDependency = function (path) {
31+
document.write('<link rel="stylesheet" href="' + path + '">');
32+
};
33+
34+
var loadJsDependency = function (path) {
35+
document.write('<script src="' + path + '"></script>');
36+
};
37+
38+
var basePath = getBasePath();
39+
40+
cssDependencies.forEach(function (path) {
41+
loadCssDependency(basePath + path);
42+
});
43+
jsDependencies.forEach(function (path) {
44+
loadJsDependency(basePath + path);
45+
});
46+
}());

‎example/RegressionRunner.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
<title>Regression Runner</title>
55
<meta charset="utf-8"/>
66

7-
<link rel="stylesheet" type="text/css" href="../dist/csscritic.min.css">
7+
<script src="../csscritic.js"></script>
88

9-
<script type="text/javascript" src="../dist/csscritic.allinone.js"></script>
10-
11-
<script type="text/javascript">
9+
<script>
1210
window.onload = function() {
1311
csscritic.addReporter(csscritic.BasicHTMLReporter());
1412
csscritic.add('pageUnderTest.html');
1513
csscritic.execute();
1614
};
1715
</script>
18-
1916
</head>
20-
2117
<body>
2218
<button onclick="localStorage.clear(); window.location.reload();">Reset all tests</button>
2319
</body>

‎test/SpecRunner.html

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@
1414
<script src="helpers.js"></script>
1515

1616
<!-- include source files here... -->
17-
<script src="../node_modules/rasterizehtml/dist/rasterizeHTML.allinone.js"></script>
18-
<script src="../node_modules/imagediff/imagediff.js"></script>
1917
<script src="../node_modules/jssha/src/sha.js"></script>
20-
<script src="../src/utils.js"></script>
21-
<script src="../src/browserrenderer.js"></script>
22-
<script src="../src/domstorage.js"></script>
23-
<script src="../src/csscritic.js"></script>
24-
<script src="../src/basichtmlreporter.js"></script>
18+
<script src="../csscritic.js"></script>
2519
<script src="../src/terminalreporter.js"></script>
2620
<script src="../src/signoffreporter.js"></script>
2721

0 commit comments

Comments
 (0)
Please sign in to comment.