File tree Expand file tree Collapse file tree 3 files changed +110
-45
lines changed
Expand file tree Collapse file tree 3 files changed +110
-45
lines changed Original file line number Diff line number Diff line change 1+ var nock = require ( 'nock' ) ;
2+ var path = require ( 'path' ) ;
3+ var fs = require ( 'fs' ) ;
4+
5+ module . exports = function ( name , options ) {
6+ // options tell us where to store our fixtures
7+ options = options || { } ;
8+ var test_folder = options . test_folder || 'test' ;
9+ var fixtures_folder = options . fixtures_folder || 'fixtures' ;
10+ var fp = path . join ( test_folder , fixtures_folder , name + '.js' ) ;
11+ // `has_fixtures` indicates whether the test has fixtures we should read,
12+ // or doesn't, so we should record and save them.
13+ var has_fixtures = ! ! process . env . NOCK_RECORD ;
14+
15+ return {
16+ // starts recording, or ensure the fixtures exist
17+ before : function ( ) {
18+ if ( ! has_fixtures ) try {
19+ require ( './' + fp ) ;
20+ has_fixtures = true ;
21+ } catch ( e ) {
22+ console . log ( JSON . stringify ( e ) ) ;
23+ nock . recorder . rec ( {
24+ dont_print : true
25+ } ) ;
26+ } else {
27+ has_fixtures = false ;
28+ nock . recorder . rec ( {
29+ dont_print : true
30+ } ) ;
31+ }
32+ } ,
33+ // saves our recording if fixtures didn't already exist
34+ after : function ( done ) {
35+ if ( ! has_fixtures ) {
36+ has_fixtures = nock . recorder . play ( ) ;
37+ var text = "var nock = require('nock');\n" + has_fixtures . join ( '\n' ) ;
38+ fs . writeFile ( fp , text , done ) ;
39+ } else {
40+ done ( ) ;
41+ }
42+ }
43+ }
44+ } ;
Original file line number Diff line number Diff line change 1+ var nock = require ( 'nock' ) ;
2+
3+ nock . recorder . rec ( {
4+ dont_print : true
5+ } ) ;
6+
7+
8+
19var pubnub = PUBNUB . init ( {
210 publish_key : 'ds' ,
311 subscribe_key : 'ds' ,
You can’t perform that action at this time.
0 commit comments