-
-
Notifications
You must be signed in to change notification settings - Fork 907
/
compile.js
128 lines (112 loc) · 4.1 KB
/
compile.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
var fs = require('fs'),
path = require('path'),
wrench = require('wrench'),
colors = require('colors'),
TU = require('../lib/testUtils'),
CONST = require('../../Alloy/common/constants'),
_ = require('../../Alloy/lib/alloy/underscore')._,
platforms = require('../../platforms/index');
var TIMEOUT_COMPILE = 10000;
var GEN_FOLDER = '_generated';
var alloyRoot = path.join(__dirname,'..','..'),
paths = {
apps: path.join(alloyRoot,'test','apps'),
harness: path.join(alloyRoot,'test','projects','Harness')
},
compilerDirectives = (function() {
var cds = [];
_.each(_.keys(platforms), function(p) {
cds.push('OS_' + p.toUpperCase());
});
cds.concat(_.pluck(CONST.DEPLOY_TYPES,'key'));
return cds;
})(),
cdRegex = new RegExp('(?:' + compilerDirectives.join('|') + ')');
// The alloy command test suite
describe('alloy compile', function() {
TU.addMatchers();
// Iterate through each test app and make sure it compiles for all platforms
_.each(wrench.readdirSyncRecursive(paths.apps), function(file) {
if (process.env.app && file !== process.env.app) { return; }
describe(file.yellow, function() {
var indexJs = path.join(paths.apps,file,'controllers','index.js');
if (!path.existsSync(indexJs) || indexJs.indexOf(GEN_FOLDER) !== -1) { return; }
it('preparing test app', function() {
TU.asyncExecTest('jake app:setup dir=' + file + ' quiet=1');
});
_.each(platforms, function(platform,k) {
describe(('[' + platform.platform + ']').cyan, function () {
it('compiles without critical error',
function() {
TU.asyncExecTest(
'alloy compile ' + paths.harness + ' --config platform=' + platform.platform, {
test: function() {
// Make sure there were no compile errors
expect(this.output.error).toBeFalsy();
},
timeout: TIMEOUT_COMPILE
}
);
});
it('leaves no compiler directives in generated code', function() {
var hrDir = path.join(paths.harness,'Resources');
var cPaths = [
path.join(hrDir,'alloy'),
path.join(hrDir,platform.titaniumFolder,'alloy')
];
_.each(cPaths, function(cPath) {
if (!fs.existsSync(cPath)) { return; }
var files = wrench.readdirSyncRecursive(cPath);
_.each(files, function(file) {
var fullpath = path.join(cPath,file);
if (!fs.statSync(fullpath).isFile() ||
!/\.js$/.test(fullpath)) {
return;
}
var content = fs.readFileSync(fullpath, 'utf8');
expect(cdRegex.test(content)).toBeFalsy();
});
});
});
it('has no undefined style entries', function() {
var hrDir = path.join(paths.harness,'Resources');
var cPaths = [
path.join(hrDir,'alloy','styles'),
path.join(hrDir,platform.titaniumFolder,'alloy','styles')
];
_.each(cPaths, function(cPath) {
if (!fs.existsSync(cPath)) { return; }
var files = wrench.readdirSyncRecursive(cPath);
_.each(files, function(file) {
var fullpath = path.join(cPath,file);
if (!fs.statSync(fullpath).isFile() ||
!/\.js$/.test(fullpath)) {
return;
}
var json = require(fullpath);
expect(json).toHaveNoUndefinedStyles();
});
});
});
var genFolder = path.join(paths.apps,file,GEN_FOLDER,platform.platform);
if (!fs.existsSync(genFolder)) { return; }
var hrFolder = path.join(paths.harness,'Resources');
var files = wrench.readdirSyncRecursive(genFolder);
_.each(files, function(gFile) {
var goodFile = path.join(genFolder,gFile);
if (!fs.statSync(goodFile).isFile()) { return; }
var newFile = path.join(hrFolder,gFile);
it ('generated a ' + gFile.yellow + ' file', function() {
expect(fs.existsSync(newFile)).toBeTruthy();
});
it('matches known good generated code for ' + gFile.yellow, function () {
var goodFileContents = fs.readFileSync(goodFile, 'utf8');
var newFileContents = fs.readFileSync(newFile, 'utf8');
expect(goodFileContents === newFileContents).toBeTruthy();
});
});
});
});
});
});
});