Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/adapters/TelnetAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@

describe('connect', () => {
it('does not crash and triggers shutdown when the socket errors after the connection is established', async () => {
// Stub pressHomeButton so we don't need a real device
sinon.stub(rokuDeploy, 'pressHomeButton').resolves();
// Stub keyPress so we don't need a real device
sinon.stub(rokuDeploy, 'keyPress').resolves();

Check failure on line 261 in src/adapters/TelnetAdapter.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"keyPress"' is not assignable to parameter of type 'keyof RokuDeploy'.
// Stub Socket.prototype.connect so it doesn't attempt a real connection.
// The callback is invoked synchronously to simulate a successful connection.
sinon.stub(Socket.prototype, 'connect').callsFake(function(this: Socket, ...args: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/TelnetAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
try {
this.logger.log('Pressing home button');
//force roku to return to home screen. This gives the roku adapter some security in knowing new messages won't be appearing during initialization
await rokuDeploy.pressHomeButton(this.options.host, this.options.remotePort);
await rokuDeploy.keyPress({ device: { host: this.options.host }, key: 'home', ecpPort: this.options.remotePort });

Check failure on line 273 in src/adapters/TelnetAdapter.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'keyPress' does not exist on type 'RokuDeploy'.
let telnetSocket: Socket = new Socket({ allowHalfOpen: false });
util.registerSocketLogging(telnetSocket, this.logger, 'TelnetSocket');

Expand Down
61 changes: 29 additions & 32 deletions src/debugSession/BrightScriptDebugSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,21 @@

//mock the rokuDeploy module with promises so we can have predictable tests
session.rokuDeploy = <any>{
prepublishToStaging: () => {
stage: () => {
return Promise.resolve();
},
zipPackage: () => {
zip: () => {
return Promise.resolve();
},
pressHomeButton: () => {
keyPress: () => {
return Promise.resolve();
},
publish: () => {
sideload: () => {
return Promise.resolve();
},
createPackage: () => {
createSignedPackage: () => {
return Promise.resolve();
},
deploy: () => {
return Promise.resolve();
},
getOptions: () => {
},
getFilePaths: () => {
}
};
Expand Down Expand Up @@ -203,11 +198,13 @@
let sendEvent = session.sendEvent.bind(session);
sinon.stub(session, 'sendEvent').callsFake((event) => {
if (isCustomRequestEvent(event)) {
void rokuDeploy.zipFolder(session['launchConfiguration'].stagingDir, packagePath).then(() => {
void rokuDeploy.zip({ dir: session['launchConfiguration'].stagingDir, out: packagePath }).then(() => {

Check failure on line 201 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'zip' does not exist on type 'RokuDeploy'.
//pretend we are the client and send a response back
session.emit(ClientToServerCustomEventName.customRequestEventResponse, {
requestId: event.body.requestId
});
}, (e) => {
console.error('Failed to zip the staging folder', e);
});
} else {
//call through
Expand All @@ -220,7 +217,7 @@
return Promise.resolve(session['rokuAdapter']);
});

const publishStub = sinon.stub(session.rokuDeploy, 'publish').callsFake(() => {
const publishStub = sinon.stub(session.rokuDeploy, 'sideload').callsFake(() => {

Check failure on line 220 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.
//emit the app-ready event
(session['rokuAdapter'] as TelnetAdapter)['emit']('app-ready');

Expand All @@ -234,6 +231,7 @@
cwd: tempDir,
//where the source files reside
rootDir: rootDir,
files: DefaultFiles,
//where roku-debug should put the staged files (and inject breakpoints)
stagingDir: `${stagingDir}/staging`,
//the name of the task that should be run to create the zip (doesn't matter for this test...we're going to intercept it anyway)
Expand Down Expand Up @@ -1262,7 +1260,7 @@
// - https://github.com/rokucommunity/vscode-brightscript-language/issues/807 (EHOSTDOWN)
// - https://github.com/rokucommunity/roku-debug/issues/332 (ECONNREFUSED)
//@vscode/debugadapter dispatches disconnectRequest without awaiting the returned Promise
//(debugSession.js:391), so any rejection from `await this.rokuDeploy.pressHomeButton(...)`
//(debugSession.js:391), so any rejection from the `await this.rokuDeploy.keyPress(...)` home press
//becomes an unhandled rejection that crashes the DAP process. When the device is powered
//off / unreachable at disconnect time, the ECP connect attempt fails — the specific Node
//error code depends on the OS-level reason (host unresponsive vs. connection refused).
Expand All @@ -1273,7 +1271,7 @@
host: '192.168.1.17',
remotePort: 8060
};
session.rokuDeploy.pressHomeButton = () => Promise.reject(rejection);
session.rokuDeploy.keyPress = () => Promise.reject(rejection);

Check failure on line 1274 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Property 'keyPress' does not exist on type 'RokuDeploy'.
//stub shutdown so the test doesn't tear down the whole session machinery
sinon.stub(session, 'shutdown').resolves();
}
Expand Down Expand Up @@ -1879,8 +1877,8 @@
it('installs libraries sequentially when marked install=true', async () => {
stubDefaults();
const installOrder = [];
const publishStub = sinon.stub(rokuDeploy, 'publish').callsFake(async (options) => {
installOrder.push(options.outFile);
const publishStub = sinon.stub(rokuDeploy, 'sideload').callsFake(async (options) => {

Check failure on line 1880 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.
installOrder.push(path.basename(options.zip));
await util.sleep(10);
return { message: 'success', results: [] };
});
Expand All @@ -1897,8 +1895,8 @@
it('skips libraries where install is not true', async () => {
stubDefaults();
const installOrder = [];
const publishStub = sinon.stub(rokuDeploy, 'publish').callsFake(async (options) => {
installOrder.push(options.outFile);
const publishStub = sinon.stub(rokuDeploy, 'sideload').callsFake(async (options) => {

Check failure on line 1898 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.
installOrder.push(path.basename(options.zip));
await util.sleep(10);
return { message: 'success', results: [] };
});
Expand All @@ -1917,24 +1915,25 @@

it('sends proper form data for installation', async () => {
stubDefaults();
const publishStub = sinon.stub(rokuDeploy, 'publish').resolves({ message: 'success', results: [] });
const publishStub = sinon.stub(rokuDeploy, 'sideload').resolves({ message: 'success', results: [] });

Check failure on line 1918 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.

await runPrepareAndHost([
{ rootDir: complib1Dir, outFile: 'testLib.zip', install: true }
] as any, 8080);

expect(publishStub.getCall(0).args[0]).to.include({
host: '192.168.1.100',
const options = publishStub.getCall(0).args[0];
expect(options).to.include({
password: 'test123',
username: 'rokudev',
outFile: 'testLib.zip',
appType: 'dcl'
});
expect(options.device).to.eql({ host: '192.168.1.100' });
expect(path.basename(options.zip)).to.equal('testLib.zip');
});

it('logs error when publish fails and includes lib index', async () => {
stubDefaults();
sinon.stub(rokuDeploy, 'publish').rejects(new Error('Network error'));
sinon.stub(rokuDeploy, 'sideload').rejects(new Error('Network error'));

Check failure on line 1936 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.

await runPrepareAndHost([
{ rootDir: complib1Dir, outFile: 'lib1.zip', install: true }
Expand All @@ -1961,8 +1960,8 @@
events.push(`zip-${this['outFile']}`);
await util.sleep(1);
});
sinon.stub(rokuDeploy, 'publish').callsFake((options) => {
events.push(`install-${options.outFile}`);
sinon.stub(rokuDeploy, 'sideload').callsFake((options) => {

Check failure on line 1963 in src/debugSession/BrightScriptDebugSession.spec.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Argument of type '"sideload"' is not assignable to parameter of type 'keyof RokuDeploy'.
events.push(`install-${path.basename(options.zip)}`);
return Promise.resolve({ message: 'success', results: [] });
});

Expand Down Expand Up @@ -2042,7 +2041,7 @@
it('handles packagePath and packageUploadOverrides for component libraries', async () => {
stubDefaults();
const installOrder = [];
sinon.stub(rokuDeploy, 'publish').callsFake(async (options) => {
sinon.stub(rokuDeploy, 'sideload').callsFake(async (options) => {
installOrder.push(options);
await util.sleep(10);
return { message: 'success', results: [] };
Expand Down Expand Up @@ -2076,13 +2075,11 @@

expect(installOrder.length).to.equal(2);
expect(installOrder[0]).to.include({
outFile: path.basename(s`${tempDir}/custom/cl1.zip`),
outDir: path.dirname(s`${tempDir}/custom/cl1.zip`),
zip: s`${tempDir}/custom/cl1.zip`,
packageUploadOverrides: packageUploadOverrides1
});
expect(installOrder[1]).to.include({
outFile: path.basename(s`${tempDir}/custom/cl2.zip`),
outDir: path.dirname(s`${tempDir}/custom/cl2.zip`),
zip: s`${tempDir}/custom/cl2.zip`,
packageUploadOverrides: packageUploadOverrides2
});
});
Expand Down Expand Up @@ -3050,7 +3047,7 @@
setupLaunchStubs();
// Override the publish stub to throw a CompileError
(session as any).publish.restore();
sinon.stub(session as any, 'publish').rejects(new CompileError('compile failed', [], {} as any));
sinon.stub(session as any, 'publish').rejects(new CompileError('compile failed'));
session['initRequestArgs'].supportsProgressReporting = true;

await session.launchRequest({} as any, launchConfiguration);
Expand Down Expand Up @@ -3103,7 +3100,7 @@
const clock = sinon.useFakeTimers();
const shutdownStub = sinon.stub(session, 'shutdown').resolves() as unknown as SinonStub;
rokuAdapter.connected = false;
sinon.stub(session.rokuDeploy, 'publish').resolves();
sinon.stub(session.rokuDeploy, 'sideload').resolves();

const publishPromise = (session as any).publish();

Expand Down
Loading
Loading