forked from xolvio/qualityfaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallaby_server.js
287 lines (246 loc) · 10.4 KB
/
wallaby_server.js
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
var babel = require('babel-core');
var path = require('path');
module.exports = function (wallaby) {
var babelCompiler = wallaby.compilers.babel({
babel: babel,
presets: ['react', 'es2015', 'stage-0'],
plugins: ['transform-decorators-legacy']
});
process.env.NODE_PATH += path.delimiter +
path.join(
wallaby.localProjectDir,
'src/.meteor/local/build/programs/server/node_modules'
);
process.env.NODE_PATH += path.delimiter +
path.join(wallaby.projectCacheDir, 'src', 'imports');
return {
files: [
{pattern: 'src/imports/**/*-spec.@(js|jsx)', ignore: true},
{pattern: 'src/imports/**/ui/**/*.@(js|jsx)', ignore: true},
{pattern: 'src/imports/**/*.@(js|jsx)', load: false},
],
tests: [
{pattern: 'src/imports/**/*-spec.@(js|jsx)'},
{pattern: 'src/imports/**/ui/**/*-spec.@(js|jsx)', ignore: true},
{pattern: 'tests/jasmine/server/unit/**/*-spec.@(js|jsx)'},
{pattern: 'tests/jasmine/server/unit/quarantine/**/*.@(js|jsx)', ignore: true},
],
compilers: {
// Important: Make sure that src/.meteor/ is excluded from the pattern
'src/imports/**/*.@(js|jsx)': babelCompiler,
'tests/jasmine/server/unit/**/*.@(js|jsx)': babelCompiler,
},
bootstrap: function () {
wallaby.delayStart();
var path = require("path");
if (!process.env.ROOT_URL) {
process.env.ROOT_URL = 'http://localhost:3000/';
}
if (!process.env.MONGO_URL) {
process.env.MONGO_URL = 'mongodb://127.0.0.1:3001/wallaby-server';
}
var serverAppPath = path.resolve(
wallaby.localProjectDir,
'src/.meteor/local/build/programs/server'
);
var Fiber = require('fibers');
var fs = require('fs');
var Future = require('fibers/future');
var _ = require('underscore');
var files = require(path.resolve(serverAppPath, './mini-files.js'));
// read our control files
var serverJsonPath = path.resolve(serverAppPath, 'program.json');
process.argv[2] = serverJsonPath;
var serverDir = path.dirname(serverJsonPath);
var serverJson = JSON.parse(fs.readFileSync(serverJsonPath, 'utf8'));
var configJson =
JSON.parse(fs.readFileSync(path.resolve(serverDir, 'config.json'), 'utf8'));
// Set up environment
global.__meteor_bootstrap__ = {
startupHooks: [],
serverDir: serverDir,
configJson: configJson };
global.__meteor_runtime_config__ = { meteorRelease: configJson.meteorRelease };
// connect (and some other NPM modules) use $NODE_ENV to make some decisions;
// eg, if $NODE_ENV is not production, they send stack traces on error. connect
// considers 'development' to be the default mode, but that's less safe than
// assuming 'production' to be the default. If you really want development mode,
// set it in your wrapper script (eg, run-app.js).
if (!process.env.NODE_ENV)
process.env.NODE_ENV = 'production';
var excludedPackages = [
'packages/sanjo_karma.js',
'packages/sanjo_long-running-child-process.js',
'packages/velocity_chokidar.js',
'packages/velocity_console-reporter.js',
'packages/velocity_core.js',
'packages/velocity_meteor-internals.js',
'packages/velocity_meteor-stubs.js',
'packages/velocity_shim.js',
'packages/velocity_source-map-support.js',
'packages/xolvio_jasmine-server-integration.js',
];
var shouldLoadPackage = function (fileInfo) {
return fileInfo.path.indexOf('packages/') === 0 &&
!_.contains(excludedPackages, fileInfo.path);
};
Fiber(function () {
_.each(serverJson.load, function (fileInfo) {
if (!shouldLoadPackage(fileInfo)) {
return;
}
var code = fs.readFileSync(path.resolve(serverDir, fileInfo.path));
var Npm = {
/**
* @summary Require a package that was specified using
* `Npm.depends()`.
* @param {String} name The name of the package to require.
* @locus Server
* @memberOf Npm
*/
require: function (name) {
if (!fileInfo.node_modules) {
return require(name);
}
var nodeModuleBase = path.resolve(serverDir,
files.convertToOSPath(fileInfo.node_modules));
var nodeModuleDir = path.resolve(nodeModuleBase, name);
// If the user does `Npm.require('foo/bar')`, then we should resolve to
// the package's node modules if `foo` was one of the modules we
// installed. (`foo/bar` might be implemented as `foo/bar.js` so we
// can't just naively see if all of nodeModuleDir exists.
if (fs.existsSync(path.resolve(nodeModuleBase, name.split("/")[0]))) {
return require(nodeModuleDir);
}
try {
return require(name);
} catch (e) {
// Try to guess the package name so we can print a nice
// error message
// fileInfo.path is a standard path, use files.pathSep
var filePathParts = fileInfo.path.split(files.pathSep);
var packageName = filePathParts[1].replace(/\.js$/, '');
// XXX better message
throw new Error(
"Can't find npm module '" + name +
"'. Did you forget to call 'Npm.depends' in package.js " +
"within the '" + packageName + "' package?");
}
}
};
var getAsset = function (assetPath, encoding, callback) {
var fut;
if (!callback) {
fut = new Future();
callback = fut.resolver();
}
// This assumes that we've already loaded the meteor package, so meteor
// itself can't call Assets.get*. (We could change this function so that
// it doesn't call bindEnvironment if you don't pass a callback if we need
// to.)
var _callback = Package.meteor.Meteor.bindEnvironment(function (err, result) {
if (result && !encoding)
// Sadly, this copies in Node 0.10.
result = new Uint8Array(result);
callback(err, result);
}, function (e) {
console.log("Exception in callback of getAsset", e.stack);
});
// Convert a DOS-style path to Unix-style in case the application code was
// written on Windows.
assetPath = files.convertToStandardPath(assetPath);
if (!fileInfo.assets || !_.has(fileInfo.assets, assetPath)) {
_callback(new Error("Unknown asset: " + assetPath));
} else {
var filePath = path.join(serverDir, fileInfo.assets[assetPath]);
fs.readFile(files.convertToOSPath(filePath), encoding, _callback);
}
if (fut)
return fut.wait();
};
var Assets = {
getText: function (assetPath, callback) {
return getAsset(assetPath, "utf8", callback);
},
getBinary: function (assetPath, callback) {
return getAsset(assetPath, undefined, callback);
}
};
// \n is necessary in case final line is a //-comment
var wrapped = "(function(Npm, Assets){" + code + "\n})";
// It is safer to use the absolute path when source map is present as
// different tooling, such as node-inspector, can get confused on relative
// urls.
// fileInfo.path is a standard path, convert it to OS path to join with
// __dirname
var fileInfoOSPath = files.convertToOSPath(fileInfo.path);
// The final 'true' is an undocumented argument to runIn[Foo]Context that
// causes it to print out a descriptive error message on parse error. It's
// what require() uses to generate its errors.
var func = require('vm').runInThisContext(wrapped, fileInfoOSPath, true);
func.call(global, Npm, Assets); // Coffeescript
});
global.Npm = {
/**
* @summary Require a package that was specified using
* `Npm.depends()`.
* @param {String} name The name of the package to require.
* @locus Server
* @memberOf Npm
*/
require: function (name) {
return require(name);
}
};
var getAsset = function (assetPath, encoding, callback) {
var fut;
if (!callback) {
fut = new Future();
callback = fut.resolver();
}
// This assumes that we've already loaded the meteor package, so meteor
// itself can't call Assets.get*. (We could change this function so that
// it doesn't call bindEnvironment if you don't pass a callback if we need
// to.)
var _callback = Package.meteor.Meteor.bindEnvironment(function (err, result) {
if (result && !encoding)
// Sadly, this copies in Node 0.10.
result = new Uint8Array(result);
callback(err, result);
}, function (e) {
console.log("Exception in callback of getAsset", e.stack);
});
// Convert a DOS-style path to Unix-style in case the application code was
// written on Windows.
assetPath = files.convertToStandardPath(assetPath);
var filePath = path.join(serverDir, 'assets/app', assetPath);
try {
fs.readFile(files.convertToOSPath(filePath), encoding, _callback);
} catch (error) {
_callback(new Error("Unknown asset: " + assetPath));
}
if (fut)
return fut.wait();
};
global.Assets = {
getText: function (assetPath, callback) {
return getAsset(assetPath, "utf8", callback);
},
getBinary: function (assetPath, callback) {
return getAsset(assetPath, undefined, callback);
}
};
wallaby.start();
}).run();
},
env: {
type: 'node',
runner: path.resolve(process.env.HOME, '.nvm/v0.10.40/bin/node')
},
testFramework: 'jasmine',
workers: {
recycle: true
},
debug: true
};
};