Jhernandez has uploaded a new change for review.
https://gerrit.wikimedia.org/r/289375
Change subject: Add http recording when running tests
......................................................................
Add http recording when running tests
npm test # run the tests using the recorded fixtures and record
# new http requests
See play modes: https://github.com/assaf/node-replay#settings
By default we use *record*.
In my macbook air 11', running the tests takes around 40s, with the cached
fixtures it takes between 700ms and 1s. A lot better if you are doing TDD or
frequently running the tests.
In CI, http fixtures are not used.
Bug: T132902
Change-Id: I4596fed1d89e5cc07ff6a3dafc3771a1d30edea2
---
M .gitignore
M README.md
M package.json
M test/utils/server.js
4 files changed, 20 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps
refs/changes/75/289375/1
diff --git a/.gitignore b/.gitignore
index 7402d4e..77ec4b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
npm-debug.log
.DS_Store
tmp/
+fixtures/
diff --git a/README.md b/README.md
index 9074b31..d5bdb1b 100644
--- a/README.md
+++ b/README.md
@@ -89,6 +89,20 @@
npm run-script coverage
```
+If you're going to run the tests many times, you can record the external HTTP
+interactions for running the tests faster:
+
+```
+VCR_MODE=record npm test # Run tests recording http interactions
+# After the first run you should have a fixtures/ folder
+VCR_MODE=cache npm test # Run tests with cached http interactions, caches new
+requests. Should be a lot faster, also VCR_MODE=playback plays using cached
+http interactions but goes to network for uncached ones (without caching them).
+```
+
+See [sepia](https://www.npmjs.com/package/sepia) for more documentation about
+the http recording.
+
### Troubleshooting
In a lot of cases when there is an issue with node it helps to recreate the
diff --git a/package.json b/package.json
index c4d3db1..566e4e5 100644
--- a/package.json
+++ b/package.json
@@ -58,7 +58,8 @@
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"mocha-jshint": "^2.2.6",
- "mocha-lcov-reporter": "^1.0.0"
+ "mocha-lcov-reporter": "^1.0.0",
+ "replay": "^2.0.6"
},
"deploy": {
"node": "4.3.0",
diff --git a/test/utils/server.js b/test/utils/server.js
index 29968de..98011b5 100644
--- a/test/utils/server.js
+++ b/test/utils/server.js
@@ -1,6 +1,8 @@
'use strict';
-
+// Record http interactions when using the server
+var Replay = require('replay');
+Replay.mode = process.env.REPLAY || 'record';
var BBPromise = require('bluebird');
var ServiceRunner = require('service-runner');
var logStream = require('./logStream');
--
To view, visit https://gerrit.wikimedia.org/r/289375
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4596fed1d89e5cc07ff6a3dafc3771a1d30edea2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits