From d83142e67ddd189e6350df24a18f3b16b26f8bbc Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 13 Apr 2016 10:44:09 +0100 Subject: [PATCH] Enable ability to mock endpoints in development mode no issue - moves existing mirage config into the `testConfig()` function to retain full mocks during testing - configure mirage to passthrough all requests when in development mode --- core/client/app/mirage/config.js | 23 ++++++++++++++++------- core/client/config/environment.js | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/client/app/mirage/config.js b/core/client/app/mirage/config.js index d9434b8abd..aa66a629e4 100644 --- a/core/client/app/mirage/config.js +++ b/core/client/app/mirage/config.js @@ -52,6 +52,22 @@ export default function () { this.namespace = 'ghost/api/v0.1'; // make this `api`, for example, if your API is namespaced // this.timing = 400; // delay for each request, automatically set to 0 during testing + // Mock endpoints here to override real API requests during development + + // keep this line, it allows all other API requests to hit the real server + this.passthrough(); + + // add any external domains to make sure those get passed through too + this.passthrough('https://count.ghost.org/'); + this.passthrough('http://www.gravatar.com/**'); +} + +// Mock all endpoints here as there is no real API during testing +export function testConfig() { + // this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server + this.namespace = 'ghost/api/v0.1'; // make this `api`, for example, if your API is namespaced + // this.timing = 400; // delay for each request, automatically set to 0 during testing + /* Authentication ------------------------------------------------------- */ this.post('/authentication/token', function () { @@ -326,10 +342,3 @@ export default function () { }; }); } - -/* -You can optionally export a config that is only loaded during tests -export function testConfig() { - -} -*/ diff --git a/core/client/config/environment.js b/core/client/config/environment.js index 2d9500dc13..3889a71ff3 100644 --- a/core/client/config/environment.js +++ b/core/client/config/environment.js @@ -32,6 +32,7 @@ module.exports = function (environment) { ENV.APP.LOG_TRANSITIONS = true; ENV.APP.LOG_TRANSITIONS_INTERNAL = true; ENV.APP.LOG_VIEW_LOOKUPS = true; + // Enable mirage here in order to mock API endpoints during development ENV['ember-cli-mirage'] = { enabled: false };