Permalink
Browse files

[test] Test `readSync`

  • Loading branch information...
1 parent 3d9a0f2 commit 8673a64bdd4632a8ae348cecdb14a1cfaccf8a3d @mmalecki committed May 12, 2012
Showing with 44 additions and 29 deletions.
  1. +44 −29 test/read-dir-files-test.js
@@ -1,7 +1,8 @@
var path = require('path'),
assert = require('assert'),
vows = require('vows'),
- readDirFiles = require('../');
+ readDirFiles = require('../'),
+ fixtures = path.join(__dirname, 'fixtures', 'dir');
var content = {
a: new Buffer('Hello world\n'),
@@ -38,39 +39,53 @@ function getContent(content, encoding, recursive) {
vows.describe('read-dir-files/read').addBatch({
'When using `read-dir-files`': {
- 'and reading a directory (`readDirFiles.read("dir", cb)`)': {
- topic: function () {
- readDirFiles.read(path.join(__dirname, 'fixtures', 'dir'), this.callback);
+ 'asynchronously': {
+ 'reading a directory (`readDirFiles.read("dir", cb)`)': {
+ topic: function () {
+ readDirFiles.read(fixtures, this.callback);
+ },
+ 'it should contain all files': function (data) {
+ assert.isObject(data);
+ assert.deepEqual(data, content);
+ }
},
- 'it should contain all files': function (data) {
- assert.isObject(data);
- assert.deepEqual(data, content);
- }
- },
- 'and reading a directory (`readDirFiles.read("dir", "utf8", cb)`)': {
- topic: function () {
- readDirFiles.read(
- path.join(__dirname, 'fixtures', 'dir'),
- 'utf8',
- this.callback
- );
+ 'reading a directory (`readDirFiles.read("dir", "utf8", cb)`)': {
+ topic: function () {
+ readDirFiles.read(fixtures, 'utf8', this.callback);
+ },
+ 'it should contain all files': function (data) {
+ assert.isObject(data);
+ assert.deepEqual(data, getContent(content, 'utf8'));
+ }
},
- 'it should contain all files': function (data) {
- assert.isObject(data);
- assert.deepEqual(data, getContent(content, 'utf8'));
+ 'non-recursively reading a directory (`readDirFiles.read("dir", false, cb)`)': {
+ topic: function () {
+ readDirFiles.read(fixtures, false, this.callback);
+ },
+ 'it should contain all files': function (data) {
+ assert.isObject(data);
+ assert.deepEqual(data, getContent(content, false));
+ }
}
},
- 'and non-recursively reading a directory (`readDirFiles.read("dir", false, cb)`)': {
- topic: function () {
- readDirFiles.read(
- path.join(__dirname, 'fixtures', 'dir'),
- false,
- this.callback
- );
+ 'synchronously': {
+ 'reading a directory (`readDirFiles.readSync("dir")`)': {
+ topic: readDirFiles.readSync(fixtures),
+ 'it should contain all files': function (data) {
+ assert.deepEqual(data, content);
+ },
+ },
+ 'reading a directory (`readDirFiles.readSync("dir", "utf8")`)': {
+ topic: readDirFiles.readSync(fixtures, 'utf8'),
+ 'it should contain all files': function (data) {
+ assert.deepEqual(data, getContent(content, 'utf8'));
+ }
},
- 'it should contain all files': function (data) {
- assert.isObject(data);
- assert.deepEqual(data, getContent(content, false));
+ 'non-recursively reading a directory (`readDirFiles.read("dir", false, cb)`)': {
+ topic: readDirFiles.readSync(fixtures, false),
+ 'it should contain all files': function (data) {
+ assert.deepEqual(data, getContent(content, false));
+ }
}
}
}

0 comments on commit 8673a64

Please sign in to comment.