source: frontend/node_modules/jake/test/integration/file_task.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 5.0 KB
Line 
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
19const PROJECT_DIR = process.env.PROJECT_DIR;
20const JAKE_CMD = `${PROJECT_DIR}/bin/cli.js`;
21
22let assert = require('assert');
23let fs = require('fs');
24let exec = require('child_process').execSync;
25let { rmRf } = require(`${PROJECT_DIR}/lib/jake`);
26
27let cleanUpAndNext = function (callback) {
28 rmRf('./foo', {
29 silent: true
30 });
31 callback && callback();
32};
33
34suite('fileTask', function () {
35 this.timeout(7000);
36
37 setup(function () {
38 cleanUpAndNext();
39 });
40
41 test('where a file-task prereq does not change with --always-make', function () {
42 let out;
43 out = exec(`${JAKE_CMD} -q fileTest:foo/from-src1.txt`).toString().trim();
44 assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
45 out);
46 out = exec(`${JAKE_CMD} -q -B fileTest:foo/from-src1.txt`).toString().trim();
47 assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
48 out);
49 cleanUpAndNext();
50 });
51
52 test('concating two files', function () {
53 let out;
54 out = exec(`${JAKE_CMD} -q fileTest:foo/concat.txt`).toString().trim();
55 assert.equal('fileTest:foo/src1.txt task\ndefault task\nfileTest:foo/src2.txt task\n' +
56 'fileTest:foo/concat.txt task', out);
57 // Check to see the two files got concat'd
58 let data = fs.readFileSync(process.cwd() + '/foo/concat.txt');
59 assert.equal('src1src2', data.toString());
60 cleanUpAndNext();
61 });
62
63 test('where a file-task prereq does not change', function () {
64 let out;
65 out = exec(`${JAKE_CMD} -q fileTest:foo/from-src1.txt`).toString().trim();
66 assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', out);
67 out = exec(`${JAKE_CMD} -q fileTest:foo/from-src1.txt`).toString().trim();
68 // Second time should be a no-op
69 assert.equal('', out);
70 cleanUpAndNext();
71 });
72
73 test('where a file-task prereq does change, then does not', function (next) {
74 exec('mkdir -p ./foo');
75 exec('touch ./foo/from-src1.txt');
76 setTimeout(() => {
77 fs.writeFileSync('./foo/src1.txt', '-SRC');
78 // Task should run the first time
79 let out;
80 out = exec(`${JAKE_CMD} -q fileTest:foo/from-src1.txt`).toString().trim();
81 assert.equal('fileTest:foo/from-src1.txt task', out);
82 // Task should not run on subsequent invocation
83 out = exec(`${JAKE_CMD} -q fileTest:foo/from-src1.txt`).toString().trim();
84 assert.equal('', out);
85 cleanUpAndNext(next);
86 }, 1000);
87 });
88
89 test('a preexisting file', function () {
90 let prereqData = 'howdy';
91 exec('mkdir -p ./foo');
92 fs.writeFileSync('foo/prereq.txt', prereqData);
93 let out;
94 out = exec(`${JAKE_CMD} -q fileTest:foo/from-prereq.txt`).toString().trim();
95 assert.equal('fileTest:foo/from-prereq.txt task', out);
96 let data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
97 assert.equal(prereqData, data.toString());
98 out = exec(`${JAKE_CMD} -q fileTest:foo/from-prereq.txt`).toString().trim();
99 // Second time should be a no-op
100 assert.equal('', out);
101 cleanUpAndNext();
102 });
103
104 test('a preexisting file with --always-make flag', function () {
105 let prereqData = 'howdy';
106 exec('mkdir -p ./foo');
107 fs.writeFileSync('foo/prereq.txt', prereqData);
108 let out;
109 out = exec(`${JAKE_CMD} -q fileTest:foo/from-prereq.txt`).toString().trim();
110 assert.equal('fileTest:foo/from-prereq.txt task', out);
111 let data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
112 assert.equal(prereqData, data.toString());
113 out = exec(`${JAKE_CMD} -q -B fileTest:foo/from-prereq.txt`).toString().trim();
114 assert.equal('fileTest:foo/from-prereq.txt task', out);
115 cleanUpAndNext();
116 });
117
118 test('nested directory-task', function () {
119 exec(`${JAKE_CMD} -q fileTest:foo/bar/baz/bamf.txt`);
120 let data = fs.readFileSync(process.cwd() + '/foo/bar/baz/bamf.txt');
121 assert.equal('w00t', data);
122 cleanUpAndNext();
123 });
124
125 test('partially existing prereqs', function () {
126 /*
127 dependency graph:
128 /-- foo/output2a.txt --\
129 foo -- foo/output1.txt --+ +-- output3.txt
130 \-- foo/output2b.txt --/
131 */
132 // build part of the prereqs
133 exec(`${JAKE_CMD} -q fileTest:foo/output2a.txt`);
134 // verify the final target gets built
135 exec(`${JAKE_CMD} -q fileTest:foo/output3.txt`);
136 let data = fs.readFileSync(process.cwd() + '/foo/output3.txt');
137 assert.equal('w00t', data);
138 cleanUpAndNext();
139 });
140});
141
Note: See TracBrowser for help on using the repository browser.