Skip to content

Commit 5992e81

Browse files
author
Misko Hevery
committed
added rake task to create a single file for scenario runner
1 parent 2cce1ff commit 5992e81

File tree

8 files changed

+93
-12
lines changed

8 files changed

+93
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ externs.js
33
angular.js
44
angular-minified.js
55
angular-debug.js
6+
angular-scenario.js

Rakefile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include FileUtils
33
task :default => [:compile, :test]
44

55
desc 'Generate Externs'
6-
task :compileexterns do
6+
task :compile_externs do
77
out = File.new("externs.js", "w")
88

99
out.write("function _(){};\n")
@@ -29,9 +29,31 @@ task :compileexterns do
2929
out.close
3030
end
3131

32+
desc 'Compile Scenario'
33+
task :compile_scenario do
34+
concat = %x(cat \
35+
lib/underscore/underscore.js \
36+
lib/jquery/jquery-1.4.2.js \
37+
src/scenario/angular.prefix \
38+
src/Angular.js \
39+
src/JSON.js \
40+
src/scenario/Runner.js \
41+
src/scenario/DSL.js \
42+
src/scenario/angular.suffix \
43+
)
44+
css = %x(cat css/angular-scenario.css)
45+
f = File.new("angular-scenario.js", 'w')
46+
f.write(concat)
47+
f.write('document.write(\'<style type="text/css">\n')
48+
f.write(css.gsub(/'/, "\\'").gsub(/\n/, "\\n"));
49+
f.write('\n</style>\');')
50+
f.close
51+
end
52+
3253
desc 'Compile JavaScript'
3354
task :compile do
34-
Rake::Task['compileexterns'].execute 0
55+
Rake::Task['compile_externs'].execute 0
56+
Rake::Task['compile_scenario'].execute 0
3557

3658
concat = %x(cat \
3759
src/angular.prefix \

scenario/Runner-compiled.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<script type="text/javascript" src="../angular-scenario.js"></script>
5+
<script type="text/javascript" src="widgets-scenario.js"></script>
6+
</head>
7+
<body>
8+
</body>
9+
</html>

src/scenario/DSL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ angular.scenario.dsl.browser = {
55
self.testFrame.load(function(){
66
self.testFrame.unbind();
77
self.testDocument = jQuery(self.testWindow.document);
8+
self.testWindow = self.testFrame[0].contentWindow;
89
done();
910
});
1011
if (this.testFrame.attr('src') == url) {

src/scenario/Runner.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
angular['scenario'] = (angular['scenario'] = {});
2-
angular.scenario['dsl'] = (angular.scenario['dsl'] = {});
1+
angular['scenario'] = angular['scenario'] || (angular['scenario'] = {});
2+
angular.scenario['dsl'] = angular.scenario['dsl'] || (angular.scenario['dsl'] = {});
33

44
angular.scenario.Runner = function(scope, jQuery){
55
var self = scope.$scenario = this;
66
this.scope = scope;
77
this.jQuery = jQuery;
8-
angular.extend(scope, angular.scenario.dsl);
98

109
var specs = this.specs = {};
1110
var path = [];
@@ -30,7 +29,7 @@ angular.scenario.Runner = function(scope, jQuery){
3029
self.currentSpec = null;
3130
};
3231
this.logger = function returnNoop(){
33-
return angular.extend(returnNoop, {close:angular.noop, fail:angular.noop});;
32+
return _(returnNoop).extend({close:_.identity, fail:_.identity});;
3433
};
3534
};
3635

@@ -60,7 +59,7 @@ angular.scenario.Runner.prototype = {
6059
var element = jQuery('<li class="running '+type+'"><span></span></li>');
6160
element.find('span').text(text);
6261
container.append(element);
63-
return angular.extend(logger(element), {
62+
return _(logger(element)).extend({
6463
close: function(){
6564
element.removeClass('running');
6665
if(!element.hasClass('fail'))
@@ -81,7 +80,7 @@ angular.scenario.Runner.prototype = {
8180
}
8281
this.logger = logger(console);
8382
var specNames = [];
84-
angular.foreach(this.specs, function(spec, name){
83+
_(this.specs).each(function(spec, name){
8584
specNames.push(name);
8685
}, this);
8786
specNames.sort();
@@ -109,7 +108,7 @@ angular.scenario.Runner.prototype = {
109108
result.passed = false;
110109
result.failed = true;
111110
result.error = error;
112-
result.log('fail', angular.isString(error) ? error : angular.toJson(error)).fail();
111+
result.log('fail', _(error).isString() ? error : toJson(error)).fail();
113112
}
114113
};
115114
specThis = {
@@ -122,18 +121,19 @@ angular.scenario.Runner.prototype = {
122121
function done() {
123122
result.finished = true;
124123
stepLogger.close();
125-
(callback||angular.noop).call(specThis);
124+
(callback||_.identity).call(specThis);
126125
}
127126
function next(){
128127
var step = spec.steps[spec.nextStepIndex];
129-
(result.log || {close:angular.noop}).close();
128+
(result.log || {close:_.identity}).close();
130129
result.log = null;
131130
if (step) {
132131
spec.nextStepIndex ++;
133132
result.log = stepLogger('step', step.name);
134133
try {
135134
step.fn.call(specThis, next);
136135
} catch (e) {
136+
console.error(e);
137137
result.fail(e);
138138
done();
139139
}

src/scenario/angular.prefix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
(function(window, document, previousOnLoad){
25+
window.angular = {
26+
scenario: {
27+
dsl: window
28+
}
29+
};
30+

src/scenario/angular.suffix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
var $scenarioRunner = new angular.scenario.Runner(window, jQuery);
3+
4+
window.onload = function(){
5+
try {
6+
if (previousOnLoad) previousOnLoad();
7+
} catch(e) {}
8+
$scenarioRunner.run(jQuery(window.document.body));
9+
};
10+
11+
})(window, document, window.onload);

src/scenario/bootstrap.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
document.write('<link rel="stylesheet" type="text/css" href="' + prefix + path + '"/>');
1919
}
2020

21+
window.angular = {
22+
scenario: {
23+
dsl: window
24+
}
25+
};
26+
2127
window.onload = function(){
2228
_.defer(function(){
2329
$scenarioRunner.run(jQuery(window.document.body));
@@ -27,8 +33,9 @@
2733
addCSS("../../css/angular-scenario.css");
2834
addScript("../../lib/underscore/underscore.js");
2935
addScript("../../lib/jquery/jquery-1.4.2.js");
30-
addScript("../angular-bootstrap.js");
3136
addScript("Runner.js");
37+
addScript("../Angular.js");
38+
addScript("../JSON.js");
3239
addScript("DSL.js");
3340
document.write('<script type="text/javascript">' +
3441
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +

0 commit comments

Comments
 (0)