1 |
|
2 | 'use strict';
|
3 |
|
4 | var fs = require('fs'),
|
5 | es = require('event-stream'),
|
6 | expect = require('expect.js'),
|
7 | sinon = require('sinon'),
|
8 | path = require('path');
|
9 |
|
10 | require('mocha');
|
11 |
|
12 | var gutil = require('gulp-util'),
|
13 | protractor = require('../').protractor,
|
14 | webdriver = require('../').webdriver,
|
15 | getProtractorDir = require('../').getProtractorDir,
|
16 | getProtractorCli = require('../').getProtractorCli,
|
17 | child_process = require('child_process'),
|
18 | events = require('events');
|
19 |
|
20 | var winExt = /^win/.test(process.platform) ? '.cmd' : '';
|
21 |
|
22 |
|
23 | describe('gulp-protractor: getProtractorDir', function() {
|
24 |
|
25 | it('should find the protractor installation', function(done) {
|
26 | expect(getProtractorDir()).to.equal(path.resolve('./node_modules/.bin'));
|
27 | done();
|
28 | });
|
29 | });
|
30 |
|
31 | describe('gulp-protractor: getProtractorCli', function() {
|
32 |
|
33 | it('should find the protractor cli.js', function(done) {
|
34 | expect(getProtractorCli()).to.equal(path.resolve('./node_modules/protractor/built/cli.js'));
|
35 | done();
|
36 | });
|
37 | });
|
38 |
|
39 | describe('gulp-protractor: protractor', function() {
|
40 |
|
41 | it('should pass in the args into the protractor call', function(done) {
|
42 | var fakeProcess = new events.EventEmitter();
|
43 | var spy = sinon.stub(child_process, 'fork', function(cmd, args, options) {
|
44 |
|
45 | expect(path.basename(cmd)).to.equal('cli.js');
|
46 | expect(path.basename(args[0])).to.equal('protractor.config.js');
|
47 | expect(args[1]).to.equal('--browser');
|
48 | expect(args[2]).to.equal('Chrome');
|
49 | expect(args[3]).to.equal('--chrome-only');
|
50 | child_process.fork.restore();
|
51 | done();
|
52 |
|
53 | return new events.EventEmitter();
|
54 | });
|
55 | var srcFile = new gutil.File({
|
56 | path: 'test/fixtures/test.js',
|
57 | cwd: 'test/',
|
58 | base: 'test/fixtures',
|
59 | contents: null
|
60 | });
|
61 |
|
62 | var stream = protractor({
|
63 | configFile: 'test/fixtures/protractor.config.js',
|
64 | args: [
|
65 | '--browser', 'Chrome',
|
66 | '--chrome-only'
|
67 | ]
|
68 | });
|
69 |
|
70 | stream.write(srcFile);
|
71 | stream.end();
|
72 | });
|
73 |
|
74 | it('should pass the test-files to protractor via arg', function(done) {
|
75 | var fakeProcess = new events.EventEmitter();
|
76 | var spy = sinon.stub(child_process, 'fork', function(cmd, args, options) {
|
77 |
|
78 | expect(path.basename(cmd)).to.equal('cli.js');
|
79 | expect(path.basename(args[0])).to.equal('protractor.config.js');
|
80 | expect(args[1]).to.equal('--specs');
|
81 | expect(args[2]).to.equal('test/fixtures/test.js');
|
82 |
|
83 | child_process.fork.restore();
|
84 | done();
|
85 |
|
86 | return new events.EventEmitter();
|
87 | });
|
88 |
|
89 | var srcFile = new gutil.File({
|
90 | path: 'test/fixtures/test.js',
|
91 | cwd: 'test/',
|
92 | base: 'test/fixtures',
|
93 | contents: null
|
94 | });
|
95 |
|
96 | var stream = protractor({
|
97 | configFile: 'test/fixtures/protractor.config.js'
|
98 | });
|
99 |
|
100 | stream.write(srcFile);
|
101 | stream.end();
|
102 |
|
103 | });
|
104 |
|
105 | it('shouldnt pass the test-files to protractor if there are none', function(done) {
|
106 | var spy = sinon.stub(child_process, 'fork', function(cmd, args, options) {
|
107 |
|
108 | expect(path.basename(cmd)).to.equal('cli.js');
|
109 | expect(path.basename(args[0])).to.equal('protractor.config.js');
|
110 | expect(args[1]).to.be(undefined);
|
111 | expect(args[2]).to.be(undefined);
|
112 |
|
113 | child_process.fork.restore();
|
114 | done();
|
115 |
|
116 | return new events.EventEmitter();
|
117 | });
|
118 |
|
119 | var srcFile = new gutil.File({
|
120 | path: 'test/fixtures/test.js',
|
121 | cwd: 'test/',
|
122 | base: 'test/fixtures',
|
123 | contents: null
|
124 | });
|
125 |
|
126 | var stream = protractor({
|
127 | configFile: 'test/fixtures/protractor.config.js'
|
128 | });
|
129 |
|
130 | stream.end();
|
131 |
|
132 | });
|
133 |
|
134 | it('should propogate protractor exit code', function(done) {
|
135 | var fakeProcess = new events.EventEmitter();
|
136 | var spy = sinon.stub(child_process, 'fork', function(cmd, args, options) {
|
137 | child_process.fork.restore();
|
138 | process.nextTick(function() { fakeProcess.emit('exit', 255) });
|
139 | fakeProcess.kill = function() { };
|
140 | return fakeProcess;
|
141 | });
|
142 |
|
143 | var srcFile = new gutil.File({
|
144 | path: 'test/fixtures/test.js',
|
145 | cwd: 'test/',
|
146 | base: 'test/fixtures',
|
147 | contents: null
|
148 | });
|
149 |
|
150 | var stream = protractor({
|
151 | configFile: 'test/fixtures/protractor.config.js'
|
152 | });
|
153 |
|
154 | stream.write(srcFile);
|
155 | stream.end();
|
156 | stream.on('error', function(err) {
|
157 | done();
|
158 | });
|
159 | });
|
160 | });
|
161 |
|
162 |
|
163 | describe('gulp-protractor: webdriver', function() {
|
164 |
|
165 | it.skip('should call update and then start on the webdriver-manager', function(done) {
|
166 |
|
167 | var fakeProcess = new events.EventEmitter();
|
168 | var seconds_call = false;
|
169 | var spy = sinon.stub(child_process, 'spawn', function(cmd, args, options) {
|
170 | expect(path.basename(cmd)).to.equal('webdriver-manager' + winExt);
|
171 | if (!seconds_call) {
|
172 | expect(args[0]).to.equal('update');
|
173 | } else {
|
174 | expect(args[0]).to.equal('start');
|
175 | child_process.spawn.restore();
|
176 | done();
|
177 | }
|
178 | return fakeProcess;
|
179 | });
|
180 |
|
181 | var wd = webdriver();
|
182 | setTimeout(function() {
|
183 | seconds_call = true;
|
184 | fakeProcess.emit('close');
|
185 | }, 100);
|
186 |
|
187 |
|
188 | });
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | });
|