Skip to content

Commit 1f2bea3

Browse files
committed
Use proxyquireify to stub uuid4 (couldn't stub window.crypto in Phantom)
1 parent d6ea677 commit 1f2bea3

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

Gruntfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var proxyquire = require('proxyquireify');
12

23
module.exports = function(grunt) {
34
"use strict";
@@ -109,7 +110,8 @@ module.exports = function(grunt) {
109110
options: {
110111
browserifyOptions: {
111112
debug: true // source maps
112-
}
113+
},
114+
plugin: [proxyquire.plugin]
113115
}
114116
}
115117
},
@@ -305,7 +307,7 @@ module.exports = function(grunt) {
305307
grunt.registerTask('dist', ['build.core', 'copy:dist']);
306308

307309
// Test task
308-
grunt.registerTask('test', ['jshint', 'mocha', 'browserify.core', 'browserify:test']);
310+
grunt.registerTask('test', ['jshint', 'browserify.core', 'browserify:test', 'mocha']);
309311

310312
// Webserver tasks
311313
grunt.registerTask('run:test', ['connect:test']);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"grunt-sri": "mattrobenolt/grunt-sri#pretty",
3131
"jquery": "^2.1.4",
3232
"lodash": "~2.4.0",
33+
"proxyquireify": "^3.0.0",
3334
"sinon": "~1.7.3",
3435
"through2": "^2.0.0"
3536
},

src/singleton.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
'use strict';
22

3-
var Raven = require('./raven');
3+
var RavenConstructor = require('./raven');
44

55
var _Raven = window.Raven;
66

7-
var raven = new Raven();
7+
var Raven = new RavenConstructor();
88

99
/*
1010
* Allow multiple versions of Raven to be installed.
1111
* Strip Raven from the global context and returns the instance.
1212
*
1313
* @return {Raven}
1414
*/
15-
raven.noConflict = function () {
15+
Raven.noConflict = function () {
1616
window.Raven = _Raven;
17-
return raven;
17+
return Raven;
1818
};
1919

20-
raven.afterLoad();
20+
Raven.afterLoad();
2121

22-
module.exports = raven;
22+
module.exports = Raven;

test/index.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@
3232
<!-- Deps -->
3333
<script src="../node_modules/jquery/dist/jquery.js"></script>
3434

35-
<!-- Raven -->
36-
<!--<script src="../vendor/TraceKit/tracekit.js"></script>-->
37-
<!--<script src="../build/raven.js"></script>-->
38-
<!-- <script src="../plugins/jquery.js"></script>-->
39-
4035
<!-- Tests -->
4136
<script src="../build/raven.test.js"></script>
42-
<!--<script src="plugins/jquery.test.js"></script>-->
4337

4438
<script>
4539
if (!window.PHANTOMJS) {

test/raven.test.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
/*global assert:false, console:true*/
33
'use strict';
44

5-
var _Raven = require('../src/raven');
6-
var TraceKit = require('../vendor/TraceKit/tracekit');
7-
var joinRegExp = require('../src/utils').joinRegExp;
5+
var proxyquire = require('proxyquireify')(require);
86

9-
window.crypto.getRandomValues = function(arr) {
10-
console.log('getRandomValues');
11-
return [1, 2, 3, 4, 5, 6];
12-
};
7+
var TraceKit = require('../vendor/TraceKit/tracekit');
8+
var _Raven = proxyquire('../src/raven', {
9+
'./utils': {
10+
// patched to return a predictable result
11+
uuid4: function () {
12+
return 'abc123';
13+
}
14+
},
15+
16+
// Ensure same TraceKit obj is shared (without specifying this, proxyquire
17+
// seems to clone dependencies or something weird)
18+
'../vendor/TraceKit/tracekit': TraceKit
19+
});
1320

14-
// uuid4 return value generated by stubbed getRandomValues above
15-
var CONST_UUID4 = "00000000000040008000000000000000";
21+
var joinRegExp = require('../src/utils').joinRegExp;
1622

1723
// window.console must be stubbed in for browsers that don't have it
1824
if (typeof window.console === 'undefined') {
@@ -27,10 +33,6 @@ function setupRaven() {
2733
Raven.globalOptions.fetchContext = true;
2834
}
2935

30-
// patched to return a predictable result
31-
// Raven._uuid4 = function() {
32-
// return CONST_UUID4;
33-
// };
3436

3537
var Raven;
3638

@@ -720,7 +722,7 @@ describe('globals', function() {
720722
'User-Agent': 'lolbrowser'
721723
}
722724
},
723-
event_id: CONST_UUID4,
725+
event_id: 'abc123',
724726
message: 'bar',
725727
extra: {'session:duration': 100}
726728
});
@@ -752,7 +754,7 @@ describe('globals', function() {
752754
'User-Agent': 'lolbrowser'
753755
}
754756
},
755-
event_id: CONST_UUID4,
757+
event_id: 'abc123',
756758
user: {
757759
name: 'Matt'
758760
},
@@ -787,7 +789,7 @@ describe('globals', function() {
787789
'User-Agent': 'lolbrowser'
788790
}
789791
},
790-
event_id: CONST_UUID4,
792+
event_id: 'abc123',
791793
message: 'bar',
792794
tags: {tag1: 'value1', tag2: 'value2'},
793795
extra: {'session:duration': 100}
@@ -830,7 +832,7 @@ describe('globals', function() {
830832
}
831833
},
832834

833-
event_id: CONST_UUID4,
835+
event_id: 'abc123',
834836
message: 'bar',
835837
extra: {key1: 'value1', key2: 'value2', 'session:duration': 100}
836838
});
@@ -861,7 +863,7 @@ describe('globals', function() {
861863
Raven._send({message: 'bar'});
862864
assert.deepEqual(Raven._makeRequest.lastCall.args[0].data, {
863865
message: 'ibrokeit',
864-
event_id: CONST_UUID4
866+
event_id: 'abc123'
865867
});
866868
});
867869

@@ -893,7 +895,7 @@ describe('globals', function() {
893895
'User-Agent': 'lolbrowser'
894896
}
895897
},
896-
event_id: CONST_UUID4,
898+
event_id: 'abc123',
897899
message: 'bar',
898900
extra: {'session:duration': 100}
899901
});
@@ -925,7 +927,7 @@ describe('globals', function() {
925927
'User-Agent': 'lolbrowser'
926928
}
927929
},
928-
event_id: CONST_UUID4,
930+
event_id: 'abc123',
929931
message: 'bar',
930932
extra: {'session:duration': 100}
931933
});
@@ -958,7 +960,7 @@ describe('globals', function() {
958960
'User-Agent': 'lolbrowser'
959961
}
960962
},
961-
event_id: CONST_UUID4,
963+
event_id: 'abc123',
962964
message: 'bar',
963965
extra: {'session:duration': 100}
964966
});
@@ -991,7 +993,7 @@ describe('globals', function() {
991993
'User-Agent': 'lolbrowser'
992994
}
993995
},
994-
event_id: CONST_UUID4,
996+
event_id: 'abc123',
995997
message: 'bar',
996998
extra: {'session:duration': 100}
997999
});
@@ -1030,7 +1032,7 @@ describe('globals', function() {
10301032
'User-Agent': 'lolbrowser'
10311033
}
10321034
},
1033-
event_id: CONST_UUID4,
1035+
event_id: 'abc123',
10341036
message: 'bar',
10351037
extra: {'session:duration': 100},
10361038
});
@@ -1071,7 +1073,7 @@ describe('globals', function() {
10711073
'User-Agent': 'lolbrowser'
10721074
}
10731075
},
1074-
event_id: CONST_UUID4,
1076+
event_id: 'abc123',
10751077
message: 'bar',
10761078
extra: {'session:duration': 100}
10771079
});
@@ -1753,12 +1755,12 @@ describe('Raven (public API)', function() {
17531755

17541756
describe('.setRelease', function() {
17551757
it('should set the globalOptions.release attribute', function() {
1756-
Raven.setRelease(CONST_UUID4);
1757-
assert.equal(Raven.globalOptions.release, CONST_UUID4);
1758+
Raven.setRelease('abc123');
1759+
assert.equal(Raven.globalOptions.release, 'abc123');
17581760
});
17591761

17601762
it('should clear globalOptions.release with no arguments', function() {
1761-
Raven.globalOptions.release = CONST_UUID4;
1763+
Raven.globalOptions.release = 'abc123';
17621764
Raven.setRelease();
17631765
assert.isUndefined(Raven.globalOptions.release);
17641766
});
@@ -1831,7 +1833,7 @@ describe('Raven (public API)', function() {
18311833
it('should tag lastEventId #integration', function() {
18321834
setupRaven();
18331835
Raven.captureMessage('lol');
1834-
assert.equal(Raven.lastEventId(), CONST_UUID4);
1836+
assert.equal(Raven.lastEventId(), 'abc123');
18351837
});
18361838

18371839
it('should respect `ignoreErrors`', function() {

0 commit comments

Comments
 (0)