Skip to content

Commit 3b5eebb

Browse files
committed
Configure TAV to test with legacy fixtures
1 parent d8b1e47 commit 3b5eebb

File tree

4 files changed

+124
-22
lines changed

4 files changed

+124
-22
lines changed

.tav.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
axios_1:
2+
name: axios
3+
versions: '> 0.15.2 < 1.0'
4+
commands: node ./node_modules/.bin/mocha test/*
5+
6+
axios_2:
7+
name: axios
8+
versions: '>= 0.13.0 < 0.15.2'
9+
commands: FIXTURE_PREFIX=legacy1 node ./node_modules/.bin/mocha test/*
10+
11+
axios_3:
12+
name: axios
13+
versions: '>= 0.11 < 0.13'
14+
commands: FIXTURE_PREFIX=legacy2 node ./node_modules/.bin/mocha test/*

test/axios_vcr_test.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var fs = require('fs')
2+
var path = require('path')
23
var rimraf = require('rimraf')
34
var assert = require('assert')
45
var VCR = require('../index')
@@ -8,9 +9,9 @@ function clearFixtures() {
89
rimraf.sync('./test/fixtures')
910
}
1011

11-
function fileExists(path) {
12+
function fileExists(cassettePath) {
1213
try {
13-
return fs.statSync(path).isFile()
14+
return fs.statSync(cassettePath).isFile()
1415
} catch(e) {
1516
return false
1617
}
@@ -34,14 +35,14 @@ describe('Axios VCR', function() {
3435
afterEach(clearFixtures)
3536

3637
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)
3940

4041
axios.get(posts).then(function(response) {
41-
getFixture(path, response.config).then(function(fixture) {
42+
getFixture(cassettePath, response.config).then(function(fixture) {
4243
assert.deepEqual(fixture.originalResponseData.data, response.data)
4344
done()
44-
VCR.ejectCassette(path)
45+
VCR.ejectCassette(cassettePath)
4546
})
4647
})
4748
})
@@ -85,38 +86,39 @@ describe('Axios VCR', function() {
8586
check that the response is the same as the cassette file.
8687
*/
8788
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))
9092

9193
var url = 'http://something.com/unexisting'
92-
VCR.mountCassette(path)
94+
VCR.mountCassette(cassettePath)
9395

9496
axios.get(url).then(function(res) {
95-
getFixture(path, res.config).then(function(fixture) {
97+
getFixture(cassettePath, res.config).then(function(fixture) {
9698
assert.deepEqual(fixture.originalResponseData, _.omit(res, 'fixture'))
9799
done()
98100

99-
VCR.ejectCassette(path)
101+
VCR.ejectCassette(cassettePath)
100102
})
101103
})
102104
})
103105

104106
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'
106108

107109
try {
108-
fs.unlinkSync(path)
110+
fs.unlinkSync(cassettePath)
109111
} catch(e) {}
110112

111-
assert(!fileExists(path))
112-
VCR.mountCassette(path)
113+
assert(!fileExists(cassettePath))
114+
VCR.mountCassette(cassettePath)
113115

114116
axios.get(posts).then(function(response) {
115117
assert.equal(200, response.status)
116-
fs.unlinkSync(path)
118+
fs.unlinkSync(cassettePath)
117119
done()
118120

119-
VCR.ejectCassette(path)
121+
VCR.ejectCassette(cassettePath)
120122
})
121123
})
122124
})
@@ -131,9 +133,9 @@ describe('Axios VCR', function() {
131133
var todosUrl = 'http://jsonplaceholder.typicode.com/todos'
132134

133135
it('stores multiple requests in the same cassette', function(done) {
134-
var path = './test/fixtures/multiple.json'
136+
var cassettePath = './test/fixtures/multiple.json'
135137

136-
VCR.mountCassette(path)
138+
VCR.mountCassette(cassettePath)
137139

138140
var usersPromise = axios.get(usersUrl)
139141
var todosPromise = axios.get(todosUrl)
@@ -142,15 +144,15 @@ describe('Axios VCR', function() {
142144
var usersResponse = responses[0]
143145
var todosResponse = responses[1]
144146

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)
147149

148150
Promise.all([usersResponsePromise, todosResponsePromise]).then(function(fixtures) {
149151
assert.deepEqual(fixtures[0].originalResponseData.data, usersResponse.data)
150152
assert.deepEqual(fixtures[1].originalResponseData.data, todosResponse.data)
151153
done()
152154

153-
VCR.ejectCassette(path)
155+
VCR.ejectCassette(cassettePath)
154156
})
155157
})
156158
})
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"2dff074369933923c30f9c868cf65f79": {
3+
"meta": {
4+
"url": "http://something.com/unexisting",
5+
"method": "get",
6+
"headers": {
7+
"common": { "Accept": "application/json, text/plain, */*" },
8+
"patch": { "Content-Type": "application/x-www-form-urlencoded" },
9+
"post": { "Content-Type": "application/x-www-form-urlencoded" },
10+
"put": { "Content-Type": "application/x-www-form-urlencoded" }
11+
}
12+
},
13+
"fixture": true,
14+
"originalResponseData": {
15+
"status": 200,
16+
"statusText": "OK",
17+
"headers": {
18+
"server": "Cowboy",
19+
"connection": "close",
20+
"x-powered-by": "Express",
21+
"vary": "Origin, Accept-Encoding",
22+
"access-control-allow-credentials": "true",
23+
"cache-control": "no-cache",
24+
"pragma": "no-cache",
25+
"expires": "-1",
26+
"x-content-type-options": "nosniff",
27+
"content-type": "application/json; charset=utf-8",
28+
"content-length": "292",
29+
"etag": "W/\"124-yv65LoT2uMHrpn06wNpAcQ\"",
30+
"date": "Thu, 09 Jun 2016 08:53:20 GMT",
31+
"via": "1.1 vegur"
32+
},
33+
"data": "bla",
34+
"config": {
35+
"url": "http://something.com/unexisting",
36+
"method": "get",
37+
"headers": {
38+
"common": { "Accept": "application/json, text/plain, */*" },
39+
"patch": { "Content-Type": "application/x-www-form-urlencoded" },
40+
"post": { "Content-Type": "application/x-www-form-urlencoded" },
41+
"put": { "Content-Type": "application/x-www-form-urlencoded" }
42+
}
43+
}
44+
}
45+
}
46+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"56e7cedef2202ac3a46947b52d90a2d6": {
3+
"meta": {
4+
"url": "http://something.com/unexisting",
5+
"method": "get",
6+
"headers": {
7+
"Accept": "application/json, text/plain, */*"
8+
}
9+
},
10+
"fixture": true,
11+
"originalResponseData": {
12+
"status": 200,
13+
"statusText": "OK",
14+
"headers": {
15+
"server": "Cowboy",
16+
"connection": "close",
17+
"x-powered-by": "Express",
18+
"vary": "Origin, Accept-Encoding",
19+
"access-control-allow-credentials": "true",
20+
"cache-control": "no-cache",
21+
"pragma": "no-cache",
22+
"expires": "-1",
23+
"x-content-type-options": "nosniff",
24+
"content-type": "application/json; charset=utf-8",
25+
"content-length": "292",
26+
"etag": "W/\"124-yv65LoT2uMHrpn06wNpAcQ\"",
27+
"date": "Thu, 09 Jun 2016 08:53:20 GMT",
28+
"via": "1.1 vegur"
29+
},
30+
"data": "bla",
31+
"config": {
32+
"url": "http://something.com/unexisting",
33+
"method": "get",
34+
"headers": {
35+
"Accept": "application/json, text/plain, */*"
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)