Skip to content

Commit

Permalink
fixup! tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Dec 17, 2019
1 parent b5f490f commit 4eac739
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/adapter/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,16 @@ export class BreakpointManager {
}

/**
* Gets whether the breakpoint ID was an automatically set 'instrumentation'
* breakpoint.
* Notifies the breakpoint manager that a breakpoint was hit. If the
* breakpoint ID was an entry breakpoint, this'll return `true`.
*/
public isModuleEntryBreakpoint(breakpointId: Cdp.Debugger.BreakpointId) {
for (const b of this.moduleEntryBreakpoints.values()) {
if (b.cdpIds.includes(breakpointId)) {
public tryResolveModuleEntryBreakpoint(breakpointId: Cdp.Debugger.BreakpointId) {
for (const bp of this.moduleEntryBreakpoints.values()) {
if (bp.cdpIds.includes(breakpointId)) {
// we intentionally don't remove the record from the map; it's kept as
// an indicator that it did exist and was hit, so that if further
// breakpoints are set in the file it doesn't get re-applied.
bp.remove();
return true;
}
}
Expand Down Expand Up @@ -863,11 +867,7 @@ export class BreakpointManager {
return;
}

const bp = new Breakpoint(this, 0, source, {
line: 1,
column: 1,
});

const bp = new Breakpoint(this, 0, source, { line: 1 });
this.moduleEntryBreakpoints.set(source.path, bp);
this._setBreakpoint(bp, thread);
}
Expand Down
18 changes: 14 additions & 4 deletions src/adapter/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from './sources';
import { StackFrame, StackTrace } from './stackTrace';
import { VariableStore, IVariableStoreDelegate } from './variables';
import { bisectArray } from '../common/objUtils';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -559,14 +560,23 @@ export class Thread implements IVariableStoreDelegate {
}

private async _onPaused(event: Cdp.Debugger.PausedEvent) {
const isSourceMapPause =
(event.reason === 'instrumentation' && event.data?.scriptId) ||
event.hitBreakpoints?.some(b => this._breakpointManager.isModuleEntryBreakpoint(b));
let isSourceMapPause = event.reason === 'instrumentation' && event.data?.scriptId;
if (event.hitBreakpoints) {
let entryBps: string[];
[entryBps, event.hitBreakpoints] = bisectArray(event.hitBreakpoints, b =>
this._breakpointManager.tryResolveModuleEntryBreakpoint(b),
);
isSourceMapPause = isSourceMapPause || entryBps.length > 0;
}

if (isSourceMapPause) {
const location = event.callFrames[0].location;
const scriptId = event.data?.scriptId || location.scriptId;
const remainPaused = await this._handleSourceMapPause(scriptId, location);
let remainPaused = await this._handleSourceMapPause(scriptId, location);

if (event.hitBreakpoints?.length) {
remainPaused = true;
}

if (
scheduledPauseOnAsyncCall &&
Expand Down
21 changes: 21 additions & 0 deletions src/common/objUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,24 @@ export function debounce(duration: number, fn: () => void): (() => void) & { cle

return debounced;
}

/**
* Bisets the array by the predicate. The first return value will be the ones
* in which the predicate returned true, the second where it returned false.
*/
export function bisectArray<T>(
items: ReadonlyArray<T>,
predicate: (item: T) => boolean,
): [T[], T[]] {
const a: T[] = [];
const b: T[] = [];
for (const item of items) {
if (predicate(item)) {
a.push(item);
} else {
b.push(item);
}
}

return [a, b];
}
18 changes: 12 additions & 6 deletions src/test/node/node-path-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ import { ProtocolError, ErrorCodes } from '../../dap/errors';

describe('NodePathProvider', () => {
let p: NodePathProvider;
const env = EnvironmentVars.empty.addToPath(join(testWorkspace, 'nodePathProvider'));
const env = (name: string) =>
EnvironmentVars.empty.addToPath(join(testWorkspace, 'nodePathProvider', name));
const binaryLocation = (name: string) =>
join(testWorkspace, 'nodePathProvider', name + (process.platform === 'win32' ? '.exe' : ''));
join(
testWorkspace,
'nodePathProvider',
name,
process.platform === 'win32' ? 'node.exe' : 'node',
);

beforeEach(() => (p = new NodePathProvider()));

it('rejects not found', async () => {
try {
await p.resolveAndValidate(env, 'not-found');
await p.resolveAndValidate(env('not-found'), 'node');
throw new Error('expected to throw');
} catch (err) {
expect(err).to.be.an.instanceOf(ProtocolError);
Expand All @@ -29,7 +35,7 @@ describe('NodePathProvider', () => {

it('rejects outdated', async () => {
try {
await p.resolveAndValidate(env, 'outdated');
await p.resolveAndValidate(env('outdated'), 'node');
throw new Error('expected to throw');
} catch (err) {
expect(err).to.be.an.instanceOf(ProtocolError);
Expand All @@ -44,8 +50,8 @@ describe('NodePathProvider', () => {
});

it('works if up to date', async () => {
expect(await p.resolveAndValidate(env, 'up-to-date')).to.equal(binaryLocation('up-to-date'));
expect(await p.resolveAndValidate(env('up-to-date'))).to.equal(binaryLocation('up-to-date'));
// hit the cached path:
await p.resolveAndValidate(env, 'up-to-date');
await p.resolveAndValidate(env('up-to-date'));
});
});
2 changes: 2 additions & 0 deletions src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ export class TestRoot {
program: this._launchUrl,
rootPath: this._workspaceRoot,
trace: { logFile: tmpLogPath },
outFiles: [`${this._workspaceRoot}/**/*.js`, '!**/node_modules/**'],
resolveSourceMapLocations: ['**', '!**/node_modules/**'],
...options,
} as INodeLaunchConfiguration);
const result = await new Promise(f => (this._launchCallback = f));
Expand Down
6 changes: 3 additions & 3 deletions testWorkspace/nodePathProvider/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FLAG_OUTDATED = -ldflags "-s -w -X main.version=v6.0.0"
FLAG_CURRENT = -ldflags "-s -w -X main.version=v12.0.0"
SRC = program.go
OUT = outdated.exe up-to-date.exe
OUT = outdated/node.exe up-to-date/node.exe

all: $(OUT)

clean:
rm -f $(OUT)

outdated.exe: $(SRC)
outdated/node.exe: $(SRC)
GOOS=windows GOARCH=amd64 go build $(FLAG_OUTDATED) -o $@ ./program.go

up-to-date.exe: $(SRC)
up-to-date/node.exe: $(SRC)
GOOS=windows GOARCH=amd64 go build $(FLAG_CURRENT) -o $@ ./program.go

.PHONY: all clean
Binary file removed testWorkspace/nodePathProvider/outdated.exe
Binary file not shown.
File renamed without changes.
Binary file added testWorkspace/nodePathProvider/outdated/node.exe
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 comments on commit 4eac739

Please sign in to comment.