-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Norbert Szydlik
committed
Dec 19, 2015
1 parent
8f721ff
commit e427b4d
Showing
7 changed files
with
85 additions
and
7 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,2 @@ | ||
# Version 0.0.1 # | ||
* Demo preview how TestDome should look like |
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 |
---|---|---|
@@ -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 |
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,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); | ||
}; |
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,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"); | ||
}); | ||
}); |
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
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
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