Skip to content

Commit

Permalink
Add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-Holbrook committed Nov 20, 2024
1 parent 70e5231 commit 4551d78
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 42 deletions.
107 changes: 67 additions & 40 deletions src/debugSession/BrightScriptDebugSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ describe('BrightScriptDebugSession', () => {
});
});

describe('setExceptionBreakPointsRequestSets', () => {
describe('setExceptionBreakpoints', () => {
let response;
let args;
beforeEach(() => {
response = {
seq: 0,
Expand All @@ -457,15 +458,13 @@ describe('BrightScriptDebugSession', () => {
command: "setExceptionBreakpoints",
success: true,
}
args = {
filters: undefined,
filterOptions: undefined
}
});
it('both caught and uncaught filters', async function() {
let args = {
filters: [],
filterOptions: [
{ filterId: "caught" },
{ filterId: "uncaught" }
],
}
args.filters = ["caught", "uncaught"]
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

Expand All @@ -476,22 +475,13 @@ describe('BrightScriptDebugSession', () => {
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([
{
filter: 'caught',
conditionExpression: undefined
},
{
filter: 'uncaught',
conditionExpression: undefined
}
{ filter: 'caught' },
{ filter: 'uncaught' }
]);
});

it('set uncaught filters', async function() {
let args = {
filters: [],
filterOptions: [{ filterId: "uncaught" }],
}
args.filters = ["uncaught"]
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

Expand All @@ -502,18 +492,12 @@ describe('BrightScriptDebugSession', () => {
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([
{
filter: 'uncaught',
conditionExpression: undefined
}
{ filter: 'uncaught' }
]);
});

it('set caught filter', async function() {
let args = {
filters: [],
filterOptions: [{ filterId: "caught" }],
}
args.filters = ["caught"]
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

Expand All @@ -524,18 +508,27 @@ describe('BrightScriptDebugSession', () => {
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([
{
filter: 'caught',
conditionExpression: undefined
}
{ filter: 'caught' }
]);
});

it('set zero filters', async function() {
let args = {
filters: [],
filterOptions: [],
}
args.filters = []
args.filterOptions = []
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

await session['setExceptionBreakPointsRequest'](response, args);

expect(response.body.breakpoints).to.eql([
{ verified: true },
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([]);
});

it.only('set filters with bad values', async function() {
args.filters = ['garbage']
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

Expand All @@ -549,10 +542,6 @@ describe('BrightScriptDebugSession', () => {
});

it('fails to set filters', async function() {
let args = {
filters: [],
filterOptions: [],
}
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => {
throw new Error('error')
Expand All @@ -566,6 +555,44 @@ describe('BrightScriptDebugSession', () => {
]);
});

it('sets filters with conditions', async function() {
args.filterOptions = [{ filterId: "caught", condition: "a > 1" }]
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

await session['setExceptionBreakPointsRequest'](response, args);

expect(response.body.breakpoints).to.eql([
{ verified: true },
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([
{
filter: 'caught',
conditionExpression: 'a > 1'
}
]);
});

it('resets filters when the app closes', async function() {
args.filters = ['caught', 'uncaught']
sinon.stub(session, 'getRokuAdapter' as keyof BrightScriptDebugSession).callsFake(async () => { });
const stub = sinon.stub(rokuAdapter, 'setExceptionBreakpoints').callsFake(async (filters) => { });

await session['setExceptionBreakPointsRequest'](response, args);
expect(response.body.breakpoints).to.eql([
{ verified: true },
{ verified: true }
]);
expect(stub.firstCall.args[0]).to.eql([
{ filter: 'caught' },
{ filter: 'uncaught' }
]);
expect(session['exceptionBreakpointFilters']).to.eql([
{ filter: 'caught' },
{ filter: 'uncaught' }
]);
});
});

describe('evaluating variable', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ export class BrightScriptDebugSession extends BaseDebugSession {
protected async setExceptionBreakPointsRequest(response: DebugProtocol.SetExceptionBreakpointsResponse, args: DebugProtocol.SetExceptionBreakpointsArguments) {
response.body ??= {};
try {
//ensure the rokuAdapter is loaded
await this.getRokuAdapter();

let filterOptions: ExceptionBreakpointFilter[];
if (args.filterOptions) {
Expand All @@ -257,6 +255,9 @@ export class BrightScriptDebugSession extends BaseDebugSession {
}
this.exceptionBreakpointFilters = filterOptions

//ensure the rokuAdapter is loaded
await this.getRokuAdapter();

await this.rokuAdapter.setExceptionBreakpoints(filterOptions);
//if success
response.body.breakpoints = [
Expand Down

0 comments on commit 4551d78

Please sign in to comment.