1 | var fs = require('fs.extra');
|
2 | var spawn = require('child_process').spawn;
|
3 | var expect = require('chai').expect;
|
4 | var nock = require('nock');
|
5 | var path = require('path');
|
6 | var request = require('request');
|
7 |
|
8 |
|
9 | var fake = !process.env.NOCK_OFF;
|
10 |
|
11 | describe("compy should", function(){
|
12 | after(cleanDir);
|
13 |
|
14 | describe('install', function(){
|
15 | this.timeout(100000);
|
16 | var github = nock('https://raw.github.com:443')
|
17 | .get('/component/model/master/component.json')
|
18 | .reply(200,JSON.stringify({}),{'content-type': 'text/plain; charset=utf-8'});
|
19 | before(function(done){
|
20 | cleanDir(function(){
|
21 | prepareDir(function(){
|
22 | runCompyWith('install', done);
|
23 | });
|
24 | })
|
25 | })
|
26 | it('should create compoents folder', function(done){
|
27 | expect(fs.existsSync(__dirname + '/tempdata/components')).to.be.ok;
|
28 | done();
|
29 | })
|
30 | it('install component-model dependency from pachage.json', function(done){
|
31 | expect(fs.existsSync(__dirname + '/tempdata/components/component-model')).to.be.ok;
|
32 | done();
|
33 | })
|
34 | it('with component.json inside', function(done){
|
35 | expect(fs.existsSync(__dirname + '/tempdata/components/component-model/component.json')).to.be.ok;
|
36 | done();
|
37 | })
|
38 | })
|
39 |
|
40 | describe('install <component name> - component/domify', function(){
|
41 | this.timeout(100000);
|
42 | var github = nock('https://raw.github.com:443')
|
43 | .get('/component/domify/master/component.json')
|
44 | .reply(200,JSON.stringify({}),{'content-type': 'text/plain; charset=utf-8'});
|
45 |
|
46 | before(function(done){
|
47 | cleanDir(function(){
|
48 | prepareDir(function(){
|
49 | runCompyWith(['install','component/domify'], done);
|
50 | });
|
51 | })
|
52 | })
|
53 | it('should create compoents folder', function(done){
|
54 | expect(fs.existsSync(__dirname + '/tempdata/components')).to.be.ok;
|
55 | done();
|
56 | })
|
57 | it('fetch component/domify', function(done){
|
58 | expect(fs.existsSync(__dirname + '/tempdata/components/component-domify')).to.be.ok;
|
59 | done();
|
60 | })
|
61 | it('with component.json inside', function(done){
|
62 | expect(fs.existsSync(__dirname + '/tempdata/components/component-domify/component.json')).to.be.ok;
|
63 | done();
|
64 | })
|
65 | it('save it as dependency in local package.json', function(done){
|
66 | expect(require(__dirname + '/tempdata/package.json').compy.dependencies).to.have.property("component/domify","*");
|
67 | done();
|
68 | })
|
69 |
|
70 | })
|
71 |
|
72 | describe('compile #compile', function(){
|
73 | this.timeout(100000);
|
74 | var github = nock('https://raw.github.com:443')
|
75 | .get('/component/model/master/component.json')
|
76 | .reply(200,JSON.stringify({}),{'content-type': 'text/plain; charset=utf-8'});
|
77 |
|
78 | before(function(done){
|
79 | cleanDir(function(){
|
80 | prepareDir(function(){
|
81 | runCompyWith('install', function(){
|
82 | runCompyWith('compile', done);
|
83 | });
|
84 | });
|
85 | })
|
86 | })
|
87 | it('should exists /dist folder', function(done){
|
88 | expect(fs.existsSync(__dirname + '/tempdata/dist')).to.be.ok;
|
89 | done();
|
90 | })
|
91 | it('folder should contain index.html and app.js files', function(done){
|
92 | expect(fs.existsSync(__dirname + '/tempdata/dist/index.html')).to.be.ok;
|
93 | expect(fs.existsSync(__dirname + '/tempdata/dist/app.js')).to.be.ok;
|
94 | done();
|
95 | })
|
96 | it('app.js should contain special string', function(done){
|
97 | expect(fs.readFileSync(__dirname + '/tempdata/dist/app.js').toString()).to.contain('/* test string */');
|
98 | done();
|
99 | })
|
100 | it('some.tocopy.tst file should exists in /dist folder [local GRUNTFILE test]', function(done){
|
101 | expect(fs.existsSync(__dirname + '/tempdata/dist/some.tocopy.tst')).to.be.ok;
|
102 | done();
|
103 | })
|
104 |
|
105 | it('.coffee script files should be compiled in javascript', function(done){
|
106 | expect(fs.readFileSync(__dirname + '/tempdata/dist/app.js').toString()).to.contain('if (opposite_check) {');
|
107 | done();
|
108 | })
|
109 | })
|
110 |
|
111 |
|
112 |
|
113 | describe('set static server', function(){
|
114 | this.timeout(100000);
|
115 | var github = nock('https://raw.github.com:443')
|
116 | .get('/component/model/master/component.json')
|
117 | .reply(200,JSON.stringify({}),{'content-type': 'text/plain; charset=utf-8'});
|
118 |
|
119 | before(function(done){
|
120 | cleanDir(function(){
|
121 | prepareDir(function(){
|
122 | runCompyWith('install', function(){
|
123 | runCompyWith('compile', function(){
|
124 | runCompyWith('server');
|
125 | done();
|
126 | });
|
127 | });
|
128 | });
|
129 | })
|
130 | })
|
131 | it('should ping localhost port 8080', function(done){
|
132 | request.get("http://localhost:8080", function(err, res, body){
|
133 | expect(res).to.have.property("statusCode", 200);
|
134 | expect(body).to.be.ok;
|
135 | request.get("http://localhost:8080/app.js", gotJs);
|
136 | })
|
137 | function gotJs(err, res, body){
|
138 | expect(res).to.have.property("statusCode", 200);
|
139 | expect(body).to.be.ok;
|
140 | request.get("http://localhost:8080/app.css", gotCss);
|
141 | }
|
142 | function gotCss(err, res, body){
|
143 | expect(res).to.have.property("statusCode", 200);
|
144 | expect(body).to.be.ok;
|
145 | done();
|
146 | }
|
147 | })
|
148 | })
|
149 | })
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | function runCompyWith(comands, done){
|
161 | var args = [__dirname + '/../bin/compy'].concat(comands);
|
162 | if(fake){
|
163 | var oldDir = process.cwd();
|
164 | process.chdir(__dirname + "/tempdata");
|
165 | var oldArgv = process.argv;
|
166 | process.argv = ['node','mocha'].concat(comands);
|
167 | var oldExit = process.exit;
|
168 | var oldRequire = Object.keys(require.cache);
|
169 | process.exit = function(code){
|
170 | process.exit = oldExit;
|
171 | process.chdir(oldDir);
|
172 | process.argv = oldArgv;
|
173 | Object.keys(require.cache).forEach(function(reqModule){
|
174 | if(!~oldRequire.indexOf(reqModule)){
|
175 | delete require.cache[reqModule];
|
176 | }
|
177 | })
|
178 | return done && done();
|
179 | }
|
180 | require('../bin/compy');
|
181 | return;
|
182 | }
|
183 | var compy = spawn('node', args, {cwd: __dirname + "/tempdata" });
|
184 | compy.on('close', function(){
|
185 | done()
|
186 | });
|
187 | compy.stdout.on('data', function(data){
|
188 | console.log(data.toString());
|
189 | })
|
190 | compy.stderr.on('data', function(data){
|
191 | console.log(data.toString());
|
192 | })
|
193 | }
|
194 |
|
195 | function prepareDir(done){
|
196 | fs.copyRecursive( __dirname + '/testdata', __dirname + '/tempdata', done);
|
197 | }
|
198 |
|
199 | function cleanDir(done){
|
200 | fs.rmrf( __dirname + '/tempdata', done);
|
201 | }
|