[Service] Integrate DeviceHome and SignalingServer
[platform/framework/web/wrtjs.git] / device_home / node_modules / jake / test / integration / file_task.js
1 /*
2  * Jake JavaScript build tool
3  * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */
18
19 const PROJECT_DIR = process.env.PROJECT_DIR;
20
21 let assert = require('assert');
22 let fs = require('fs');
23 let exec = require('child_process').execSync;
24 let { rmRf } = require(`${PROJECT_DIR}/lib/jake`);
25
26 let cleanUpAndNext = function (callback) {
27   rmRf('./foo', {
28     silent: true
29   });
30   callback && callback();
31 };
32
33 suite('fileTask', function () {
34   this.timeout(7000);
35
36   setup(function () {
37     cleanUpAndNext();
38   });
39
40   test('where a file-task prereq does not change with --always-make', function () {
41     let out;
42     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-src1.txt').toString().trim();
43     assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
44       out);
45     out = exec('./node_modules/.bin/jake -q -B fileTest:foo/from-src1.txt').toString().trim();
46     assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
47       out);
48     cleanUpAndNext();
49   });
50
51   test('concating two files', function () {
52     let out;
53     out = exec('./node_modules/.bin/jake -q fileTest:foo/concat.txt').toString().trim();
54     assert.equal('fileTest:foo/src1.txt task\ndefault task\nfileTest:foo/src2.txt task\n' +
55           'fileTest:foo/concat.txt task', out);
56     // Check to see the two files got concat'd
57     let data = fs.readFileSync(process.cwd() + '/foo/concat.txt');
58     assert.equal('src1src2', data.toString());
59     cleanUpAndNext();
60   });
61
62   test('where a file-task prereq does not change', function () {
63     let out;
64     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-src1.txt').toString().trim();
65     assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', out);
66     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-src1.txt').toString().trim();
67     // Second time should be a no-op
68     assert.equal('', out);
69     cleanUpAndNext();
70   });
71
72   test('where a file-task prereq does change, then does not', function (next) {
73     exec('mkdir -p ./foo');
74     exec('touch ./foo/from-src1.txt');
75     setTimeout(() => {
76       fs.writeFileSync('./foo/src1.txt', '-SRC');
77       // Task should run the first time
78       let out;
79       out = exec('./node_modules/.bin/jake -q fileTest:foo/from-src1.txt').toString().trim();
80       assert.equal('fileTest:foo/from-src1.txt task', out);
81       // Task should not run on subsequent invocation
82       out = exec('./node_modules/.bin/jake -q fileTest:foo/from-src1.txt').toString().trim();
83       assert.equal('', out);
84       cleanUpAndNext(next);
85     }, 1000);
86   });
87
88   test('a preexisting file', function () {
89     let prereqData = 'howdy';
90     exec('mkdir -p ./foo');
91     fs.writeFileSync('foo/prereq.txt', prereqData);
92     let out;
93     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-prereq.txt').toString().trim();
94     assert.equal('fileTest:foo/from-prereq.txt task', out);
95     let data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
96     assert.equal(prereqData, data.toString());
97     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-prereq.txt').toString().trim();
98     // Second time should be a no-op
99     assert.equal('', out);
100     cleanUpAndNext();
101   });
102
103   test('a preexisting file with --always-make flag', function () {
104     let prereqData = 'howdy';
105     exec('mkdir -p ./foo');
106     fs.writeFileSync('foo/prereq.txt', prereqData);
107     let out;
108     out = exec('./node_modules/.bin/jake -q fileTest:foo/from-prereq.txt').toString().trim();
109     assert.equal('fileTest:foo/from-prereq.txt task', out);
110     let data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
111     assert.equal(prereqData, data.toString());
112     out = exec('./node_modules/.bin/jake -q -B fileTest:foo/from-prereq.txt').toString().trim();
113     assert.equal('fileTest:foo/from-prereq.txt task', out);
114     cleanUpAndNext();
115   });
116
117   test('nested directory-task', function () {
118     exec('./node_modules/.bin/jake -q fileTest:foo/bar/baz/bamf.txt');
119     let data = fs.readFileSync(process.cwd() + '/foo/bar/baz/bamf.txt');
120     assert.equal('w00t', data);
121     cleanUpAndNext();
122   });
123
124 });
125