2 * Jake JavaScript build tool
3 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 const PROJECT_DIR = process.env.PROJECT_DIR;
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`);
26 let cleanUpAndNext = function (callback) {
30 callback && callback();
33 suite('fileTask', function () {
40 test('where a file-task prereq does not change with --always-make', function () {
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',
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',
51 test('concating two files', function () {
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());
62 test('where a file-task prereq does not change', function () {
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);
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');
76 fs.writeFileSync('./foo/src1.txt', '-SRC');
77 // Task should run the first time
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);
88 test('a preexisting file', function () {
89 let prereqData = 'howdy';
90 exec('mkdir -p ./foo');
91 fs.writeFileSync('foo/prereq.txt', prereqData);
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);
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);
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);
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);