1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | 'use strict';
|
19 |
|
20 | var assert = require('assert'),
|
21 | fs = require('fs'),
|
22 | path = require('path');
|
23 |
|
24 | var promise = require('../').promise,
|
25 | io = require('../io'),
|
26 | cmd = require('../lib/command'),
|
27 | remote = require('../remote');
|
28 |
|
29 | const {enablePromiseManager} = require('../lib/test/promise');
|
30 |
|
31 | describe('DriverService', function() {
|
32 | describe('start()', function() {
|
33 | var service;
|
34 |
|
35 | beforeEach(function() {
|
36 | service = new remote.DriverService(process.execPath, {
|
37 | port: 1234,
|
38 | args: ['-e', 'process.exit(1)']
|
39 | });
|
40 | });
|
41 |
|
42 | afterEach(function() {
|
43 | return service.kill();
|
44 | });
|
45 |
|
46 | it('fails if child-process dies', function() {
|
47 | this.timeout(1000);
|
48 | return service.start(500).then(expectFailure, verifyFailure);
|
49 | });
|
50 |
|
51 | enablePromiseManager(function() {
|
52 | describe(
|
53 | 'failures propagate through control flow if child-process dies',
|
54 | function() {
|
55 | it('', function() {
|
56 | this.timeout(1000);
|
57 |
|
58 | return promise.controlFlow().execute(function() {
|
59 | promise.controlFlow().execute(function() {
|
60 | return service.start(500);
|
61 | });
|
62 | }).then(expectFailure, verifyFailure);
|
63 | });
|
64 | });
|
65 | });
|
66 |
|
67 | function verifyFailure(e) {
|
68 | assert.ok(!(e instanceof promise.CancellationError));
|
69 | assert.equal('Server terminated early with status 1', e.message);
|
70 | }
|
71 |
|
72 | function expectFailure() {
|
73 | throw Error('expected to fail');
|
74 | }
|
75 | });
|
76 | });
|
77 |
|
78 | describe('FileDetector', function() {
|
79 | class ExplodingDriver {
|
80 | schedule() {
|
81 | throw Error('unexpected call');
|
82 | }
|
83 | }
|
84 |
|
85 | it('returns the original path if the file does not exist', function() {
|
86 | return io.tmpDir(dir => {
|
87 | let theFile = path.join(dir, 'not-there');
|
88 | return (new remote.FileDetector)
|
89 | .handleFile(new ExplodingDriver, theFile)
|
90 | .then(f => assert.equal(f, theFile));
|
91 | });
|
92 | });
|
93 |
|
94 | it('returns the original path if it is a directory', function() {
|
95 | return io.tmpDir(dir => {
|
96 | return (new remote.FileDetector)
|
97 | .handleFile(new ExplodingDriver, dir)
|
98 | .then(f => assert.equal(f, dir));
|
99 | });
|
100 | });
|
101 |
|
102 | it('attempts to upload valid files', function() {
|
103 | return io.tmpFile(theFile => {
|
104 | return (new remote.FileDetector)
|
105 | .handleFile(
|
106 | new (class FakeDriver {
|
107 | schedule(command) {
|
108 | assert.equal(command.getName(), cmd.Name.UPLOAD_FILE);
|
109 | assert.equal(typeof command.getParameters()['file'], 'string');
|
110 | return Promise.resolve('success!');
|
111 | }
|
112 | }),
|
113 | theFile)
|
114 | .then(f => assert.equal(f, 'success!'));
|
115 | });
|
116 | });
|
117 | });
|