Select Git revision
maxArrayLength.js
file.js 6.44 KiB
/*
* Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const PROJECT_DIR = process.env.PROJECT_DIR;
let assert = require('assert');
let fs = require('fs');
let path = require('path');
let file = require(`${PROJECT_DIR}/lib/utils/file`);
let existsSync = fs.existsSync || path.existsSync;
let exec = require('child_process').execSync;
suite('fileUtils', function () {
test('mkdirP', function () {
let expected = [
['foo'],
['foo', 'bar'],
['foo', 'bar', 'baz'],
['foo', 'bar', 'baz', 'qux']
];
file.mkdirP('foo/bar/baz/qux');
let res = exec('find foo').toString().trim().split('\n');
for (let i = 0, ii = res.length; i < ii; i++) {
assert.equal(path.join.apply(path, expected[i]), res[i]);
}
file.rmRf('foo');
});
test('rmRf', function () {
file.mkdirP('foo/bar/baz/qux');
file.rmRf('foo/bar');
let res = exec('find foo').toString().trim().split('\n');
assert.equal(1, res.length);
assert.equal('foo', res[0]);
fs.rmdirSync('foo');
});
test('rmRf with symlink subdir', function () {
file.mkdirP('foo');
file.mkdirP('bar');
fs.writeFileSync('foo/hello.txt', 'hello, it\'s me');
fs.symlinkSync('../foo', 'bar/foo'); file.rmRf('bar');
// Make sure the bar directory was successfully deleted
let barDeleted = false;
try {
fs.statSync('bar');
} catch(err) {
if(err.code == 'ENOENT') {
barDeleted = true;
}
}
assert.equal(true, barDeleted);