-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tschaub/benchmarks
Add some benchmarks.
- Loading branch information
Showing
9 changed files
with
243 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
|
||
var mock = require('..'); | ||
|
||
|
||
/** | ||
* Timed test. This includes the mock setup and teardown as part of the overall | ||
* test time. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
mock({ | ||
'foo-mock.txt': 'foo' | ||
}); | ||
|
||
fs.readFile('foo-mock.txt', 'utf8', function(err, str) { | ||
assert.ifError(err); | ||
assert.equal(str, 'foo'); | ||
|
||
mock.restore(); | ||
done(); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var rimraf = require('rimraf'); | ||
|
||
var tmpPath = '.tmp'; | ||
|
||
|
||
/** | ||
* Timed test. This includes the setup and teardown as part of the overall | ||
* test time. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.mkdir(tmpPath, function(mkdirErr) { | ||
assert.ifError(mkdirErr); | ||
var tmpFile = path.join(tmpPath, 'foo-real.txt'); | ||
fs.writeFile(tmpFile, 'foo', function(writeErr) { | ||
assert.ifError(writeErr); | ||
fs.readFile(tmpFile, 'utf8', function(readErr, str) { | ||
assert.ifError(readErr); | ||
assert.equal(str, 'foo'); | ||
rimraf(tmpPath, done); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
|
||
var mock = require('..'); | ||
|
||
|
||
/** | ||
* Test setup. Not timed. | ||
*/ | ||
exports.beforeEach = function() { | ||
mock({ | ||
'foo-mock.txt': 'foo' | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* Timed test. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.readFile('foo-mock.txt', 'utf8', function(err, str) { | ||
assert.ifError(err); | ||
assert.equal(str, 'foo'); | ||
done(); | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* Test teardown. Not timed. | ||
*/ | ||
exports.afterEach = function() { | ||
mock.restore(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var rimraf = require('rimraf'); | ||
|
||
var tmpPath = '.tmp'; | ||
|
||
|
||
/** | ||
* Test setup. Not timed. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.beforeEach = function(done) { | ||
fs.mkdir(tmpPath, function(err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', done); | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* Timed test. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.readFile(path.join(tmpPath, 'foo-real.txt'), 'utf8', function(err, str) { | ||
assert.ifError(err); | ||
assert.equal(str, 'foo'); | ||
done(); | ||
}); | ||
}; | ||
|
||
|
||
/** | ||
* Test teardown. Not timed. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.afterEach = function(done) { | ||
rimraf(tmpPath, done); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
|
||
var mock = require('..'); | ||
|
||
|
||
/** | ||
* Timed test. This includes the mock setup and teardown as part of the overall | ||
* test time. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
mock(); | ||
|
||
fs.writeFile('foo-mock.txt', 'foo', function(err) { | ||
assert.ifError(err); | ||
|
||
mock.restore(); | ||
done(); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var assert = require('assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var rimraf = require('rimraf'); | ||
|
||
var tmpPath = '.tmp'; | ||
|
||
|
||
/** | ||
* Timed test. This includes the setup and teardown as part of the overall | ||
* test time. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.mkdir(tmpPath, function(mkdirErr) { | ||
assert.ifError(mkdirErr); | ||
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', function(err) { | ||
assert.ifError(err); | ||
rimraf(tmpPath, done); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var mock = require('..'); | ||
|
||
|
||
/** | ||
* Test setup. Not timed. | ||
*/ | ||
exports.beforeEach = function() { | ||
mock(); | ||
}; | ||
|
||
|
||
/** | ||
* Timed test. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.writeFile('foo-mock.txt', 'foo', done); | ||
}; | ||
|
||
|
||
/** | ||
* Test teardown. Not timed. | ||
*/ | ||
exports.afterEach = function() { | ||
mock.restore(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var rimraf = require('rimraf'); | ||
|
||
var tmpPath = '.tmp'; | ||
|
||
|
||
/** | ||
* Test setup. Not timed. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.beforeEach = function(done) { | ||
fs.mkdir(tmpPath, done); | ||
}; | ||
|
||
|
||
/** | ||
* Timed test. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.test = function(done) { | ||
fs.writeFile(path.join(tmpPath, 'foo-real.txt'), 'foo', done); | ||
}; | ||
|
||
|
||
/** | ||
* Test teardown. Not timed. | ||
* @param {function(Error)} done Callback. | ||
*/ | ||
exports.afterEach = function(done) { | ||
rimraf(tmpPath, done); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters