Skip to content

Commit a2ff780

Browse files
committed
chore(e2e): selenium runs on watch AND singlerun now
1 parent 025c61b commit a2ff780

File tree

9 files changed

+173
-25
lines changed

9 files changed

+173
-25
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ notifications:
77
irc: "chat.freenode.net#ui-grid"
88

99
env:
10+
matrix:
11+
- JOB=unit
12+
- JOB=e2e
1013
global:
1114
- SAUCE_USERNAME=nggrid
1215
- SAUCE_CONNECT_READY_FILE=/tmp/sauce-connect-ready
@@ -32,14 +35,11 @@ before_script:
3235
- npm install --quiet -g grunt-cli karma-cli
3336
- npm install
3437
- bower install
38+
- grunt install
3539
- ./lib/sauce/sauce_connect_block.sh
3640

3741
script:
38-
- grunt
39-
# - git config credential.helper "store --file=.git/credentials"
40-
# - echo "https://${GITHUB_NAME}:${GITHUB_PASS}@github.com" > .git/credentials
41-
- grunt test:ci
42-
- grunt release
42+
- ./scripts/travis/travis_build.sh
4343

4444
# after_success:
4545

Gruntfile.js

+78-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,36 @@ module.exports = function(grunt) {
1111
version: util.getVersion(),
1212
stable_version: util.getStableVersion(),
1313
dist: 'dist',
14-
site: process.env.TRAVIS ? 'ui.grid.info' : 'localhost:<%= connect.docs.options.port %>',
14+
site: process.env.TRAVIS ? 'ui-grid.info' : 'localhost:<%= connect.docs.options.port %>',
1515
banner: '/*! <%= pkg.title || pkg.name %> - v<%= version %> - ' +
1616
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
1717
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
1818
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
1919
' Licensed <%= pkg.license %> */\n',
2020

21+
shell: {
22+
options: {
23+
stdout: true
24+
},
25+
selenium: {
26+
command: './selenium/start',
27+
options: {
28+
stdout: false,
29+
async: true
30+
}
31+
},
32+
'protractor-install': {
33+
command: './node_modules/protractor/bin/webdriver-manager update'
34+
},
35+
'protractor-start': {
36+
command: 'node ./node_modules/protractor/bin/webdriver-manager start',
37+
options: {
38+
stdout: true,
39+
async: true
40+
}
41+
}
42+
},
43+
2144
// Clean the temp directory
2245
clean: ['.tmp', '<%= dist %>', 'docs'],
2346

@@ -109,6 +132,30 @@ module.exports = function(grunt) {
109132
}
110133
},
111134

135+
protractor: {
136+
options: {
137+
keepAlive: true,
138+
configFile: "./test/protractor.conf.js"
139+
},
140+
singlerun: {},
141+
auto: {
142+
keepAlive: true,
143+
options: {
144+
args: {
145+
seleniumPort: 4444,
146+
specs: ['.tmp/e2e/**/*.spec.js', 'test/e2e/**/*.spec.js']
147+
}
148+
}
149+
}
150+
// docs: {
151+
// options: {
152+
// args: {
153+
// baseUrl: 'http://localhost:9999'
154+
// }
155+
// }
156+
// }
157+
},
158+
112159
jshint: {
113160
options: {
114161
curly: true,
@@ -176,6 +223,11 @@ module.exports = function(grunt) {
176223
// livereload: true
177224
}
178225
},
226+
protractor: {
227+
files: ['.tmp/e2e/**/*.spec.js', 'test/e2e/**/*.spec.js', '<%= dist %>/docs/**'],
228+
tasks: ['protractor:auto']
229+
},
230+
179231
less: {
180232
files: 'src/**/*.less',
181233
tasks: ['less']
@@ -228,6 +280,12 @@ module.exports = function(grunt) {
228280
base: '<%= dist %>',
229281
livereload: true
230282
}
283+
},
284+
testserver: {
285+
options: {
286+
port: process.env.TEST_PORT || 9999,
287+
base: '<%= dist %>'
288+
}
231289
}
232290
},
233291

@@ -313,9 +371,13 @@ module.exports = function(grunt) {
313371
grunt.loadNpmTasks('grunt-angular-templates');
314372
grunt.loadNpmTasks('grunt-contrib-connect');
315373
grunt.loadNpmTasks('grunt-karma');
374+
grunt.loadNpmTasks('grunt-protractor-runner');
316375
grunt.loadNpmTasks('grunt-ngdocs');
317376
grunt.loadNpmTasks('grunt-conventional-changelog');
318377
grunt.loadNpmTasks('grunt-gh-pages');
378+
grunt.loadNpmTasks('grunt-shell-spawn');
379+
380+
grunt.registerTask('install', ['shell:protractor-install']);
319381

320382
// register before and after test tasks so we don't have to change cli
321383
// options on the CI server
@@ -329,12 +391,18 @@ module.exports = function(grunt) {
329391
// Build with no testing
330392
grunt.registerTask('build', ['concat', 'uglify', 'less', 'ngdocs', 'copy']);
331393

394+
// Auto-test tasks for development
395+
grunt.registerTask('autotest:unit', ['karmangular:start']);
396+
grunt.registerTask('autotest:e2e', ['shell:protractor-start']);
397+
332398
// Development watch task
333-
grunt.registerTask('dev', ['before-test', 'after-test', 'connect', 'karmangular:start', 'watch']);
399+
grunt.registerTask('dev', ['before-test', 'after-test', 'connect', 'autotest:unit', 'autotest:e2e', 'watch']);
334400

335401
// Testing tasks
336402
// grunt.registerTask('test:ci', ['clean', 'jshint', 'ngtemplates', 'karma:sauce']);
337403
grunt.registerTask('test:ci', ['clean', 'jshint', 'ngtemplates', 'serialsauce']);
404+
grunt.registerTask('test:docs', ['connect:', 'protractor:docs']);
405+
grunt.registerTask('test:e2e', ['protractor:singlerun']);
338406

339407
// Test
340408
grunt.registerTask('test', 'Run tests on singleRun karma server', function() {
@@ -349,4 +417,12 @@ module.exports = function(grunt) {
349417
});
350418

351419
grunt.registerTask('release', ['clean', 'build', 'cut-release', 'gh-pages']);
420+
421+
grunt.registerTask('blah', function () {
422+
var ngdoc = require('./node_modules/grunt-ngdocs/src/ngdoc.js');
423+
424+
console.log(ngdoc);
425+
});
426+
427+
grunt.registerTask('butt', ['shell:protractor-start', 'watch:protractor']);
352428
};

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
1. Add banners to compiled .css files (grunt-banner?)
55
1. Add grunt-nuget task to autodeploy builds to nuget
66
1. Try to reomve `npm install` commands from travis before-script
7+
1. Add grunt task that will use ngdoc to build test specs from docs into .tmp/e2e/doc.spec.js
8+
- It will need to run after ngdocs does. Maybe make a `gendocs` task that runs both serially.
79

810
1. [DONE] Add --browsers option for testing on saucelabs with specific browser(s)
911
1. [DONE] Make karmangular run in `watch` mode and in singlerun too.

lib/grunt/plugins.js

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var path = require('path');
33
var util = require('./utils.js');
44
var semver = require('semver');
55
var shell = require('shelljs');
6+
var remote = require('selenium-webdriver/remote');
67

78
module.exports = function(grunt) {
89

@@ -235,4 +236,25 @@ module.exports = function(grunt) {
235236

236237
done();
237238
});
239+
240+
grunt.registerTask('selenium:start', function() {
241+
var done = this.async();
242+
243+
// Get the config from the config file
244+
var configFile = path.resolve(process.cwd(), grunt.config('protractor.options.configFile'));
245+
var config = require(configFile);
246+
247+
var server = new remote.SeleniumServer(config.seleniumServerJar, {
248+
args: config.seleniumArgs,
249+
port: config.seleniumPort
250+
});
251+
252+
// console.log('server', server.start);
253+
254+
server.start().then(function(url) {
255+
grunt.log.writeln('Selenium standalone server started at ' + url);
256+
257+
done();
258+
});
259+
});
238260
};

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
"grunt-gh-pages": "~0.9.0",
5252
"semver": "~2.2.1",
5353
"shelljs": "~0.2.6",
54-
"grunt-contrib-copy": "~0.4.1"
54+
"grunt-contrib-copy": "~0.4.1",
55+
"protractor": "~0.14.0",
56+
"grunt-protractor-runner": "~0.2.0",
57+
"grunt-shell-spawn": "~0.3.0",
58+
"selenium-webdriver": "~2.39.0"
5559
}
5660
}

src/js/directives/ui-grid-style.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111
* Allows us to interpolate expressions in `<style>` elements. Angular doesn't do this by default as it can/will/might? break in IE8.
1212
*
1313
* @example
14-
<example module="app">
15-
<file name="app.js">
16-
var app = angular.module('app', ['ui.grid']);
14+
<doc:example module="app">
15+
<doc:source>
16+
<script>
17+
var app = angular.module('app', ['ui.grid']);
1718
18-
app.controller('MainCtrl', ['$scope', function ($scope) {
19-
$scope.myStyle = '.blah { color: red }';
20-
}]);
21-
</file>
22-
<file name="index.html">
23-
<div ng-controller="MainCtrl">
24-
<style ui-grid-style>{{ myStyle }}</style>
25-
<span class="blah">I am red.</span>
26-
</div>
27-
</file>
28-
</example>
19+
app.controller('MainCtrl', ['$scope', function ($scope) {
20+
$scope.myStyle = '.blah { color: red }';
21+
}]);
22+
</script>
23+
24+
<div ng-controller="MainCtrl">
25+
<style ui-grid-style>{{ myStyle }}</style>
26+
<span class="blah">I am red.</span>
27+
</div>
28+
</doc:source>
29+
<doc:scenario>
30+
it('should do stuff!', function () {
31+
32+
});
33+
</doc:scenario>
34+
</doc:example>
2935
*/
3036

3137
var app = angular.module('ui.grid.style', []);

test/e2e/test.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
describe('angularjs homepage', function() {
2+
3+
});

test/protractor.conf.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// An example configuration file.
2+
exports.config = {
3+
// The address of a running selenium server.
4+
5+
// seleniumAddress: 'http://localhost:4444/wd/hub',
6+
seleniumServerJar: '../node_modules/protractor/selenium/selenium-server-standalone-2.37.0.jar',
7+
seleniumPort: 4444,
8+
9+
// Capabilities to be passed to the webdriver instance.
10+
capabilities: {
11+
'browserName': 'chrome'
12+
},
13+
14+
// A base URL for your application under test. Calls to protractor.get()
15+
// with relative paths will be prepended with this.
16+
// baseUrl: 'http://localhost:9999',
17+
18+
// Spec patterns are relative to the location of the spec file. They may
19+
// include glob patterns.
20+
// specs: ['./e2e/**/*.spec.js'],
21+
22+
// Options to be passed to Jasmine-node.
23+
jasmineNodeOpts: {
24+
showColors: true, // Use colors in the command line report.
25+
26+
// Default time to wait in ms before a test fails.
27+
defaultTimeoutInterval: 20000
28+
}
29+
};

travis_build.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
set -e
44

5-
# export SAUCE_ACCESS_KEY=`echo $SAUCE_ACCESS_KEY | rev`
6-
7-
grunt test:ci
5+
if [ $JOB = "unit" ]; then
6+
grunt
7+
grunt test:ci
8+
grunt release
9+
elif [ $JOB = "e2e" ]; then
10+
# grunt clean build test:e2e --browsers=SL_Chrome
11+
else
12+
echo "Unknown job type. Please set JOB=unit or JOB=e2e."
13+
fi

0 commit comments

Comments
 (0)