This demo shows how to test Fastly services using Mocha and npm.
The solution comprises three parts:
fiddle-client.js
: JavaScript HTTP client for Fastly fiddlefiddle-mocha.js
: Mocha test generatortest.js
: Test spec
To get started quickly:
- Clone this repository
- Run
npm install
in the directory you cloned into (requires NodeJS> 10.0,0
) - Run
npm test
The test.js
file defines the Fastly service configuration and test scenarios:
spec
: The service configuration. This is a fiddle-shaped object:origins
: Array of up to 5 origin hosts (with scheme). These will be exposed to VCL asF_origin_0
up toF_origin_4
vcl
: Object, VCL code to push to each of the available subroutines within the Fastly state machine. Available subroutines are 'init', 'recv', 'hit', 'miss', 'pass', 'fetch', 'error', 'deliver', 'log'.
scenarios[]
: Array of test scenarios to run, each one an object comprising:name
: Name of the test scenariorequests[]
: A Fiddle requests array, where each item is a fiddle request-shaped object with at least atests
property
This code is available as open source under the terms of the MIT License.