|
1 | | -import ENV from '../config/environment'; |
2 | | -import getRfc232TestContext from 'ember-cli-mirage/get-rfc232-test-context'; |
3 | | -import startMirageImpl from 'ember-cli-mirage/start-mirage'; |
4 | | -import * as config from '../mirage/config'; |
5 | | -const { default: makeServer } = config; |
6 | | - |
7 | | -// |
8 | | -// This initializer does two things: |
9 | | -// |
10 | | -// 1. Pulls the mirage config objects from the application's config and |
11 | | -// registers them in the container so `ember-cli-mirage/start-mirage` can |
12 | | -// find them (since it doesn't have access to the app's namespace). |
13 | | -// 2. Provides legacy support for auto-starting mirage in pre-rfc268 acceptance |
14 | | -// tests. |
15 | | -// |
16 | | -export default { |
17 | | - name: 'ember-cli-mirage', |
18 | | - initialize(application) { |
19 | | - if (makeServer) { |
20 | | - application.register('mirage:make-server', makeServer, { |
21 | | - instantiate: false, |
22 | | - }); |
23 | | - } |
24 | | - |
25 | | - ENV['ember-cli-mirage'] = ENV['ember-cli-mirage'] || {}; |
26 | | - if (_shouldUseMirage(ENV.environment, ENV['ember-cli-mirage'])) { |
27 | | - startMirage(application.__container__, ENV); |
28 | | - } |
29 | | - }, |
30 | | -}; |
31 | | - |
32 | | -function startMirage(owner, env = ENV) { |
33 | | - return startMirageImpl(owner, { env, makeServer }); |
34 | | -} |
35 | | - |
36 | | -function _shouldUseMirage(env, addonConfig) { |
37 | | - if (typeof FastBoot !== 'undefined') { |
38 | | - return false; |
39 | | - } |
40 | | - if (getRfc232TestContext()) { |
41 | | - return false; |
42 | | - } |
43 | | - let userDeclaredEnabled = typeof addonConfig.enabled !== 'undefined'; |
44 | | - let defaultEnabled = _defaultEnabled(env, addonConfig); |
45 | | - |
46 | | - return userDeclaredEnabled ? addonConfig.enabled : defaultEnabled; |
47 | | -} |
48 | | - |
49 | | -/* |
50 | | - Returns a boolean specifying the default behavior for whether |
51 | | - to initialize Mirage. |
52 | | -*/ |
53 | | -function _defaultEnabled(env, addonConfig) { |
54 | | - let usingInDev = env === 'development' && !addonConfig.usingProxy; |
55 | | - let usingInTest = env === 'test'; |
56 | | - |
57 | | - return usingInDev || usingInTest; |
58 | | -} |
| 1 | +export { |
| 2 | + default, |
| 3 | + initialize, |
| 4 | +} from 'ember-cli-mirage/initializers/ember-cli-mirage'; |
0 commit comments