-
Notifications
You must be signed in to change notification settings - Fork 433
Expand file tree
/
Copy pathember-cli-mirage.js
More file actions
68 lines (61 loc) · 2 KB
/
ember-cli-mirage.js
File metadata and controls
68 lines (61 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ENV from '../config/environment';
import getRfc232TestContext from 'ember-cli-mirage/get-rfc232-test-context';
import startMirageImpl from 'ember-cli-mirage/start-mirage';
import * as config from '../mirage/config';
const { default: baseConfig, testConfig, makeServer } = config;
//
// This initializer does two things:
//
// 1. Pulls the mirage config objects from the application's config and
// registers them in the container so `ember-cli-mirage/start-mirage` can
// find them (since it doesn't have access to the app's namespace).
// 2. Provides legacy support for auto-starting mirage in pre-rfc268 acceptance
// tests.
//
export default {
name: 'ember-cli-mirage',
initialize(application) {
if (baseConfig) {
application.register('mirage:base-config', baseConfig, {
instantiate: false,
});
}
if (testConfig) {
application.register('mirage:test-config', testConfig, {
instantiate: false,
});
}
if (makeServer) {
application.register('mirage:make-server', makeServer, {
instantiate: false,
});
}
ENV['ember-cli-mirage'] = ENV['ember-cli-mirage'] || {};
if (_shouldUseMirage(ENV.environment, ENV['ember-cli-mirage'])) {
startMirage(ENV);
}
},
};
export function startMirage(env = ENV) {
return startMirageImpl(null, { env, baseConfig, testConfig, makeServer });
}
function _shouldUseMirage(env, addonConfig) {
if (typeof FastBoot !== 'undefined') {
return false;
}
if (getRfc232TestContext()) {
return false;
}
let userDeclaredEnabled = typeof addonConfig.enabled !== 'undefined';
let defaultEnabled = _defaultEnabled(env, addonConfig);
return userDeclaredEnabled ? addonConfig.enabled : defaultEnabled;
}
/*
Returns a boolean specifying the default behavior for whether
to initialize Mirage.
*/
function _defaultEnabled(env, addonConfig) {
let usingInDev = env === 'development' && !addonConfig.usingProxy;
let usingInTest = env === 'test';
return usingInDev || usingInTest;
}