Skip to content

Commit

Permalink
Switch to Promise-based API. Add tests for XHR.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Wendelin committed Oct 19, 2014
1 parent 3ec311a commit dfb7f00
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"exports": false,
"it": false,
"jasmine": false,
"sinon": false,
"require": false,
"runs": false,
"waits": false,
"spyOn": false,
"waitsFor": false,
"files": true,
Expand Down
12 changes: 7 additions & 5 deletions karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
module.exports = function (config) {
'use strict';
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
process.exit(1);
}

// Check out https://saucelabs.com/platforms for all browser/platform combos
var customLaunchers = {
sl_chrome: {
slChrome: {
base: 'SauceLabs',
browserName: 'chrome'
},
sl_firefox: {
slFirefox: {
base: 'SauceLabs',
browserName: 'firefox'
},
sl_ie_11: {
slIE11: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
sl_ie_9: {
slIE9: {
base: 'SauceLabs',
browserName: 'internet explorer',
platform: 'Windows 7',
Expand All @@ -30,8 +31,9 @@ module.exports = function (config) {

config.set({
basePath: '',
frameworks: ['jasmine'],
frameworks: ['jasmine', 'sinon'],
files: [
'node_modules/es6-promise/dist/es6-promise.js',
'stacktrace-gps.js',
'spec/*-spec.js'
],
Expand Down
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
frameworks: ['jasmine', 'sinon'],
files: [
'node_modules/es6-promise/dist/es6-promise.js',
'stacktrace-gps.js',
'spec/*-spec.js'
],
Expand Down
94 changes: 51 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
{
"name": "stacktrace-gps",
"description": "Turns partial code location into precise code location",
"maintainers": [
"Eric Wendelin <me@eriwen.com> (http://www.eriwen.com)",
"Victor Homyakov (https://github.com/victor-homyakov)"
],
"version": "0.1.0",
"keywords": [
"stacktrace",
"error",
"debugger"
],
"homepage": "http://www.stacktracejs.com",
"repository": {
"type": "git",
"url": "git://github.com/stacktracejs/stacktrace-gps.git"
},
"devDependencies": {
"colors": "~1.0.3",
"coveralls": "^2.11.2",
"jasmine-node": "~1.14",
"jshint": "^2.5.6",
"karma": "~0.12",
"karma-chrome-launcher": "^0.1.5",
"karma-coverage": "^0.2.6",
"karma-firefox-launcher": "^0.1.3",
"karma-ie-launcher": "^0.1.5",
"karma-jasmine": "^0.1.5",
"karma-opera-launcher": "^0.1.0",
"karma-phantomjs-launcher": "^0.1.4",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10"
},
"bugs": {
"url": "https://github.com/stacktracejs/stacktrace-gps/issues"
},
"licenses": [{
"type": "Public Domain",
"url": "https://github.com/stacktracejs/stacktrace-gps/blob/master/LICENSE"
}],
"main": "./stacktrace-gps.js",
"scripts": {
"test": "make test"
"name": "stacktrace-gps",
"description": "Turns partial code location into precise code location",
"maintainers": [
"Eric Wendelin <me@eriwen.com> (http://www.eriwen.com)",
"Victor Homyakov (https://github.com/victor-homyakov)"
],
"version": "0.1.0",
"keywords": [
"stacktrace",
"error",
"debugger"
],
"homepage": "http://www.stacktracejs.com",
"repository": {
"type": "git",
"url": "git://github.com/stacktracejs/stacktrace-gps.git"
},
"devDependencies": {
"colors": "~1.0.3",
"coveralls": "^2.11.2",
"jasmine-node": "~1.14",
"jasmine-sinon": "^0.4.0",
"jshint": "^2.5.6",
"karma": "~0.12",
"karma-chrome-launcher": "^0.1.5",
"karma-coverage": "^0.2.6",
"karma-firefox-launcher": "^0.1.3",
"karma-ie-launcher": "^0.1.5",
"karma-jasmine": "^0.1.5",
"karma-opera-launcher": "^0.1.0",
"karma-phantomjs-launcher": "^0.1.4",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10",
"karma-sinon": "^1.0.3",
"sinon": "^1.10.3"
},
"bugs": {
"url": "https://github.com/stacktracejs/stacktrace-gps/issues"
},
"licenses": [
{
"type": "Public Domain",
"url": "https://github.com/stacktracejs/stacktrace-gps/blob/master/LICENSE"
}
],
"main": "./stacktrace-gps.js",
"scripts": {
"test": "make test"
},
"dependencies": {
"es6-promise": "^2.0.0"
}
}
140 changes: 126 additions & 14 deletions spec/stacktrace-gps-spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,131 @@
/* global StackTraceGPS: false */
describe('StackTraceGPS', function () {
describe('#findFunctionName', function() {
var unit = new StackTraceGPS();
it('throws an error given invalid URL String', function() {
var fn = function () {
unit.findFunctionName(undefined);
};
expect(fn).toThrow(new TypeError('Given URL is not a String'));
});

it('throws an error given invalid line number', function() {
var fn = function () {
unit.findFunctionName('https://raw.githubusercontent.com/stacktracejs/stacktrace.js/master/stacktrace.js', undefined);
};
expect(fn).toThrow(new TypeError('Given line number must be a positive integer'));
describe('#findFunctionName', function () {
var server;
var callback;
var errback;

beforeEach(function () {
server = sinon.fakeServer.create();
callback = jasmine.createSpy('callback');
errback = jasmine.createSpy('errback');
});
afterEach(function () {
server.restore();
});

it('rejects given invalid URL String', function () {
runs(function() {
new StackTraceGPS().findFunctionName(undefined).then(callback, errback);
});
waits(100);
runs(function() {
expect(callback).not.toHaveBeenCalled();
expect(errback).toHaveBeenCalledWith(new TypeError('Given URL is not a String'));
});
});

it('rejects given invalid line number', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', undefined)
.then(callback, errback);
});
waits(100);
runs(function() {
expect(callback).not.toHaveBeenCalled();
expect(errback).toHaveBeenCalledWith(new TypeError('Given line number must be a positive integer'));
});
});

it('rejects if source file could not be found', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', 23)
.then(callback, errback);
server.requests[0].respond(404, {}, 'Not Found');
});
waits(100);
runs(function() {
expect(callback).not.toHaveBeenCalled();
expect(errback).toHaveBeenCalled();
});
});

it('finds function name within function expression', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', 1)
.then(callback, errback);
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
server.requests[0].respond(200, { 'Content-Type': 'application/x-javascript' }, source);
});
waits(100);
runs(function() {
expect(callback).toHaveBeenCalledWith('foo');
expect(errback).not.toHaveBeenCalled();
});
});

it('finds function name within function declaration', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', 2)
.then(callback, errback);
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
server.requests[0].respond(200, { 'Content-Type': 'application/x-javascript' }, source);
});
waits(100);
runs(function() {
expect(callback).toHaveBeenCalledWith('bar');
expect(errback).not.toHaveBeenCalled();
});
});

it('finds function name within function evaluation', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', 3)
.then(callback, errback);
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
server.requests[0].respond(200, { 'Content-Type': 'application/x-javascript' }, source);
});
waits(100);
runs(function() {
expect(callback).toHaveBeenCalledWith('baz');
expect(errback).not.toHaveBeenCalled();
});
});

it('resolves to undefined if function name could not be found', function () {
runs(function() {
new StackTraceGPS()
.findFunctionName('http://localhost:9999/file.js', 1)
.then(callback, errback);
server.requests[0].respond(200, { 'Content-Type': 'application/x-javascript' }, '');
});
waits(100);
runs(function() {
expect(callback).toHaveBeenCalledWith(undefined);
expect(errback).not.toHaveBeenCalled();
});
});

it('caches subsequent requests to the same location', function() {
var unit = new StackTraceGPS();
runs(function() {
unit.findFunctionName('http://localhost:9999/file.js', 3).then(callback, errback);
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
server.requests[0].respond(200, { 'Content-Type': 'application/x-javascript' }, source);
});
waits(100);
runs(function() {
unit.findFunctionName('http://localhost:9999/file.js', 2).then(callback, errback);
});
waits(100);
runs(function() {
expect(server.requests.length).toBe(1);
});
});
});
});
Loading

0 comments on commit dfb7f00

Please sign in to comment.