Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

JSTD adapter for running e2e tests #337

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<a name="0.9.16"><a/>
# <angular/> 0.9.16 weather-control (in-progress) #

### Features
- we can run scenario tests with jstd (from command line and in multiple browsers)


### Breaking changes
- html scenario runner requires ng:autotest option to start tests automatically


<a name="0.9.15"><a/>
Expand Down
32 changes: 29 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ANGULAR_SCENARIO = [
'src/scenario/output/Html.js',
'src/scenario/output/Json.js',
'src/scenario/output/Xml.js',
'src/scenario/output/Object.js',
'src/scenario/output/Object.js'
]

BUILD_DIR = 'build'
Expand Down Expand Up @@ -94,6 +94,30 @@ task :compile_scenario => :init do
end
end

desc 'Compile JSTD Scenario Adapter'
task :compile_jstd_scenario_adapter => :init do

deps = [
'src/jstd-scenario-adapter/angular.prefix',
'src/jstd-scenario-adapter/Adapter.js',
'src/jstd-scenario-adapter/angular.suffix',
]

concat = 'cat ' + deps.flatten.join(' ')

File.open(path_to('jstd-scenario-adapter.js'), 'w') do |f|
f.write(%x{#{concat}})
end

# TODO(vojta) use jstd configuration when implemented
# (instead of including jstd-adapter-config.js)
File.open(path_to('jstd-scenario-adapter-config.js'), 'w') do |f|
f.write("/**\r\n" +
" * Configuration for jstd scenario adapter \n */\n" +
"var jstdScenarioAdapter = {\n relativeUrlPrefix: '/build/docs/'\n};\n")
end
end


desc 'Generate IE css js patch'
task :generate_ie_compat => :init do
Expand Down Expand Up @@ -152,7 +176,7 @@ end


desc 'Compile JavaScript'
task :compile => [:init, :compile_scenario, :generate_ie_compat] do
task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter, :generate_ie_compat] do

deps = [
'src/angular.prefix',
Expand Down Expand Up @@ -195,7 +219,9 @@ task :package => [:clean, :compile, :docs] do
path_to('angular.js'),
path_to('angular.min.js'),
path_to('angular-ie-compat.js'),
path_to('angular-scenario.js')
path_to('angular-scenario.js'),
path_to('jstd-scenario-adapter.js'),
path_to('jstd-scenario-adapter-config.js'),
].each do |src|
dest = src.gsub(/^[^\/]+\//, '').gsub(/((\.min)?\.js)$/, "-#{version}\\1")
FileUtils.cp(src, pkg_dir + '/' + dest)
Expand Down
8 changes: 4 additions & 4 deletions docs/cookbook.deeplinking.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ In this example we have a simple app which consist of two screens:

The two partials are defined in the following URLs:

* {@link ./static/settings.html}
* {@link ./static/welcome.html}
* {@link ./examples/settings.html}
* {@link ./examples/welcome.html}


<doc:example>
Expand All @@ -44,8 +44,8 @@ The two partials are defined in the following URLs:
AppCntl.$inject = ['$route']
function AppCntl($route) {
// define routes
$route.when("", {template:'./static/welcome.html', controller:WelcomeCntl});
$route.when("/settings", {template:'./static/settings.html', controller:SettingsCntl});
$route.when("", {template:'./examples/welcome.html', controller:WelcomeCntl});
$route.when("/settings", {template:'./examples/settings.html', controller:SettingsCntl});
$route.parent(this);

// initialize the model to something useful
Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions docs/src/gen-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ var writes = callback.chain(function(){
var metadata = ngdoc.metadata(docs);
writer.output('docs-keywords.js', ['NG_PAGES=', JSON.stringify(metadata).replace(/{/g, '\n{'), ';'], writes.waitFor());
writer.copyDir('img', writes.waitFor());
writer.copyDir('static', writes.waitFor());
writer.copy('index.html', writes.waitFor());
writer.copy('docs.js', writes.waitFor());
writer.copy('docs.css', writes.waitFor());
writer.copy('doc_widgets.js', writes.waitFor());
writer.copy('doc_widgets.css', writes.waitFor());
writer.copy('docs-scenario.html', writes.waitFor());
writer.copyDir('examples', writes.waitFor());
writer.copyTpl('index.html', writes.waitFor());
writer.copyTpl('docs.js', writes.waitFor());
writer.copyTpl('docs.css', writes.waitFor());
writer.copyTpl('doc_widgets.js', writes.waitFor());
writer.copyTpl('doc_widgets.css', writes.waitFor());
writer.copyTpl('docs-scenario.html', writes.waitFor());
writer.output('docs-scenario.js', ngdoc.scenarios(docs), writes.waitFor());
writer.output('sitemap.xml', new SiteMap(docs).render(), writes.waitFor());
writer.output('robots.txt', 'Sitemap: http://docs.angularjs.org/sitemap.xml\n', writes.waitFor());
writer.copy('syntaxhighlighter/shBrushJScript.js', writes.waitFor());
writer.copy('syntaxhighlighter/shBrushXml.js', writes.waitFor());
writer.copy('syntaxhighlighter/shCore.css', writes.waitFor());
writer.copy('syntaxhighlighter/shCore.js', writes.waitFor());
writer.copy('syntaxhighlighter/shThemeDefault.css', writes.waitFor());
writer.copy('jquery.min.js', writes.waitFor());
writer.copyTpl('syntaxhighlighter/shBrushJScript.js', writes.waitFor());
writer.copyTpl('syntaxhighlighter/shBrushXml.js', writes.waitFor());
writer.copyTpl('syntaxhighlighter/shCore.css', writes.waitFor());
writer.copyTpl('syntaxhighlighter/shCore.js', writes.waitFor());
writer.copyTpl('syntaxhighlighter/shThemeDefault.css', writes.waitFor());
writer.copyTpl('jquery.min.js', writes.waitFor());
});
writes.onDone(function(){
console.log('DONE. Generated ' + docs.length + ' pages in ' +
Expand Down
2 changes: 1 addition & 1 deletion docs/src/templates/docs-scenario.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns:ng="http://angularjs.org" wiki:ng="http://angularjs.org">
<head>
<title>&lt;angular/&gt; Docs Scenario Runner</title>
<script type="text/javascript" src="../angular-scenario.js" ng:autobind></script>
<script type="text/javascript" src="../angular-scenario.js" ng:autotest></script>
<script type="text/javascript" src="docs-scenario.js"></script>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ exports.makeDir = function (path, callback) {
})();
};

exports.copy = function(filename, callback){
exports.copyTpl = function(filename, callback) {
copy('docs/src/templates/' + filename, OUTPUT_DIR + filename, callback);
};

Expand Down
2 changes: 1 addition & 1 deletion example/personalLog/scenario/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Personal Log Scenario Runner</title>
<script type="text/javascript" src="../../../src/scenario/angular-bootstrap.js"></script>
<script type="text/javascript" src="../../../src/scenario/angular-bootstrap.js" ng:autotest></script>
<script type="text/javascript" src="personalLogScenario.js"></script>
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions example/personalLog/test/personalLogSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('example.personalLog.LogCtrl', function() {
beforeEach(function() {
logCtrl = createNotesCtrl();
});


it('should initialize notes with an empty array', function() {
expect(logCtrl.logs).toEqual([]);
Expand All @@ -28,7 +28,7 @@ describe('example.personalLog.LogCtrl', function() {
it('should add newMsg to logs as a log entry', function() {
logCtrl.newMsg = 'first log message';
logCtrl.addLog();

expect(logCtrl.logs.length).toBe(1);
expect(logCtrl.logs[0].msg).toBe('first log message');

Expand Down
10 changes: 10 additions & 0 deletions jsTestDriver-scenario.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
server: http://localhost:9877

load:
- build/angular-scenario.js
- build/jstd-scenario-adapter-config.js
- build/jstd-scenario-adapter.js
- build/docs/docs-scenario.js

proxy:
- {matcher: "*", server: "http://localhost:8000"}
2 changes: 2 additions & 0 deletions jsTestDriver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ load:
- test/testabilityPatch.js
- src/scenario/Scenario.js
- src/scenario/output/*.js
- src/jstd-scenario-adapter/*.js
- src/scenario/*.js
- src/angular-mocks.js
- test/mocks.js
- test/scenario/*.js
- test/scenario/output/*.js
- test/jstd-scenario-adapter/*.js
- test/*.js
- test/service/*.js
- example/personalLog/test/*.js
Expand Down
2 changes: 1 addition & 1 deletion scenario/Runner-compiled.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="../build/angular-scenario.js"></script>
<script type="text/javascript" src="../build/angular-scenario.js" ng:autotest></script>
<script type="text/javascript" src="widgets-scenario.js"></script>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion scenario/Runner.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="../src/scenario/angular-bootstrap.js"></script>
<script type="text/javascript" src="../src/scenario/angular-bootstrap.js" ng:autotest></script>
<script type="text/javascript" src="widgets-scenario.js"></script>
</head>
<body>
Expand Down
8 changes: 4 additions & 4 deletions scenario/datastore-scenarios.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
angular.scenarioDef.datastore = {
$before:[
{Given:"dataset",
{Given:"dataset",
dataset:{
Book:[{$id:'moby', name:"Moby Dick"},
Book:[{$id:'moby', name:"Moby Dick"},
{$id:'gadsby', name:'Great Gadsby'}]
}
},
{Given:"browser", at:"datastore.html#book=moby"},
],
checkLoadBook:[
{Then:"drainRequestQueue"},

{Then:"text", at:"{{book.$id}}", should_be:"moby"},
{Then:"text", at:"li[$index=0] {{book.name}}", should_be:"Great Gahdsby"},
{Then:"text", at:"li[$index=0] {{book.name}}", should_be:"Moby Dick"},

]
};
3 changes: 3 additions & 0 deletions server-scenario.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

java -jar lib/jstestdriver/JsTestDriver.jar --port 9877 --browserTimeout 90000 --config jsTestDriver-scenario.conf
15 changes: 10 additions & 5 deletions src/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ var XHR = window.XMLHttpRequest || function () {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e3) {}
throw new Error("This browser does not support XMLHttpRequest.");
};

// default xhr headers
var XHR_HEADERS = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json, text/plain, */*",
"X-Requested-With": "XMLHttpRequest"
DEFAULT: {
"Accept": "application/json, text/plain, */*",
"X-Requested-With": "XMLHttpRequest"
},
POST: {'Content-Type': 'application/x-www-form-urlencoded'}
};

/**
Expand Down Expand Up @@ -103,8 +107,9 @@ function Browser(window, document, body, XHR, $log) {
} else {
var xhr = new XHR();
xhr.open(method, url, true);
forEach(extend(XHR_HEADERS, headers || {}), function(value, key){
if (value) xhr.setRequestHeader(key, value);
forEach(extend({}, XHR_HEADERS.DEFAULT, XHR_HEADERS[uppercase(method)] || {}, headers || {}),
function(value, key) {
if (value) xhr.setRequestHeader(key, value);
});
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
Expand Down
Loading