Skip to content

Commit ae591bb

Browse files
committed
Fix initialiser location
1 parent cf8fd03 commit ae591bb

3 files changed

Lines changed: 68 additions & 61 deletions

File tree

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

packages/ember-cli-mirage/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ module.exports = {
106106
});
107107
},
108108

109-
treeForApp(appTree) {
110-
let trees = [appTree];
109+
treeForAddon(addonTree) {
110+
let trees = [addonTree];
111111
let mirageFilesTree = new Funnel(this.mirageDirectory, {
112112
destDir: 'mirage',
113113
});
@@ -117,7 +117,7 @@ module.exports = {
117117
trees.push(this._lintMirageTree(mirageFilesTree));
118118
}
119119

120-
return mergeTrees(trees);
120+
return this._super(mergeTrees(trees));
121121
},
122122

123123
_shouldIncludeFiles() {

0 commit comments

Comments
 (0)