This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
WIP: add E2E test suite unrelated to docs examples #9557
Closed
+282
−4
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5fe1832
chore(protractor): rename docs e2e test suite with `-docs` suffix
caitp edd2346
chore(package.json): add cheerio dependency
caitp ebb55a8
WIP: implement e2e test harness
caitp a0db029
WIP: also serve static files from test directories
caitp d71f56d
WIP: statSync can throw.
caitp 74e7401
WIP: fix conditional insertion of jquery
caitp b6660eb
WIP: move fixtures into fixtures directory
caitp 2d8a442
WIP: add .jshintrc files for fixtures and tests directory
caitp e120f88
WIP: add protractor grunt task + configs for running E2E specs
caitp 061f178
WIP: add sample tests
caitp 9e68bab
WIP: fix .jshintrc files and add test:e2e task for the basic e2e tests
caitp c9f18d0
WIP: try to run both jquery and non-jquery E2E tests on Travis
caitp c69259e
WIP: gruntfile u_u
caitp f4a8d1a
Kill protractor-e2e configs
caitp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"browser": true, | ||
"globals": { | ||
"angular": false, | ||
"jQuery": false, | ||
"$": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html ng-app="test"> | ||
<div ng-controller="TestCtrl"> | ||
<p>{{text}}</p> | ||
</div> | ||
|
||
<script src="angular.js"></script> | ||
<script src="script.js"></script> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
angular.module("test", []). | ||
controller("TestCtrl", function($scope) { | ||
$scope.text = "Hello, world!"; | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
{% if eq(test.ngAppTag, "html") %} | ||
<html ng-app="{{ test.ngApp }}"> | ||
{% else %} | ||
<html> | ||
{% endif %} | ||
<head> | ||
{% if scripts.jQuery %} | ||
<script src="{{ scripts.jQuery }}"></script> | ||
{% endif %} | ||
{% for script in test.scripts %} | ||
<script src="{{ test.scripts[script] }}"></script> | ||
{% endfor %} | ||
{{ test.head }} | ||
</head> | ||
{% if test.ngAppTag === "body" %} | ||
<body ng-app="{{ test.ngApp }}"> | ||
{% else %} | ||
<body> | ||
{% endif %} | ||
{% test.body %} | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"node": true, | ||
"globals": { | ||
"describe": false, | ||
"ddescribe": false, | ||
"xdescribe": false, | ||
"it": false, | ||
"xit": false, | ||
"iit": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var helper = { | ||
andWaitForAngular: function() { | ||
browser.waitForAngular(); | ||
}, | ||
loadFixture: function(fixture) { | ||
var i = 0; | ||
while (fixture[i] === '/') ++i; | ||
fixture = fixture.slice(i); | ||
if (!/\/(index\.html)?$/.test(fixture)) { | ||
fixture += '/'; | ||
} | ||
|
||
if (process.env.USE_JQUERY) { | ||
fixture += '?jquery'; | ||
} | ||
|
||
browser.get('/e2e/fixtures/' + fixture); | ||
return helper; | ||
} | ||
}; | ||
|
||
global.test = helper; | ||
global.loadFixture = helper.loadFixture; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Sample E2E test: | ||
// | ||
describe('Sample', function() { | ||
beforeEach(function() { | ||
loadFixture("sample").andWaitForAngular(); | ||
}); | ||
|
||
it('should have the interpolated text', function() { | ||
expect(element(by.binding('text')).getText()) | ||
.toBe('Hello, world!'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"node": true | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var $ = require('cheerio'); | ||
var util = require('./util'); | ||
|
||
var root = path.resolve(__dirname, '..'); | ||
var fixtures = path.resolve(root, 'fixtures'); | ||
|
||
var projectRoot = path.resolve(__dirname, '../../..'); | ||
var build = path.resolve(projectRoot, 'build'); | ||
|
||
function rewriteAngularSrc(src, query) { | ||
if (query) { | ||
if (query.build) { | ||
return query.build + '/' + src; | ||
} else if (query.cdn) { | ||
return '//ajax.googleapis.com/ajax/libs/angularjs/' + query.cdn + '/' + src; | ||
} | ||
} | ||
return '/build/' + src; | ||
} | ||
|
||
function generateFixture(test, query) { | ||
var indexFile = path.resolve(fixtures, test, 'index.html'); | ||
var text = fs.readFileSync(indexFile, 'utf8'); | ||
|
||
var $$ = $.load(text); | ||
|
||
var firstScript = null; | ||
var jquery = null; | ||
var angular = null; | ||
$$('script').each(function(i, script) { | ||
var src = $(script).attr('src'); | ||
if (src === 'jquery.js' && jquery === null) jquery = script; | ||
else if (src === 'angular.js' && angular === null) angular = script; | ||
if (firstScript === null) firstScript = script; | ||
if (src) { | ||
var s = util.stat(path.resolve(build, src)); | ||
if (s && s.isFile()) { | ||
$(script).attr('src', rewriteAngularSrc(src, query)); | ||
} else { | ||
$(script).attr('src', util.rewriteTestFile(test, src)); | ||
} | ||
} | ||
}); | ||
|
||
if (jquery && (!('jquery' in query) || (/^(0|no|false|off|n)$/i).test(query.jquery))) { | ||
$(jquery).remove(); | ||
} else if ('jquery' in query) { | ||
if ((/^(0|no|false|off|n)$/i).test(query.jquery)) { | ||
if (jquery) { | ||
$(jquery).remove(); | ||
} | ||
} else { | ||
if (!jquery) { | ||
jquery = $.load('<script></script>')('script')[0]; | ||
if (firstScript) { | ||
$(firstScript).before(jquery); | ||
} else { | ||
var head = $$('head'); | ||
if (head.length) { | ||
head.prepend(jquery); | ||
} else { | ||
$$.root().first().before(jquery); | ||
} | ||
} | ||
} | ||
if (!/^\d+\.\d+.*$/.test(query.jquery)) { | ||
$(jquery).attr('src', '/bower_components/jquery/dist/jquery.js'); | ||
} else { | ||
$(jquery).attr('src', '//ajax.googleapis.com/ajax/libs/jquery/' + query.jquery + '/jquery.js'); | ||
} | ||
} | ||
} | ||
|
||
return $$.html(); | ||
} | ||
|
||
module.exports = { | ||
generate: generateFixture | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
middleware: require('./middleware') | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
var url = require('url'); | ||
var util = require('./util'); | ||
var fixture = require('./fixture'); | ||
|
||
module.exports = middlewareFactory; | ||
|
||
function middlewareFactory(base) { | ||
base = base || '/e2e'; | ||
while (base.length && base[base.length-1] === '/') base = base.slice(0, base.length-1); | ||
var fixture_regexp = new RegExp('^' + base + '/fixtures/([a-zA-Z0-9_-]+)(/(index.html)?)?$'); | ||
var static_regexp = new RegExp('^' + base + '/fixtures/([a-zA-Z0-9_-]+)(/.*)$'); | ||
|
||
return function(req, res, next) { | ||
var match; | ||
var basicUrl = req.url; | ||
var idx = basicUrl.indexOf('?'); | ||
if (idx >= 0) { | ||
basicUrl = basicUrl.slice(0, idx); | ||
} | ||
if ((match = fixture_regexp.exec(basicUrl))) { | ||
if (util.testExists(match[1])) { | ||
try { | ||
var query = url.parse(req.url, true).query; | ||
res.write(fixture.generate(match[1], query)); | ||
res.end(); | ||
} catch (e) { | ||
return next(e); | ||
} | ||
} else { | ||
return next('Fixture ' + match[1] + ' not found.'); | ||
} | ||
} else if ((match = static_regexp.exec(basicUrl))) { | ||
var rewritten = util.rewriteTestFile(match[1], match[2]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended. There are two "base directories", one is the virtual root of E2E tests, and one is the root of the project tree. Static files are served relative to the root of the project tree, so we rewrite relative to that. |
||
if (rewritten !== false) { | ||
req.url = rewritten; | ||
} | ||
next(); | ||
} else { | ||
return next(); | ||
} | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var url = require('url'); | ||
|
||
var root = path.resolve(__dirname, '..'); | ||
var tests = path.resolve(root, 'fixtures'); | ||
|
||
function stat(path) { | ||
try { | ||
return fs.statSync(path); | ||
} catch (e) { | ||
// Ignore ENOENT. | ||
if (e.code !== 'ENOENT') { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
function testExists(testname) { | ||
var s = stat(path.resolve(tests, testname)); | ||
return s && s.isDirectory(); | ||
} | ||
|
||
function rewriteTestFile(testname, testfile) { | ||
var i = 0; | ||
while (testfile[i] === '/') ++i; | ||
testfile = testfile.slice(i); | ||
var s = stat(path.resolve(tests, testname, testfile)); | ||
if (s && (s.isFile() || s.isDirectory())) { | ||
return ['/test/e2e/fixtures', testname, testfile].join('/'); | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = { | ||
stat: stat, | ||
testExists: testExists, | ||
rewriteTestFile: rewriteTestFile | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to have a file level comment of what this does.