-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to Promise-based API. Add tests for XHR.
- Loading branch information
Eric Wendelin
committed
Oct 19, 2014
1 parent
3ec311a
commit dfb7f00
Showing
6 changed files
with
226 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.