Skip to content

Commit

Permalink
Add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Szydlik committed Dec 19, 2015
1 parent 8f721ff commit e427b4d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Version 0.0.1 #
* Demo preview how TestDome should look like
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
# Test dome #
# Installation #
To install test dome use command `npm install --save-dev test-dome`. It is recommended to use TestDome with mocha framework.

# Introduction #
TestDome is library that currently stubs `fs` module. It should behave exactly like node.js module, but without operating on actual file system.

## Usage ##
First `require("testDome");` module in your test case. In your test step enclose your module under test with `testDome.enclose(pathToModule, options);`.
In mocha framework it will automatically `.release` system modules, but in other frameworks (like nodeunit) you may do it manually.

### Example test file
var testDome = require("test-dome");
var expect = require("chai").expect;

describe("Your code", function() {
it("should hello world in file at specified path", function() {
var codeUT = testDome.enclose("./pathToCode", {
enabled: {
vfs: true
}
});
codeUT.writeHello("/tmp/helloWorld.txt");
expect(testDome.vfs.getDataOfFile("/tmp/helloWorld.txt", "utf8")).to.equal("Hello World!");
});
});


# Roadmap #
## Current step ##
My current target is to mimic whole `fs` module and test it against external libraries like `fs-extra`, `q`, `bluebird`
## Next Steps ##
* Allow to use proxyquire and zurvan for checking against time
* Mimic `http` module
* Mimic `net` module
* Mimic `child_process` module
* Add good mocking solution
14 changes: 14 additions & 0 deletions examples/example01_writeAndReadFileSync/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var fs = require("fs");

module.exports.saveReport = function(inputPath, reportPath) {
var input = fs.readFileSync(inputPath);
input = JSON.parse(input);

var report = "";
if(Array.isArray(input)) {
input.forEach(function(record) {
report += record.key + "|" + record.value + "\n";
});
}
fs.writeFileSync(reportPath, report);
};
21 changes: 21 additions & 0 deletions examples/example01_writeAndReadFileSync/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var testDome = require("../../index"); //in your test write `require("test-dome")`
var expect = require("chai").expect;

describe("code", function() {
it("should save report based on input file", function() {
var SUT = testDome.enclose("./code", {
vfs: {
"/tmp/inputData.json": {
data: JSON.stringify([{key: "testKey1", value: "testValue1"}, {key: "testKey2", value: "testValue2"}])
}
},
enabled: {
vfs: true
}
});

SUT.saveReport("/tmp/inputData.json", "/tmp/report.csv");

expect(testDome.vfs.getDataOfFile("/tmp/report.csv", "utf8")).to.equal("testKey1|testValue1\ntestKey2|testValue2\n");
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "test-dome",
"version": "0.0.1-alpha5",
"description": "Test dome allows you to create testing environment, separated from real HTTP, socket connection, filesystem or childProcess",
"description": "Comprehensive environment for isolated high level testing.",
"main": "index.js",
"scripts": {
"test": "gulp test"
Expand Down
7 changes: 6 additions & 1 deletion src/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ function getDataOfFile(absolutePath, encoding) {
if(!_.has(vfs, absolutePath)) {
assert.fail(null, null, 'Path "' + absolutePath + '" does not exist in virtual file system');
}
return vfs[absolutePath].data.toString(encoding);
if(encoding != null) {
return vfs[absolutePath].data.toString(encoding);
} else {
return vfs[absolutePath].data;
}

}

module.exports.prepareEnvironment = prepareEnvironment;
Expand Down
8 changes: 4 additions & 4 deletions test/vfs/prepareEnvironmentTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Virtual file system", function() {
}
});

expect(vfs.getDataOfFile("/tmp/test1.txt")).to.equal("TestData string");
expect(vfs.getDataOfFile("/tmp/test1.txt", "utf8")).to.equal("TestData string");
});
it("allows to create initial content of files using array buffer", function() {
vfs.prepareEnvironment({
Expand Down Expand Up @@ -45,9 +45,9 @@ describe("Virtual file system", function() {
}
});

expect(vfs.getDataOfFile("/tmp/test1.txt")).to.equal("this is string");
expect(vfs.getDataOfFile("/tmp/test2.txt")).to.equal("this is buffer");
expect(vfs.getDataOfFile("/tmp/test3.txt")).to.equal("this is mixed buffer & string");
expect(vfs.getDataOfFile("/tmp/test1.txt", "utf8")).to.equal("this is string");
expect(vfs.getDataOfFile("/tmp/test2.txt", "utf8")).to.equal("this is buffer");
expect(vfs.getDataOfFile("/tmp/test3.txt", "utf8")).to.equal("this is mixed buffer & string");
});
it("should cleanup environment when used second time", function() {
vfs.prepareEnvironment({
Expand Down

0 comments on commit e427b4d

Please sign in to comment.