Skip to content

Commit 5b1ed52

Browse files
committed
selenium option added
1 parent 38b0b41 commit 5b1ed52

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

gulpfile.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ var knownOptions = {
3333
'default': { 'section': false }
3434
}
3535

36-
var options = minimist(process.argv.slice(2), knownOptions);
36+
/* test server options 'phantom' or 'selenium' */
37+
var testServer = 'phantom'; // default is phantom
3738

39+
var options = minimist(process.argv.slice(2), knownOptions);
3840
gulp.task("test:visual:update", function() {
3941
gulp.src(styleguidePath, { read: false })
4042
.pipe(sc5StyleguideGemini.gather({
@@ -46,6 +48,7 @@ gulp.task("test:visual:update", function() {
4648
gridScreenshotsDir: testDirPath + '/grid-screenshots',
4749
rootUrl: 'http://localhost:3000/',
4850
sections: options.section,
51+
testServer: testServer,
4952
coreTest: '../../custom-tests/core-test.js',
5053
customTests: {
5154
'2.1': '../../custom-tests/custom-test.js'
@@ -72,6 +75,7 @@ gulp.task("test:visual", function(done){
7275
gridScreenshotsDir: testDirPath + '/grid-screenshots',
7376
rootUrl: 'http://localhost:3000/',
7477
sections: options.section,
78+
testServer: testServer,
7579
coreTest: '../../custom-tests/core-test.js',
7680
customTests: {
7781
'2.1': '../../custom-tests/custom-test.js'

src/index.es6

+29-13
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,35 @@ let removeDuplicates = (arr, newArr = []) => {
1313
return newArr;
1414
};
1515

16-
var phantomProcess;
17-
var runPhantom = function() {
16+
var serverProcess;
17+
18+
var runTestServer = function runTestServer(testServer) {
19+
20+
if (!testServer) {
21+
testServer = 'phantom';
22+
}
23+
24+
console.log('Test server:', testServer.toUpperCase());
25+
26+
// Run test server
27+
if (testServer === 'phantom') {
1828
var phantomSource = require('phantomjs-prebuilt').path;
1929

2030
// If the path we're given by phantomjs is to a .cmd, it is pointing to a global copy on Windows.
2131
// Using the cmd as the process to execute causes problems cleaning up the processes
2232
// so we walk from the cmd to the phantomjs.exe and use that instead.
23-
if(path.extname(phantomSource).toLowerCase() === '.cmd') {
24-
phantomSource = path.join(path.dirname(phantomSource), '//node_modules//phantomjs//lib//phantom//phantomjs.exe');
33+
if (path.extname(phantomSource).toLowerCase() === '.cmd') {
34+
phantomSource = path.join(path.dirname(phantomSource), '//node_modules//phantomjs//lib//phantom//phantomjs.exe');
2535
}
2636

27-
phantomProcess = spawn(phantomSource, ['--webdriver', '4444', '--disk-cache', 'false', '--ignore-ssl-errors', 'true'], {setsid:true});
28-
phantomProcess.stdout.pipe(process.stdout);
37+
serverProcess = spawn(phantomSource, ['--webdriver', '4444', '--disk-cache', 'false', '--ignore-ssl-errors', 'true'], { setsid: true });
38+
serverProcess.stdout.pipe(process.stdout);
39+
}
40+
41+
if(testServer === 'selenium') {
42+
serverProcess = spawn('selenium-standalone', ['start'], { setsid: true, detached:true });
43+
serverProcess.stdout.pipe(process.stdout);
44+
}
2945
};
3046

3147
var getGemini = function(options) {
@@ -97,9 +113,9 @@ module.exports.test = function(options) {
97113
var test = function(file, enc, callback) {
98114

99115
var gemini = getGemini(options);
100-
101-
// Run PhantomJs
102-
runPhantom();
116+
117+
// Run test server
118+
runTestServer(options.testServer);
103119

104120
// Clean report
105121
fs.removeSync(options.reportDir + '/*');
@@ -114,7 +130,7 @@ module.exports.test = function(options) {
114130
tempDir: options.reportDir
115131
});
116132
runTestsPromise.done(result => {
117-
phantomProcess.kill('SIGTERM');
133+
serverProcess.kill('SIGTERM');
118134
spawn('open', [`${options.reportDir}/index.html`]).on('error', function() {});
119135
});
120136
};
@@ -238,8 +254,8 @@ module.exports.gather = function(options) {
238254

239255
var gemini = getGemini(options);
240256

241-
// Run PhantomJs
242-
runPhantom();
257+
// Run test server
258+
runTestServer(options.testServer);
243259

244260
// Clean screenshot
245261
if (!options.sections) { // only for full replacement
@@ -254,7 +270,7 @@ module.exports.gather = function(options) {
254270
reporters: ['flat'],
255271
})
256272
.done(result => {
257-
phantomProcess.kill('SIGTERM');
273+
serverProcess.kill('SIGTERM');
258274
});
259275
}
260276
// TODO: remake with promises

tests/custom-tests/core-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var gemini = require('gemini');
4-
53
module.exports = function (page) {
64
gemini.suite(page.name, function (suite) {
75
if (page.name === 'index') {

tests/custom-tests/custom-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var gemini = require('gemini');
4-
53
module.exports = function (page) {
64
gemini.suite(page.name, function (suite) {
75
suite.setUrl(page.url).setCaptureElements('body').capture('plain', function (actions, find) {

0 commit comments

Comments
 (0)