|
@ -1,22 +1,26 @@ |
|
|
var testutil = require('testutil') |
|
|
var fs = require('fs') |
|
|
, fs = require('../') |
|
|
var path = require('path') |
|
|
, path = require('path') |
|
|
|
|
|
|
|
|
|
|
|
var terst = require('terst') |
|
|
var terst = require('terst') |
|
|
|
|
|
var testutil = require('testutil') |
|
|
|
|
|
var fse = require('../') |
|
|
|
|
|
|
|
|
var TEST_DIR = '' |
|
|
var TEST_DIR = '' |
|
|
|
|
|
|
|
|
describe('fs-extra', function () { |
|
|
describe('output', function () { |
|
|
beforeEach(function() { |
|
|
beforeEach(function() { |
|
|
TEST_DIR = testutil.createTestDir('fs-extra') |
|
|
TEST_DIR = testutil.createTestDir('fs-extra') |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
afterEach(function(done) { |
|
|
|
|
|
fse.remove(TEST_DIR, done) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
describe('+ outputFile', function() { |
|
|
describe('+ outputFile', function() { |
|
|
describe('> when the file and directory does not exist', function() { |
|
|
describe('> when the file and directory does not exist', function() { |
|
|
it('should create the file', function(done) { |
|
|
it('should create the file', function(done) { |
|
|
var file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt') |
|
|
var file = path.join(TEST_DIR, Math.random() + 't-ne', Math.random() + '.txt') |
|
|
F (fs.existsSync(file)) |
|
|
F (fs.existsSync(file)) |
|
|
fs.outputFile(file, 'hi jp', function(err) { |
|
|
fse.outputFile(file, 'hi jp', function(err) { |
|
|
F (err) |
|
|
F (err) |
|
|
T (fs.existsSync(file)) |
|
|
T (fs.existsSync(file)) |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hi jp') |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hi jp') |
|
@ -28,9 +32,9 @@ describe('fs-extra', function () { |
|
|
describe('> when the file does exist', function() { |
|
|
describe('> when the file does exist', function() { |
|
|
it('should still modify the file', function(done) { |
|
|
it('should still modify the file', function(done) { |
|
|
var file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt') |
|
|
var file = path.join(TEST_DIR, Math.random() + 't-e', Math.random() + '.txt') |
|
|
fs.mkdirsSync(path.dirname(file)) |
|
|
fse.mkdirsSync(path.dirname(file)) |
|
|
fs.writeFileSync(file, 'hello world') |
|
|
fs.writeFileSync(file, 'hello world') |
|
|
fs.outputFile(file, 'hello jp', function(err) { |
|
|
fse.outputFile(file, 'hello jp', function(err) { |
|
|
if (err) return done(err) |
|
|
if (err) return done(err) |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello jp') |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello jp') |
|
|
done() |
|
|
done() |
|
@ -44,7 +48,7 @@ describe('fs-extra', function () { |
|
|
it('should create the file', function() { |
|
|
it('should create the file', function() { |
|
|
var file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt') |
|
|
var file = path.join(TEST_DIR, Math.random() + 'ts-ne', Math.random() + '.txt') |
|
|
F (fs.existsSync(file)) |
|
|
F (fs.existsSync(file)) |
|
|
fs.outputFileSync(file, 'hello man') |
|
|
fse.outputFileSync(file, 'hello man') |
|
|
T (fs.existsSync(file)) |
|
|
T (fs.existsSync(file)) |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello man') |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello man') |
|
|
}) |
|
|
}) |
|
@ -53,9 +57,9 @@ describe('fs-extra', function () { |
|
|
describe('> when the file does exist', function() { |
|
|
describe('> when the file does exist', function() { |
|
|
it('should still modify the file', function() { |
|
|
it('should still modify the file', function() { |
|
|
var file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt') |
|
|
var file = path.join(TEST_DIR, Math.random() + 'ts-e', Math.random() + '.txt') |
|
|
fs.mkdirsSync(path.dirname(file)) |
|
|
fse.mkdirsSync(path.dirname(file)) |
|
|
fs.writeFileSync(file, 'hello world') |
|
|
fs.writeFileSync(file, 'hello world') |
|
|
fs.outputFileSync(file, 'hello man') |
|
|
fse.outputFileSync(file, 'hello man') |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello man') |
|
|
EQ (fs.readFileSync(file, 'utf8'), 'hello man') |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|