-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
104 lines (83 loc) · 2.66 KB
/
index.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
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var jsonConcat = require('broccoli-json-concat');
var middleware = require('./lib/middleware');
var bodyParser = require('body-parser');
var path = require('path');
module.exports = {
name: 'ember-cli-proxy-fixtures',
validEnv: function() {
return this.app.env !== 'production' && this.app.env !== 'staging';
},
blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},
treeForVendor: function() {
if(!this.validEnv()) { return; }
var proxyFixturesPath = path.join(this.app.project.root, 'tests/fixtures/proxy');
if (!fs.existsSync(proxyFixturesPath)) {
mkdirp.sync(proxyFixturesPath);
}
var proxyTree = jsonConcat(proxyFixturesPath, {
outputFile: 'fixtures.js',
variableName: 'window.fixtures'
});
var lib = this.treeGenerator(path.join(__dirname, 'lib'));
var qunit = this.pickFiles(lib, {
files: ['qunit.js'],
srcDir: '/',
destDir: '/'
});
return this.concatFiles(this.mergeTrees([proxyTree, qunit]), {
inputFiles: ['**/*.js'],
outputFile: '/qunit-proxy-fixtures.js'
});
},
included: function(app) {
this.app = app;
if(!this.validEnv()) { return; }
app.import('vendor/qunit-proxy-fixtures.js', {
type: 'test'
});
app.import(app.bowerDirectory + '/jquery-mockjax/jquery.mockjax.js', {
type: 'test'
});
},
serverMiddleware: function(options) {
if(!this.validEnv()) { return; }
this.project.liveReloadFilterPatterns.push('tests/fixtures/proxy');
this.middleware(options.app, options.options);
},
middleware: function(app, options) {
options.srcDir = path.join(this.project.root, 'tests/fixtures/proxy');
app.use(bodyParser.json());
app.use(middleware(options));
},
testemMiddleware: function(app) {
if(!this.validEnv()) { return; }
this.middleware(app, {});
},
postprocessTree: function(type, tree) {
if(!this.validEnv()) { return tree; }
this._requireBuildPackages();
var treeTestLoader = this.pickFiles(tree, {
files: ['test-loader.js'],
srcDir: 'assets',
destDir: 'app'
});
var lib = this.treeGenerator(path.join(__dirname, 'lib'));
var proxyTestLoader = this.pickFiles(lib, {
files: ['test-loader.js'],
srcDir: '/',
destDir: 'proxy'
});
var testLoaderTree = this.concatFiles(this.mergeTrees([treeTestLoader, proxyTestLoader]), {
inputFiles: ['**/*.js'],
outputFile: '/assets/test-loader.js'
});
return this.mergeTrees([tree, testLoaderTree], {
overwrite: true
});
}
};