Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 6615823

Browse files
authored
Reduce test loudness (#243)
* make the tests less loud * simplify appPathRelativeToRepository unit test
1 parent 52b5bd3 commit 6615823

File tree

4 files changed

+44
-96
lines changed

4 files changed

+44
-96
lines changed

src/agent/v8debugapi.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ function create(logger_, config_, jsFiles_, sourcemapper_) {
287287
// we are going to assume that repository root === the starting working
288288
// directory.
289289
var matchingScript;
290-
var scripts = findScripts(mapInfo ? mapInfo.file :
291-
path.normalize(breakpoint.location.path));
290+
var scripts = findScripts(mapInfo ? mapInfo.file :
291+
path.normalize(breakpoint.location.path), config, fileStats);
292292
if (scripts.length === 0) {
293293
return setErrorStatusAndCallback(cb, breakpoint,
294294
StatusMessage.BREAKPOINT_SOURCE_LOCATION,
@@ -406,25 +406,6 @@ function create(logger_, config_, jsFiles_, sourcemapper_) {
406406
// return v8bp;
407407
// }
408408

409-
function findScripts(scriptPath) {
410-
// Use repository relative mapping if present.
411-
if (config.appPathRelativeToRepository) {
412-
var candidate = scriptPath.replace(config.appPathRelativeToRepository,
413-
config.workingDirectory);
414-
// There should be no ambiguity resolution if project root is provided.
415-
return fileStats[candidate] ? [ candidate ] : [];
416-
}
417-
var regexp = pathToRegExp(scriptPath);
418-
// Next try to match path.
419-
var matches = Object.keys(fileStats).filter(regexp.test.bind(regexp));
420-
if (matches.length === 1) {
421-
return matches;
422-
}
423-
424-
// Finally look for files with the same name regardless of path.
425-
return findScriptsFuzzy(scriptPath, Object.keys(fileStats));
426-
}
427-
428409
function onBreakpointHit(breakpoint, callback, execState) {
429410
var v8bp = breakpoints[breakpoint.id].v8Breakpoint;
430411

@@ -584,6 +565,25 @@ function pathToRegExp(scriptPath) {
584565
return new RegExp(scriptPath + '$');
585566
}
586567

568+
function findScripts(scriptPath, config, fileStats) {
569+
// Use repository relative mapping if present.
570+
if (config.appPathRelativeToRepository) {
571+
var candidate = scriptPath.replace(config.appPathRelativeToRepository,
572+
config.workingDirectory);
573+
// There should be no ambiguity resolution if project root is provided.
574+
return fileStats[candidate] ? [candidate] : [];
575+
}
576+
var regexp = pathToRegExp(scriptPath);
577+
// Next try to match path.
578+
var matches = Object.keys(fileStats).filter(regexp.test.bind(regexp));
579+
if (matches.length === 1) {
580+
return matches;
581+
}
582+
583+
// Finally look for files with the same name regardless of path.
584+
return findScriptsFuzzy(scriptPath, Object.keys(fileStats));
585+
}
586+
587587
/**
588588
* Given an list of available files and a script path to match, this function
589589
* tries to resolve the script to a (hopefully unique) match in the file list
@@ -625,5 +625,6 @@ function findScriptsFuzzy(scriptPath, fileList) {
625625
module.exports = {
626626
create: create,
627627
// Exposed for unit testing.
628+
findScripts: findScripts,
628629
findScriptsFuzzy: findScriptsFuzzy
629630
};

test/test-debuglet.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
var _ = require('lodash');
1919
var assert = require('assert');
20-
var defaultConfig = require('../src/agent/config.js');
20+
var DEFAULT_CONFIG = require('../src/agent/config.js');
2121
var Debuglet = require('../src/agent/debuglet.js');
2222
var extend = require('extend');
2323

@@ -32,6 +32,8 @@ var nock = require('nock');
3232
var nocks = require('./nocks.js');
3333
nock.disableNetConnect();
3434

35+
var defaultConfig = extend(true, {}, DEFAULT_CONFIG, {logLevel: 0});
36+
3537
var oldGP;
3638

3739
var bp = {

test/test-env-relative-repository-path.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

test/test-v8debugapi.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,25 @@ describe('v8debugapi', function() {
12111211
it('should be possible to set deferred breakpoints');
12121212
});
12131213

1214+
describe('v8debugapi.findScripts', function() {
1215+
it('should properly handle appPathRelativeToRepository', function() {
1216+
var config = extend(true, {}, config, {
1217+
workingDirectory: '/some/strange/directory',
1218+
appPathRelativeToRepository: '/my/project/root'
1219+
});
1220+
1221+
var fakeFileStats = {
1222+
'/some/strange/directory/test/fixtures/a/hello.js':
1223+
{hash: 'fake', lines: 5},
1224+
'/my/project/root/test/fixtures/a/hello.js': {hash: 'fake', lines: 50}
1225+
};
1226+
var scriptPath = '/my/project/root/test/fixtures/a/hello.js';
1227+
var result = v8debugapi.findScripts(scriptPath, config, fakeFileStats);
1228+
assert.deepEqual(
1229+
result, ['/some/strange/directory/test/fixtures/a/hello.js']);
1230+
});
1231+
});
1232+
12141233
describe('v8debugapi.findScriptsFuzzy', function() {
12151234
var fuzzy = v8debugapi.findScriptsFuzzy;
12161235

0 commit comments

Comments
 (0)