diff --git a/.travis.yml b/.travis.yml index c4f16184..99632a4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,11 @@ node_js: cache: npm script: - npm run lint - - npm test + - npm run test jobs: include: - - name: e2e-test - script: npm run e2e-test + - name: test-e2e + script: npm run test-e2e node_js: '10' allow_failures: - - name: e2e-test + - name: test-e2e diff --git a/package.json b/package.json index c69409f9..17222f4e 100644 --- a/package.json +++ b/package.json @@ -57,18 +57,22 @@ }, "devDependencies": { "db-stations": "^3.0.0", - "eslint": "^6.8.0", + "eslint": "^7.0.0", "is-coordinates": "^2.0.2", "is-roughly-equal": "^0.1.0", + "replayer": "^2.2.3", "tap-spec": "^5.0.0", "tape": "^5.0.0", "validate-fptf": "^3.0.0", "vbb-stations-autocomplete": "^4.1.0" }, "scripts": { - "e2e-test": "env NODE_ENV=dev node test/e2e/index.js | tap-spec", "lint": "eslint .", - "test": "env NODE_ENV=dev node test/index.js | tap-spec", - "prepublishOnly": "npm test && npm run e2e-test" + "test-unit": "node test/index.js | tap-spec", + "test-integration": "VCR_MODE=playback node test/e2e/index.js | tap-spec", + "test-integration:record": "VCR_MODE=record node test/e2e/index.js | tap-spec", + "test-e2e": "VCR_OFF=true node test/e2e/index.js | tap-spec", + "test": "npm run test-unit && npm run test-integration", + "prepublishOnly": "npm run lint && npm test" } } diff --git a/test/e2e/lib/util.js b/test/e2e/lib/util.js index c606c540..836e73bd 100644 --- a/test/e2e/lib/util.js +++ b/test/e2e/lib/util.js @@ -3,6 +3,7 @@ const isRoughlyEqual = require('is-roughly-equal') const {DateTime} = require('luxon') const a = require('assert') +const {join} = require('path') const tape = require('tape') const hour = 60 * 60 * 1000 @@ -24,6 +25,18 @@ const assertValidWhen = (actual, expected, name) => { a.ok(isRoughlyEqual(day + 6 * hour, +expected, ts), name + ' is out of range') } +// HTTP request mocking +if (process.env.VCR_MODE && !process.env.VCR_OFF) { + const replayer = require('replayer') + replayer.configure({ + headerWhitelist: [ + 'Content-Type', 'Accept-Encoding', 'Accept', + ], + includeHeaderValues: true, + touchHits: false, + }) + replayer.fixtureDir(join(__dirname, '..', 'fixtures')) +} const test = tape module.exports = {