-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathstart-mirage.js
More file actions
151 lines (134 loc) · 4.87 KB
/
start-mirage.js
File metadata and controls
151 lines (134 loc) · 4.87 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import readModules from './utils/read-modules';
import Server from './server';
import { singularize, pluralize } from 'ember-inflector';
import { deprecate } from '@ember/debug';
/**
Helper to start mirage. This should not be called directly. In rfc232/rfc268
tests, use `setupMirage()` or the `autoboot` option in the addon config
in the environment. In legacy tests that call `startMirage` directly, this
should be called via the `startMirage` method exported from
`<app>/initializers/ember-cli-mirage`.
This is intended to be called with only the `owner` argument (which would be
`this.owner` in an rfc232/rfc268 test, or the application instance if called
from an instance initializer). However, to support the legacy initializer, it
can instead accept a hash of the environment and config objects.
@hide
*/
export default function startMirage(
owner,
{ env, baseConfig, testConfig, makeServer } = {}
) {
if (!env || !baseConfig) {
if (!owner) {
throw new Error('You must pass `owner` to startMirage()');
}
env = env || resolveRegistration(owner, 'config:environment');
// These are set from `<app>/initializers/ember-cli-mirage`
baseConfig = baseConfig || resolveRegistration(owner, 'mirage:base-config');
testConfig = testConfig || resolveRegistration(owner, 'mirage:test-config');
makeServer = makeServer || resolveRegistration(owner, 'mirage:make-server');
}
deprecate(
'The testConfig option passed to startMirage has been deprecated. This was never documented and will no longer be supported. Please open an issue',
testConfig === undefined,
{
id: 'ember-cli-mirage-test-config',
for: 'ember-cli-mirage',
since: '2.4.0',
until: '3.0.0',
url: 'https://www.ember-cli-mirage.com/docs/advanced/server-configuration',
}
);
// Deprecate exporting makeServer as NOT the default function
deprecate(
'Do not export the makeServer function. Please make the makeServer function the default exported function',
makeServer === undefined,
{
id: 'ember-cli-mirage-config-makeserver-export',
for: 'ember-cli-mirage',
since: '2.3.0',
until: '3.0.0',
url: 'https://www.ember-cli-mirage.com/docs/advanced/server-configuration',
}
);
let routes;
// Are they using the routes as the default export
if (baseConfig && baseConfig.length === 0) {
routes = baseConfig;
deprecate(
'The routes only function has been deprecated. Please use the make server version your default export in the config.',
false,
{
id: 'ember-cli-mirage-config-routes-only-export',
for: 'ember-cli-mirage',
since: '2.4.0',
until: '3.0.0',
url: 'https://www.ember-cli-mirage.com/docs/advanced/server-configuration',
}
);
}
// Is the default exported function the makeServer function
if (baseConfig && baseConfig.length > 0) {
makeServer = baseConfig;
}
let environment = env.environment;
let mirageEnvironment = env['ember-cli-mirage'] || {};
let discoverEmberDataModels = mirageEnvironment.discoverEmberDataModels;
deprecate(
'The discoverEmberDataModels environment variable has been deprecated. See the server configuration section on how to discover models',
discoverEmberDataModels === undefined,
{
id: 'ember-cli-mirage-config-discover-ember-data-models',
for: 'ember-cli-mirage',
since: '2.4.0',
until: '3.0.0',
url: 'https://www.ember-cli-mirage.com/docs/advanced/server-configuration',
}
);
if (discoverEmberDataModels === undefined) {
discoverEmberDataModels = true;
}
let modules = readModules(env.modulePrefix);
let options = Object.assign(modules, {
environment,
routes,
testConfig,
discoverEmberDataModels,
});
deprecate(
'The trackRequests environment variable has been deprecated. The trackRequests value should on the finalConfig sent to createServer of MirageJS',
mirageEnvironment.trackRequests === undefined,
{
id: 'ember-cli-mirage-config-track-requests',
for: 'ember-cli-mirage',
since: '2.4.0',
until: '3.0.0',
url: 'https://www.ember-cli-mirage.com/docs/advanced/server-configuration',
}
);
options.trackRequests = mirageEnvironment.trackRequests;
options.inflector = { singularize, pluralize };
let server;
if (makeServer) {
server = makeServer(options);
if (
typeof location !== 'undefined' &&
location.search.indexOf('mirageLogging') !== -1
) {
server.logging = true;
}
} else {
server = new Server(options);
}
return server;
}
// Support Ember 1.13
function resolveRegistration(owner, ...args) {
if (owner.resolveRegistration) {
return owner.resolveRegistration(...args);
} else if (owner.__container__) {
return owner.__container__.lookupFactory(...args);
} else {
return owner.container.lookupFactory(...args);
}
}