mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	integration testing using replayer ✅
This commit is contained in:
		
							parent
							
								
									51b3ca3c20
								
							
						
					
					
						commit
						0c3acaba46
					
				
					 3 changed files with 25 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								package.json
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								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"
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 = {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue