remote_test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Licensed to the Software Freedom Conservancy (SFC) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The SFC licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. 'use strict';
  18. var assert = require('assert'),
  19. fs = require('fs'),
  20. path = require('path');
  21. var promise = require('../').promise,
  22. io = require('../io'),
  23. cmd = require('../lib/command'),
  24. remote = require('../remote');
  25. const {enablePromiseManager} = require('../lib/test/promise');
  26. describe('DriverService', function() {
  27. describe('start()', function() {
  28. var service;
  29. beforeEach(function() {
  30. service = new remote.DriverService(process.execPath, {
  31. port: 1234,
  32. args: ['-e', 'process.exit(1)']
  33. });
  34. });
  35. afterEach(function() {
  36. return service.kill();
  37. });
  38. it('fails if child-process dies', function() {
  39. this.timeout(1000);
  40. return service.start(500).then(expectFailure, verifyFailure);
  41. });
  42. enablePromiseManager(function() {
  43. describe(
  44. 'failures propagate through control flow if child-process dies',
  45. function() {
  46. it('', function() {
  47. this.timeout(1000);
  48. return promise.controlFlow().execute(function() {
  49. promise.controlFlow().execute(function() {
  50. return service.start(500);
  51. });
  52. }).then(expectFailure, verifyFailure);
  53. });
  54. });
  55. });
  56. function verifyFailure(e) {
  57. assert.ok(!(e instanceof promise.CancellationError));
  58. assert.equal('Server terminated early with status 1', e.message);
  59. }
  60. function expectFailure() {
  61. throw Error('expected to fail');
  62. }
  63. });
  64. });
  65. describe('FileDetector', function() {
  66. class ExplodingDriver {
  67. schedule() {
  68. throw Error('unexpected call');
  69. }
  70. }
  71. it('returns the original path if the file does not exist', function() {
  72. return io.tmpDir().then(dir => {
  73. let theFile = path.join(dir, 'not-there');
  74. return (new remote.FileDetector)
  75. .handleFile(new ExplodingDriver, theFile)
  76. .then(f => assert.equal(f, theFile));
  77. });
  78. });
  79. it('returns the original path if it is a directory', function() {
  80. return io.tmpDir().then(dir => {
  81. return (new remote.FileDetector)
  82. .handleFile(new ExplodingDriver, dir)
  83. .then(f => assert.equal(f, dir));
  84. });
  85. });
  86. it('attempts to upload valid files', function() {
  87. return io.tmpFile().then(theFile => {
  88. return (new remote.FileDetector)
  89. .handleFile(
  90. new (class FakeDriver {
  91. schedule(command) {
  92. assert.equal(command.getName(), cmd.Name.UPLOAD_FILE);
  93. assert.equal(typeof command.getParameters()['file'], 'string');
  94. return Promise.resolve('success!');
  95. }
  96. }),
  97. theFile)
  98. .then(f => assert.equal(f, 'success!'));
  99. });
  100. });
  101. });