1
1
var fs = require ( 'fs' )
2
+ var path = require ( 'path' )
2
3
var rimraf = require ( 'rimraf' )
3
4
var assert = require ( 'assert' )
4
5
var VCR = require ( '../index' )
@@ -8,9 +9,9 @@ function clearFixtures() {
8
9
rimraf . sync ( './test/fixtures' )
9
10
}
10
11
11
- function fileExists ( path ) {
12
+ function fileExists ( cassettePath ) {
12
13
try {
13
- return fs . statSync ( path ) . isFile ( )
14
+ return fs . statSync ( cassettePath ) . isFile ( )
14
15
} catch ( e ) {
15
16
return false
16
17
}
@@ -34,14 +35,14 @@ describe('Axios VCR', function() {
34
35
afterEach ( clearFixtures )
35
36
36
37
it ( 'generates stubs for requests' , function ( done ) {
37
- var path = './test/fixtures/posts.json'
38
- VCR . mountCassette ( path )
38
+ var cassettePath = './test/fixtures/posts.json'
39
+ VCR . mountCassette ( cassettePath )
39
40
40
41
axios . get ( posts ) . then ( function ( response ) {
41
- getFixture ( path , response . config ) . then ( function ( fixture ) {
42
+ getFixture ( cassettePath , response . config ) . then ( function ( fixture ) {
42
43
assert . deepEqual ( fixture . originalResponseData . data , response . data )
43
44
done ( )
44
- VCR . ejectCassette ( path )
45
+ VCR . ejectCassette ( cassettePath )
45
46
} )
46
47
} )
47
48
} )
@@ -85,38 +86,39 @@ describe('Axios VCR', function() {
85
86
check that the response is the same as the cassette file.
86
87
*/
87
88
it ( 'skips remote calls' , function ( done ) {
88
- var path = './test/static_fixtures/posts.json'
89
- assert ( fileExists ( path ) )
89
+ var fixturePrefix = process . env . FIXTURE_PREFIX || ''
90
+ var cassettePath = path . join ( './test' , fixturePrefix , 'static_fixtures' , 'posts.json' )
91
+ assert ( fileExists ( cassettePath ) )
90
92
91
93
var url = 'http://something.com/unexisting'
92
- VCR . mountCassette ( path )
94
+ VCR . mountCassette ( cassettePath )
93
95
94
96
axios . get ( url ) . then ( function ( res ) {
95
- getFixture ( path , res . config ) . then ( function ( fixture ) {
97
+ getFixture ( cassettePath , res . config ) . then ( function ( fixture ) {
96
98
assert . deepEqual ( fixture . originalResponseData , _ . omit ( res , 'fixture' ) )
97
99
done ( )
98
100
99
- VCR . ejectCassette ( path )
101
+ VCR . ejectCassette ( cassettePath )
100
102
} )
101
103
} )
102
104
} )
103
105
104
106
it ( 'makes remote call when a cassette is not available' , function ( done ) {
105
- var path = './test/static_fixtures/no_posts.json'
107
+ var cassettePath = './test/static_fixtures/no_posts.json'
106
108
107
109
try {
108
- fs . unlinkSync ( path )
110
+ fs . unlinkSync ( cassettePath )
109
111
} catch ( e ) { }
110
112
111
- assert ( ! fileExists ( path ) )
112
- VCR . mountCassette ( path )
113
+ assert ( ! fileExists ( cassettePath ) )
114
+ VCR . mountCassette ( cassettePath )
113
115
114
116
axios . get ( posts ) . then ( function ( response ) {
115
117
assert . equal ( 200 , response . status )
116
- fs . unlinkSync ( path )
118
+ fs . unlinkSync ( cassettePath )
117
119
done ( )
118
120
119
- VCR . ejectCassette ( path )
121
+ VCR . ejectCassette ( cassettePath )
120
122
} )
121
123
} )
122
124
} )
@@ -131,9 +133,9 @@ describe('Axios VCR', function() {
131
133
var todosUrl = 'http://jsonplaceholder.typicode.com/todos'
132
134
133
135
it ( 'stores multiple requests in the same cassette' , function ( done ) {
134
- var path = './test/fixtures/multiple.json'
136
+ var cassettePath = './test/fixtures/multiple.json'
135
137
136
- VCR . mountCassette ( path )
138
+ VCR . mountCassette ( cassettePath )
137
139
138
140
var usersPromise = axios . get ( usersUrl )
139
141
var todosPromise = axios . get ( todosUrl )
@@ -142,15 +144,15 @@ describe('Axios VCR', function() {
142
144
var usersResponse = responses [ 0 ]
143
145
var todosResponse = responses [ 1 ]
144
146
145
- var usersResponsePromise = getFixture ( path , usersResponse . config )
146
- var todosResponsePromise = getFixture ( path , todosResponse . config )
147
+ var usersResponsePromise = getFixture ( cassettePath , usersResponse . config )
148
+ var todosResponsePromise = getFixture ( cassettePath , todosResponse . config )
147
149
148
150
Promise . all ( [ usersResponsePromise , todosResponsePromise ] ) . then ( function ( fixtures ) {
149
151
assert . deepEqual ( fixtures [ 0 ] . originalResponseData . data , usersResponse . data )
150
152
assert . deepEqual ( fixtures [ 1 ] . originalResponseData . data , todosResponse . data )
151
153
done ( )
152
154
153
- VCR . ejectCassette ( path )
155
+ VCR . ejectCassette ( cassettePath )
154
156
} )
155
157
} )
156
158
} )
0 commit comments