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

Commit b6c42d5

Browse files
committed
feat(docs): adding the <doc:protractor> ngdoc-tag
This is the first step in migrating tests from <doc:scenario> to <doc:protractor>. In-documentation examples with doc:protractor sections will have their contents output to a tab on the docs site as well as output to a standalone test file in build/docs/ptore2e.
1 parent 1c045f1 commit b6c42d5

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

docs/src/example.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ var makeUnique = {
66
'script.js': true,
77
'unit.js': true,
88
'spec.js': true,
9-
'scenario.js': true
9+
'scenario.js': true,
10+
'protractorTest.js': true
1011
}
1112

1213
function ids(list) {
1314
return list.map(function(item) { return item.id; }).join(' ');
1415
};
1516

1617

17-
exports.Example = function(scenarios) {
18+
exports.Example = function(scenarios, protractorTests) {
1819
this.module = '';
1920
this.deps = ['angular.js'];
2021
this.html = [];
@@ -24,6 +25,8 @@ exports.Example = function(scenarios) {
2425
this.unit = [];
2526
this.scenario = [];
2627
this.scenarios = scenarios;
28+
this.protractorTest = [];
29+
this.protractorTests = protractorTests;
2730
}
2831

2932
exports.Example.prototype.setModule = function(module) {
@@ -44,6 +47,10 @@ exports.Example.prototype.addSource = function(name, content) {
4447
var ext = name == 'scenario.js' ? 'scenario' : name.split('.')[1],
4548
id = name;
4649

50+
if (name == 'protractorTest.js') {
51+
ext = 'protractorTest';
52+
}
53+
4754
if (makeUnique[name] && usedIds[id]) {
4855
id = name + '-' + (seqCount++);
4956
}
@@ -56,6 +63,9 @@ exports.Example.prototype.addSource = function(name, content) {
5663
if (ext == 'scenario') {
5764
this.scenarios.push(content);
5865
}
66+
if (ext == 'protractorTest') {
67+
this.protractorTests.push(content);
68+
}
5969
};
6070

6171
exports.Example.prototype.enableAnimations = function() {
@@ -92,6 +102,7 @@ exports.Example.prototype.toHtmlEdit = function() {
92102
out.push(' source-edit-json="' + ids(this.json) + '"');
93103
out.push(' source-edit-unit="' + ids(this.unit) + '"');
94104
out.push(' source-edit-scenario="' + ids(this.scenario) + '"');
105+
out.push(' source-edit-protractor="' + ids(this.protractorTest) + '"');
95106
out.push('></div>\n');
96107
return out.join('');
97108
};
@@ -107,6 +118,7 @@ exports.Example.prototype.toHtmlTabs = function() {
107118
htmlTabs(this.json);
108119
htmlTabs(this.unit);
109120
htmlTabs(this.scenario);
121+
htmlTabs(this.protractorTest);
110122
out.push('</div>');
111123
return out.join('');
112124

@@ -119,7 +131,8 @@ exports.Example.prototype.toHtmlTabs = function() {
119131
if (name === 'index.html') {
120132
wrap = ' ng-html-wrap="' + self.module + ' ' + self.deps.join(' ') + '"';
121133
}
122-
if (name == 'scenario.js') name = 'End to end test';
134+
if (name == 'scenario.js') name = 'ngScenario e2e test';
135+
if (name == 'protractorTest.js') name = 'Protractor e2e test';
123136

124137
out.push(
125138
'<div class="tab-pane" title="' + name + '">\n' +

docs/src/gen-docs.js

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ writer.makeDir('build/docs/', true).then(function() {
1717
return writer.makeDir('build/docs/components/bootstrap');
1818
}).then(function() {
1919
return writer.makeDir('build/docs/components/font-awesome');
20+
}).then(function() {
21+
return writer.makeDir('build/docs/e2etests');
2022
}).then(function() {
2123
console.log('Generating AngularJS Reference Documentation...');
2224
return reader.collect();
@@ -53,6 +55,10 @@ writer.makeDir('build/docs/', true).then(function() {
5355
var id = doc.id.replace('angular.Module', 'angular.IModule');
5456

5557
fileFutures.push(writer.output('partials/' + doc.section + '/' + id + '.html', doc.html()));
58+
// If it has a sample Protractor test, output that as well.
59+
if (doc.protractorTests.length) {
60+
fileFutures.push(writer.output('ptore2e/' + doc.section + '/' + id + '_test.js', ngdoc.writeProtractorTest(doc)));
61+
}
5662
});
5763

5864
ngdoc.checkBrokenLinks(docs);

docs/src/ngdoc.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var lookupMinerrMsg = function (doc) {
3535
exports.trim = trim;
3636
exports.metadata = metadata;
3737
exports.scenarios = scenarios;
38+
exports.writeProtractorTest = writeProtractorTest;
3839
exports.merge = merge;
3940
exports.checkBrokenLinks = checkBrokenLinks;
4041
exports.Doc = Doc;
@@ -155,6 +156,7 @@ function Doc(text, file, line) {
155156
this.line = line;
156157
}
157158
this.scenarios = this.scenarios || [];
159+
this.protractorTests = this.protractorTests || [];
158160
this.requires = this.requires || [];
159161
this.param = this.param || [];
160162
this.properties = this.properties || [];
@@ -292,7 +294,7 @@ Doc.prototype = {
292294
replace(/<example(?:\s+module="([^"]*)")?(?:\s+deps="([^"]*)")?(\s+animations="true")?>([\s\S]*?)<\/example>/gmi,
293295
function(_, module, deps, animations, content) {
294296

295-
var example = new Example(self.scenarios);
297+
var example = new Example(self.scenarios, self.protractorTests);
296298
if(animations) {
297299
example.enableAnimations();
298300
example.addDeps('angular-animate.js');
@@ -329,7 +331,7 @@ Doc.prototype = {
329331
}).
330332
replace(/^<doc:example(\s+[^>]*)?>([\s\S]*)<\/doc:example>/mi, function(_, attrs, content) {
331333
var html, script, scenario,
332-
example = new Example(self.scenarios);
334+
example = new Example(self.scenarios, self.protractorTests);
333335

334336
example.setModule((attrs||'module=""').match(/^\s*module=["'](.*)["']\s*$/)[1]);
335337
content.
@@ -347,6 +349,8 @@ Doc.prototype = {
347349
}).
348350
replace(/(<doc:scenario>)([\s\S]*)(<\/doc:scenario>)/mi, function(_, before, content){
349351
example.addSource('scenario.js', content);
352+
}).replace(/(<doc:protractor>)([\s\S]*)(<\/doc:protractor>)/mi, function(_, before, content){
353+
example.addSource('protractorTest.js', content);
350354
});
351355

352356
return placeholder(example.toHtml());
@@ -1106,6 +1110,22 @@ function scenarios(docs){
11061110
}
11071111
}
11081112

1113+
function writeProtractorTest(doc){
1114+
var lines = [];
1115+
lines.push('describe("' + doc.section + '/' + doc.id + '", function() {');
1116+
lines.push(' beforeEach(function() {');
1117+
lines.push(' browser.get("index-nocache.html#!/' + doc.section + '/' + doc.id + '");');
1118+
lines.push(' });');
1119+
lines.push('');
1120+
doc.protractorTests.forEach(function(test){
1121+
lines.push(indentCode(trim(test), 2));
1122+
lines.push('');
1123+
});
1124+
lines.push('});');
1125+
lines.push('');
1126+
return lines.join('\n');
1127+
}
1128+
11091129

11101130
//////////////////////////////////////////////////////////
11111131
function metadata(docs){

src/ng/directive/ngEventDirs.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
</button>
2121
count: {{count}}
2222
</doc:source>
23-
<doc:scenario>
23+
<doc:protractor>
2424
it('should check ng-click', function() {
25-
expect(binding('count')).toBe('0');
26-
element('.doc-example-live :button').click();
27-
expect(binding('count')).toBe('1');
25+
expect(element(by.binding('count')).getText()).toMatch('0');
26+
element(by.css('.doc-example-live button')).click();
27+
expect(element(by.binding('count')).getText()).toMatch('1');
2828
});
29-
</doc:scenario>
29+
</doc:protractor>
3030
</doc:example>
3131
*/
3232
/*

0 commit comments

Comments
 (0)