Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { util, standardizePath as s } from './util';
import type { FileEntry, RokuDeployOptions } from './RokuDeployOptions';
import { cwd, expectPathExists, expectPathNotExists, expectThrowsAsync, outDir, rootDir, stagingDir, tempDir, writeFiles } from './testUtils.spec';
import { createSandbox } from 'sinon';
import * as request from 'request';
const sinon = createSandbox();

describe('index', () => {
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('index', () => {
describe('doPostRequest', () => {
it('should not throw an error for a successful request', async () => {
let body = 'responseBody';
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, undefined, { statusCode: 200 }, body);
return {} as any;
});
Expand All @@ -93,7 +94,7 @@ describe('index', () => {

it('should throw an error for a network error', async () => {
let error = new Error('Network Error');
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, error);
return {} as any;
});
Expand All @@ -109,7 +110,7 @@ describe('index', () => {

it('should throw an error for a wrong response code if verify is true', async () => {
let body = 'responseBody';
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, undefined, { statusCode: 500 }, body);
return {} as any;
});
Expand All @@ -125,7 +126,7 @@ describe('index', () => {

it('should not throw an error for a response code if verify is false', async () => {
let body = 'responseBody';
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, undefined, { statusCode: 500 }, body);
return {} as any;
});
Expand All @@ -138,7 +139,7 @@ describe('index', () => {
describe('doGetRequest', () => {
it('should not throw an error for a successful request', async () => {
let body = 'responseBody';
sinon.stub(rokuDeploy.request, 'get').callsFake((_, callback) => {
sinon.stub(request, 'get').callsFake((_, callback) => {
process.nextTick(callback, undefined, { statusCode: 200 }, body);
return {} as any;
});
Expand All @@ -149,7 +150,7 @@ describe('index', () => {

it('should throw an error for a network error', async () => {
let error = new Error('Network Error');
sinon.stub(rokuDeploy.request, 'get').callsFake((_, callback) => {
sinon.stub(request, 'get').callsFake((_, callback) => {
process.nextTick(callback, error);
return {} as any;
});
Expand Down Expand Up @@ -570,7 +571,7 @@ describe('index', () => {
describe('pressHomeButton', () => {
it('rejects promise on error', () => {
//intercept the post requests
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, new Error());
return {} as any;
});
Expand Down Expand Up @@ -704,7 +705,7 @@ describe('index', () => {

it('throws when package upload fails', async () => {
//intercept the post requests
sinon.stub(rokuDeploy.request, 'post').callsFake((data: any, callback: any) => {
sinon.stub(request, 'post').callsFake((data: any, callback: any) => {
if (data.url === `http://${options.host}/plugin_install`) {
process.nextTick(() => {
callback(new Error('Failed to publish to server'));
Expand Down Expand Up @@ -993,7 +994,7 @@ describe('index', () => {
let error = new Error('Network Error');
try {
//intercept the post requests
sinon.stub(rokuDeploy.request, 'post').callsFake((_, callback) => {
sinon.stub(request, 'post').callsFake((_, callback) => {
process.nextTick(callback, error);
return {} as any;
});
Expand Down Expand Up @@ -2349,17 +2350,17 @@ describe('index', () => {
sinon.stub(rokuDeploy.fsExtra, 'createWriteStream').returns(null);

//intercept the http request
sinon.stub(rokuDeploy.request, 'get').callsFake(() => {
let request: any = {
sinon.stub(request, 'get').callsFake(() => {
let req: any = {
on: (event, callback) => {
process.nextTick(() => {
onHandler(event, callback);
});
return request;
return req;
},
pipe: () => { }
};
return request;
return req;
});

});
Expand Down
8 changes: 3 additions & 5 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class RokuDeploy {
private logger: Logger;
//store the import on the class to make testing easier

public request = request;

public fsExtra = _fsExtra;

/**
Expand Down Expand Up @@ -637,7 +635,7 @@ export class RokuDeploy {
let writeStream: _fsExtra.WriteStream;
return new Promise<string>((resolve, reject) => {
writeStream = this.fsExtra.createWriteStream(pkgFilePath);
this.request.get(requestOptions)
request.get(requestOptions)
.on('error', (err) => {
try {
writeStream.close();
Expand All @@ -661,7 +659,7 @@ export class RokuDeploy {
*/
private async doPostRequest(params: any, verify = true) {
let results: { response: any; body: any } = await new Promise((resolve, reject) => {
this.request.post(params, (err, resp, body) => {
request.post(params, (err, resp, body) => {
if (err) {
return reject(err);
}
Expand All @@ -680,7 +678,7 @@ export class RokuDeploy {
*/
private async doGetRequest(params: any) {
let results: { response: any; body: any } = await new Promise((resolve, reject) => {
this.request.get(params, (err, resp, body) => {
request.get(params, (err, resp, body) => {
if (err) {
return reject(err);
}
Expand Down