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

Commit

Permalink
test: reduce dependence on repo layout (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofrobots committed Jan 23, 2017
1 parent daf015f commit 1e8e6bc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
3 changes: 0 additions & 3 deletions test/fixtures/source-context.json

This file was deleted.

11 changes: 7 additions & 4 deletions test/test-debuglet.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var assert = require('assert');
var defaultConfig = require('../src/agent/config.js');
var Debuglet = require('../src/agent/debuglet.js');
var extend = require('extend');
var path = require('path');

var DEBUGGEE_ID = 'bar';
var API = 'https://clouddebugger.googleapis.com';
Expand Down Expand Up @@ -309,10 +308,14 @@ describe('Debuglet', function() {


it('should pass source context to api if present', function(done) {
process.chdir(path.join(__dirname, 'fixtures'));

var debug = require('..')(
{projectId: 'fake-project', credentials: fakeCredentials});
var old = Debuglet.prototype.getSourceContext_;
Debuglet.prototype.getSourceContext_ = function(cb) {
setImmediate(function () {
cb(null, {a: 5});
});
};
var debuglet = new Debuglet(debug, defaultConfig);

var scope = nock(API).post(REGISTER_PATH, function(body) {
Expand All @@ -321,10 +324,10 @@ describe('Debuglet', function() {
}).reply(200, {debuggee: {id: DEBUGGEE_ID}});

debuglet.once('registered', function(id) {
Debuglet.prototype.getSourceContext_ = old;
assert.equal(id, DEBUGGEE_ID);
debuglet.stop();
scope.done();
process.chdir('../..');
done();
});

Expand Down
5 changes: 2 additions & 3 deletions test/test-duplicate-expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var common = require('@google-cloud/common');
var defaultConfig = require('../src/agent/config.js');
var SourceMapper = require('../src/agent/sourcemapper.js');
var scanner = require('../src/agent/scanner.js');
var path = require('path');

function stateIsClean(api) {
assert.equal(api.numBreakpoints_(), 0,
Expand All @@ -43,9 +42,9 @@ function stateIsClean(api) {
return true;
}

describe('v8debugapi', function() {
describe(__filename, function() {
var config = extend({}, defaultConfig, {
workingDirectory: path.join(process.cwd(), 'test'),
workingDirectory: __dirname,
forceNewAgent_: true
});
var logger = common.logger({ logLevel: config.logLevel });
Expand Down
5 changes: 2 additions & 3 deletions test/test-duplicate-nested-expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var common = require('@google-cloud/common');
var defaultConfig = require('../src/agent/config.js');
var SourceMapper = require('../src/agent/sourcemapper.js');
var scanner = require('../src/agent/scanner.js');
var path = require('path');
var semver = require('semver');

function stateIsClean(api) {
Expand All @@ -42,9 +41,9 @@ function stateIsClean(api) {
return true;
}

describe('v8debugapi', function() {
describe(__filename, function() {
var config = extend({}, defaultConfig, {
workingDirectory: path.join(process.cwd(), 'test'),
workingDirectory: __dirname,
forceNewAgent_: true
});
var logger = common.logger({ logLevel: config.logLevel });
Expand Down
17 changes: 11 additions & 6 deletions test/test-env-relative-repository-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ var path = require('path');
process.env.GCLOUD_PROJECT = 0;

var assert = require('assert');
var agent = require('..')();
var api;
var Debuglet = require('../src/agent/debuglet.js');
var debuglet;
var h = require('./fixtures/a/hello.js');

describe('repository relative paths', function() {

before(function(done) {
agent.startAgent({
var debug = require('..')({projectId: 'fake-project'});
var config = {
appPathRelativeToRepository: path.join(path.sep, 'my', 'project', 'root')
});
};
debuglet = new Debuglet(debug, config);
debuglet.start();
setTimeout(function() {
// Wait for v8debug api to initialize.
api = agent.private_.v8debug_;
api = debuglet.v8debug_;
assert(api, 'v8 debug api was not initialized in time');
done();
}, 1500);
Expand All @@ -44,15 +48,16 @@ describe('repository relative paths', function() {
'there should be no breakpoints active');
assert.equal(api.numListeners_(), 0,
'there should be no listeners active');
debuglet.stop();
});

it('should correctly substitute when provided', function(done) {
var bp = {
id: 0,
location: {
line: 3,
path: path.join(path.sep, 'my', 'project', 'root', 'test',
'fixtures', 'a', 'hello.js')
path: path.join(path.sep, 'my', 'project', 'root', 'packages', 'debug',
'test', 'fixtures', 'a', 'hello.js')
}
};
api.set(bp, function(err) {
Expand Down
5 changes: 2 additions & 3 deletions test/test-fat-arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var common = require('@google-cloud/common');
var defaultConfig = require('../src/agent/config.js');
var SourceMapper = require('../src/agent/sourcemapper.js');
var scanner = require('../src/agent/scanner.js');
var path = require('path');
var semver = require('semver');

process.env.GCLOUD_PROJECT = 0;
Expand All @@ -35,9 +34,9 @@ function stateIsClean(api) {
return true;
}

describe('v8debugapi', function() {
describe(__filename, function() {
var config = extend({}, defaultConfig, {
workingDirectory: path.join(process.cwd(), 'test'),
workingDirectory: __dirname,
forceNewAgent_: true
});
var logger = common.logger({ logLevel: config.logLevel });
Expand Down
2 changes: 1 addition & 1 deletion test/test-options-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('test-options-credentials', function() {
var credentials = require('./fixtures/gcloud-credentials.json');
var options = extend({}, {
projectId: 'fake-project',
keyFilename: path.join('test', 'fixtures', 'gcloud-credentials.json')
keyFilename: path.join(__dirname, 'fixtures', 'gcloud-credentials.json')
});
var debug = require('..')(options);
var scope = nocks.oauth2(function(body) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-sourcemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function testTool(tool, mapFilePath, inputFilePath, outputFilePath, inToOutLineN
});
}

var basePath = 'test/fixtures/sourcemapper/';
var basePath = path.join(__dirname, 'fixtures', 'sourcemapper');
testTool('Babel',
path.join(basePath, 'babel', 'out.js.map'),
path.join(basePath, 'babel', 'in.js'),
Expand Down
5 changes: 2 additions & 3 deletions test/test-this-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var common = require('@google-cloud/common');
var defaultConfig = require('../src/agent/config.js');
var SourceMapper = require('../src/agent/sourcemapper.js');
var scanner = require('../src/agent/scanner.js');
var path = require('path');
var semver = require('semver');

function stateIsClean(api) {
Expand All @@ -42,9 +41,9 @@ function stateIsClean(api) {
return true;
}

describe('v8debugapi', function() {
describe(__filename, function() {
var config = extend({}, defaultConfig, {
workingDirectory: path.join(process.cwd(), 'test'),
workingDirectory: __dirname,
forceNewAgent_: true
});
var logger = common.logger({ logLevel: config.logLevel });
Expand Down
5 changes: 2 additions & 3 deletions test/test-try-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var common = require('@google-cloud/common');
var defaultConfig = require('../src/agent/config.js');
var SourceMapper = require('../src/agent/sourcemapper.js');
var scanner = require('../src/agent/scanner.js');
var path = require('path');
var semver = require('semver');

function stateIsClean(api) {
Expand All @@ -42,9 +41,9 @@ function stateIsClean(api) {
return true;
}

describe('v8debugapi', function() {
describe(__filename, function() {
var config = extend({}, defaultConfig, {
workingDirectory: path.join(process.cwd(), 'test'),
workingDirectory: __dirname,
forceNewAgent_: true
});
var logger = common.logger({ logLevel: config.logLevel });
Expand Down

0 comments on commit 1e8e6bc

Please sign in to comment.