Browse Source

Removed CoffeeScript tests.

ci/travis-osximage
JP Richardson 12 years ago
parent
commit
923085a95a
  1. 42
      Cakefile
  2. 1
      package.json
  3. 70
      test/copy.test.coffee
  4. 85
      test/copy.test.js
  5. 38
      test/mkdir.test.coffee
  6. 61
      test/mkdir.test.js
  7. 36
      test/read.test.coffee
  8. 49
      test/read.test.js
  9. 106
      test/remove.test.coffee
  10. 128
      test/remove.test.js

42
Cakefile

@ -1,42 +0,0 @@
{spawn} = require('child_process')
testutil = require('testutil')
growl = require('growl')
option '-g', '--grep [PATTERN]', 'only run tests matching <pattern>'
task 'build', 'build lib/ from src/', ->
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src']
coffee.stderr.on 'data', (data) -> process.stderr.write data.toString()
coffee.stdout.on 'data', (data) -> process.stdout.write data.toString()
coffee.on 'exit', (code) ->
if code is 0
console.log 'Successfully built.'
else
console.log "Error building. Code: #{code}"
task 'test', 'test project', (options) ->
process.env['NODE_ENV'] = 'test'
testutil.fetchTestFiles './test', (files) ->
files.unshift '--colors'
if options.grep?
files.unshift options.grep
files.unshift '--grep'
mocha = spawn 'mocha', files#, customFds: [0..2]
mocha.stdout.pipe(process.stdout, end: false);
mocha.stderr.pipe(process.stderr, end: false);
task 'watch', 'Watch src/ for changes', ->
coffee = spawn 'coffee', ['-w', '-c', '-o', 'lib', 'src']
coffee.stderr.on 'data', (data) -> 'ERR: ' + process.stderr.write data.toString()
coffee.stdout.on 'data', (data) ->
d = data.toString()
if d.indexOf('compiled') > 0
#invoke 'test'
do (->)
else
growl(d, title: 'Error', image: './resources/error.png')
process.stdout.write data.toString()
#mocha = spawn 'mocha', ['-w']

1
package.json

@ -34,7 +34,6 @@
},
"devDependencies": {
"mocha": "1.4.x",
"coffee-script": "1.3.x",
"path-extra": "0.0.x",
"testutil": "~0.2.2"
},

70
test/copy.test.coffee

@ -1,70 +0,0 @@
crypto = require('crypto')
fs = require('../lib')
path = require('path-extra')
testutil = require('testutil')
mkdir = require('mkdirp')
SIZE = 16*64*1024+7
DIR = ''
describe 'fs-extra', ->
beforeEach (done) ->
DIR = testutil.createTempDir()
done()
afterEach (done) ->
fs.remove DIR, (done)
###
describe '+ copyFileSync()', ->
it 'should copy synchronously', ->
fileSrc = path.join(DIR, "TEST_fs-extra_src")
fileDest = path.join(DIR, "TEST_fs-extra_copy")
fileSrc = testutil.createFileWithData(fileSrc, SIZE)
srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')
fs.copyFileSync(fileSrc, fileDest)
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex")
T srcMd5 is destMd5
###
describe '+ copy()', ->
it 'should copy the file asynchronously', (done) ->
fileSrc = path.join(DIR, "TEST_fs-extra_src")
fileDest = path.join(DIR, "TEST_fs-extra_copy")
fileSrc = testutil.createFileWithData(fileSrc, SIZE)
srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest("hex")
destMd5 = ''
fs.copy fileSrc, fileDest, (err) ->
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex")
#T bufMd5 is destMd5
T srcMd5 is destMd5
done()
it 'should copy the directory asynchronously', (done) ->
FILES = 2
src = path.join(DIR, 'src')
dest = path.join(DIR, 'dest')
mkdir src, (err) ->
testutil.createFileWithData(path.join(src, i.toString()), SIZE) for i in [0...FILES] #create 3 files
subdir = path.join(src, 'subdir')
mkdir subdir, (err) ->
testutil.createFileWithData(path.join(subdir, i.toString()), SIZE) for i in [0...FILES] #create 3 files
fs.copy src, dest, (err) ->
T err is null
T fs.existsSync dest
T fs.existsSync path.join(dest, i.toString()) for i in [0...FILES]
destSub = path.join(dest, 'subdir')
T fs.existsSync path.join(destSub, i.toString()) for i in [0...FILES]
done()

85
test/copy.test.js

@ -0,0 +1,85 @@
var crypto = require('crypto')
, fs = require('../lib')
, path = require('path-extra')
, testutil = require('testutil')
, mkdir = require('mkdirp');
var SIZE = 16 * 64 * 1024 + 7;
var DIR = '';
describe('fs-extra', function() {
beforeEach(function(done) {
DIR = testutil.createTempDir();
done();
})
afterEach(function(done) {
fs.remove(DIR, done);
})
/*
describe '+ copyFileSync()', ->
it 'should copy synchronously', ->
fileSrc = path.join(DIR, "TEST_fs-extra_src")
fileDest = path.join(DIR, "TEST_fs-extra_copy")
fileSrc = testutil.createFileWithData(fileSrc, SIZE)
srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest('hex')
fs.copyFileSync(fileSrc, fileDest)
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex")
T srcMd5 is destMd5
*/
describe('+ copy()', function() {
it('should copy the file asynchronously', function(done) {
var fileSrc = path.join(DIR, "TEST_fs-extra_src")
, fileDest = path.join(DIR, "TEST_fs-extra_copy")
, fileSrc = testutil.createFileWithData(fileSrc, SIZE)
, srcMd5 = crypto.createHash('md5').update(fs.readFileSync(fileSrc)).digest("hex")
, destMd5 = '';
fs.copy(fileSrc, fileDest, function(err) {
destMd5 = crypto.createHash('md5').update(fs.readFileSync(fileDest)).digest("hex");
T (srcMd5 === destMd5);
done()
})
})
it('should copy the directory asynchronously', function(done) {
var FILES = 2
, src = path.join(DIR, 'src')
, dest = path.join(DIR, 'dest');
mkdir(src, function(err) {
for (var i = 0; i < FILES; ++i)
testutil.createFileWithData(path.join(src, i.toString()), SIZE);
var subdir = path.join(src, 'subdir');
mkdir(subdir, function(err) {
for (var i = 0; i < FILES; ++i)
testutil.createFileWithData(path.join(subdir, i.toString()), SIZE);
fs.copy(src, dest, function(err) {
F (err);
T (fs.existsSync(dest));
for (var i = 0; i < FILES; ++i)
T (fs.existsSync(path.join(dest, i.toString())));
var destSub = path.join(dest, 'subdir');
for (var j = 0; j < FILES; ++j)
T (fs.existsSync(path.join(destSub, j.toString())));
done();
})
})
})
})
})
})

38
test/mkdir.test.coffee

@ -1,38 +0,0 @@
fs = require('../lib')
path = require('path-extra')
testutil = require('testutil')
describe 'fs-extra', ->
describe '+ mkdir()', ->
it 'should make the directory', (done) ->
dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
F fs.existsSync dir
fs.mkdir dir, (err) ->
T err is null
T fs.existsSync dir
done()
it 'should make the entire directory path', (done) ->
dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
newDir = path.join(dir, 'dfdf', 'ffff', 'aaa')
F fs.existsSync dir
fs.mkdir newDir, (err) ->
T err is null
T fs.existsSync newDir
done()
describe '+ mkdirSync()', ->
it 'should make the directory', (done) ->
dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
F fs.existsSync dir
fs.mkdirSync dir
T fs.existsSync dir
done()
it 'should make the entire directory path', (done) ->
dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
newDir = path.join(dir, 'dfdf', 'ffff', 'aaa')
F fs.existsSync dir
fs.mkdirSync dir
T fs.existsSync dir
done()

61
test/mkdir.test.js

@ -0,0 +1,61 @@
var fs = require('../lib')
, path = require('path-extra')
, testutil = require('testutil');
describe('fs-extra', function() {
describe('+ mkdir()', function() {
it('should make the directory', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random());
F (fs.existsSync(dir));
fs.mkdir(dir, function(err) {
T (err === null);
T (fs.existsSync(dir));
done();
})
})
it('should make the entire directory path', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
, newDir = path.join(dir, 'dfdf', 'ffff', 'aaa');
F (fs.existsSync(dir));
fs.mkdir(newDir, function(err) {
T (err === null);
T (fs.existsSync(newDir));
done();
});
})
})
describe('+ mkdirSync()', function() {
it('should make the directory', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random());
F (fs.existsSync(dir));
fs.mkdirSync(dir);
T (fs.existsSync(dir));
done();
})
it('should make the entire directory path', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random())
, newDir = path.join(dir, 'dfdf', 'ffff', 'aaa');
F (fs.existsSync(dir));
fs.mkdirSync(dir);
T (fs.existsSync(dir));
done();
})
})
})

36
test/read.test.coffee

@ -1,36 +0,0 @@
fs = require('../lib')
testutil = require('testutil')
path = require('path')
DIR = ''
describe 'fs-extra', ->
beforeEach (done) ->
DIR = testutil.createTempDir()
done()
afterEach (done) ->
fs.remove DIR, done
describe '+ readJSONFile', ->
it 'should read a file and parse the json', (done) ->
obj1 = firstName: 'JP', lastName: 'Richardson'
file = path.join(DIR, 'file.json')
fs.writeFileSync(file, JSON.stringify(obj1))
fs.readJSONFile file, (err, obj2) ->
F err?
T obj1.firstName is obj2.firstName
T obj1.lastName is obj2.lastName
done()
it 'should error if it cant parse the json', (done) ->
file = path.join(DIR, 'file2.json')
fs.writeFileSync(file, '%asdfasdff444')
fs.readJSONFile file, (err, obj) ->
T err?
F obj
done()

49
test/read.test.js

@ -0,0 +1,49 @@
var fs = require('../lib')
, testutil = require('testutil')
, path = require('path');
var DIR = '';
describe('fs-extra', function() {
beforeEach(function(done) {
DIR = testutil.createTempDir();
done();
})
afterEach(function(done) {
fs.remove(DIR, done);
})
describe('+ readJSONFile', function() {
it('should read a file and parse the json', function(done) {
var obj1 = {
firstName: 'JP',
lastName: 'Richardson'
};
var file = path.join(DIR, 'file.json');
fs.writeFileSync(file, JSON.stringify(obj1));
fs.readJSONFile(file, function(err, obj2) {
F (err != null);
T (obj1.firstName === obj2.firstName);
T (obj1.lastName === obj2.lastName);
done();
})
})
it('should error if it cant parse the json', function(done) {
var file = path.join(DIR, 'file2.json');
fs.writeFileSync(file, '%asdfasdff444');
fs.readJSONFile(file, function(err, obj) {
T (err != null);
F (obj);
done();
})
})
})
})

106
test/remove.test.coffee

@ -1,106 +0,0 @@
crypto = require('crypto')
fs = require('../lib')
path = require('path-extra')
testutil = require('testutil')
mkdir = require('mkdirp')
DIR = ''
buildDir = ->
buf = new Buffer(5) #small buffer for data
bytesWritten = 0
while bytesWritten < buf.length
buf[bytesWritten] = Math.floor((Math.random()*256))
bytesWritten += 1
ex = Date.now()
baseDir = path.join(path.tempdir(), "TEST_fs-extra_rmrf-#{ex}")
fs.mkdirSync(baseDir)
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf)
subDir = path.join(path.tempdir(), Math.random() + '')
fs.mkdirSync(subDir)
fs.writeFileSync(path.join(subDir, Math.random() + ''))
baseDir
describe 'fs-extra', ->
beforeEach (done) ->
DIR = testutil.createTempDir()
done()
afterEach (done) ->
if fs.existsSync(DIR)
fs.remove DIR, done
else
done()
describe '+ removeSync()', ->
it 'should delete directories and files synchronously', ->
T fs.existsSync(DIR)
fs.removeSync(DIR)
F fs.existsSync(DIR)
it 'should delete an empty directory synchronously', ->
T fs.existsSync DIR
fs.removeSync DIR
F fs.existsSync DIR
it 'should delete a file synchronously', ->
file = testutil.createFileWithData(path.join(DIR, 'file'), 4)
T fs.existsSync file
fs.removeSync file
describe '+ remove()', ->
it 'should delete an empty directory', (done) ->
T fs.existsSync DIR
fs.remove DIR, (err) ->
T err is null
F fs.existsSync DIR
done()
it 'should delete a directory full of directories and files', (done) ->
dir = buildDir()
T fs.existsSync(DIR)
fs.remove DIR, (err) ->
T err is null
F fs.existsSync(DIR)
done()
it 'should delete a file', (done) ->
file = testutil.createFileWithData(path.join(DIR, 'file'), 4)
T fs.existsSync file
fs.remove file, (err) ->
T err is null
F fs.existsSync file
done()
it 'should delete without a callback', (done) ->
file = testutil.createFileWithData(path.join(DIR, 'file'), 4)
T fs.existsSync file
existsChecker = setInterval(->
fs.exists file, (itDoes) ->
if not itDoes
clearInterval(existsChecker)
done()
,25)
fs.remove file
describe '+ delete()', ->
it 'should delete an empty directory', (done) ->
T fs.existsSync DIR
fs.delete DIR, (err) ->
T err is null
F fs.existsSync DIR
done()
describe '+ deleteSync()', ->
it 'should delete directories and files synchronously', ->
T fs.existsSync(DIR)
fs.deleteSync(DIR)
F fs.existsSync(DIR)

128
test/remove.test.js

@ -0,0 +1,128 @@
var crypto = require('crypto')
, fs = require('../lib')
, path = require('path-extra')
, testutil = require('testutil')
, mkdir = require('mkdirp');
var DIR = '';
buildDir = function() { //shit function that should be deleted
var baseDir, buf, bytesWritten, ex, subDir;
buf = new Buffer(5);
bytesWritten = 0;
while (bytesWritten < buf.length) {
buf[bytesWritten] = Math.floor(Math.random() * 256);
bytesWritten += 1;
}
ex = Date.now();
baseDir = path.join(path.tempdir(), "TEST_fs-extra_rmrf-" + ex);
fs.mkdirSync(baseDir);
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf);
fs.writeFileSync(path.join(baseDir, Math.random() + ''), buf);
subDir = path.join(path.tempdir(), Math.random() + '');
fs.mkdirSync(subDir);
fs.writeFileSync(path.join(subDir, Math.random() + ''));
return baseDir;
};
describe('fs-extra', function() {
beforeEach(function(done) {
DIR = testutil.createTempDir();
done();
})
afterEach(function(done) {
if (fs.existsSync(DIR)) {
fs.remove(DIR, done);
} else {
done();
}
})
describe('+ removeSync()', function() {
it('should delete directories and files synchronously', function() {
T (fs.existsSync(DIR));
fs.removeSync(DIR);
F (fs.existsSync(DIR));
})
it('should delete an empty directory synchronously', function() {
T (fs.existsSync(DIR));
fs.removeSync(DIR);
F (fs.existsSync(DIR));
})
it('should delete a file synchronously', function() {
var file = testutil.createFileWithData(path.join(DIR, 'file'), 4);
T (fs.existsSync(file));
fs.removeSync(file);
})
})
describe('+ remove()', function() {
it('should delete an empty directory', function(done) {
T (fs.existsSync(DIR));
fs.remove(DIR, function(err) {
T (err === null);
F (fs.existsSync(DIR));
done();
})
})
it('should delete a directory full of directories and files', function(done) {
var dir = buildDir();
T(fs.existsSync(DIR));
return fs.remove(DIR, function(err) {
T(err === null);
F(fs.existsSync(DIR));
return done();
});
});
it('should delete a file', function(done) {
var file = testutil.createFileWithData(path.join(DIR, 'file'), 4);
T (fs.existsSync(file));
fs.remove(file, function(err) {
T (err === null);
F (fs.existsSync(file));
done();
});
})
it('should delete without a callback', function(done) {
var file = testutil.createFileWithData(path.join(DIR, 'file'), 4);
T (fs.existsSync(file));
var existsChecker = setInterval(function() {
fs.exists(file, function(itDoes) {
if (!itDoes) {
clearInterval(existsChecker);
done();
}
});
}, 25);
fs.remove(file);
})
})
describe('+ delete()', function() {
it('should delete an empty directory', function(done) {
T (fs.existsSync(DIR));
fs["delete"](DIR, function(err) {
T (err === null);
F (fs.existsSync(DIR));
done();
})
})
})
describe('+ deleteSync()', function() {
it('should delete directories and files synchronously', function() {
T (fs.existsSync(DIR));
fs.deleteSync(DIR);
F (fs.existsSync(DIR));
})
})
})
Loading…
Cancel
Save