Set up and tear down a temp directory for running filesystem tests.
There are three options for accessing these functions:
- CommonJs modules: dist/*.js (default)
- ES6 modules: dist/*.mjs
- Bundles Browser file: browser/test-fs.js
In your project's root directory, run: npm install --save-dev test-filesystem
(or yarn add --dev test-filesystem
if you use Yarn).
To use the temporary directory in tests. Do the following in your tests:
import { setUp } from 'test-filesystem'
// Setup the name for your temporary directory
const dirName = 'test-temp/'
// Use the name
setUp.setDefaults(dirName)
// use the beforeEach and afterEach methods of jest to run the setup and teardown functions
beforeEach(
() => setUp.beforeEach()
.then(
() => {
// Put any additional setup logic here
}
)
)
afterEach(
() => setUp.afterEach()
.then(
() => {
// Put any additional teardown logic here
}
)
)
An assortment of objects that can be used in tests and some functions to help debug and write tests.
Version: 1.0.0
Author: Joshua Heagle joshuaheagle@gmail.com
-
test-fs
-
.circularObject :
Object.<string, (string|Object|Array)>
-
.deepReferenceObject :
Object.<string, (string|number|Object)>
-
.domItem :
Object.<string, (string|number|Array|Object)>
-
.jsonDom :
Object.<string, (string|number|Array|Object)>
-
.linkedList :
Object.<string, (string|Object)>
-
.multiReferenceObject :
Object.<string, (string|number|Object)>
-
.nodeTree :
Object.<string, (string|Object|Array)>
-
.countMatches(content, search) ⇒
number
-
.fileExists(filePath) ⇒
boolean
-
.logObject(object, [label], [outputType]) ⇒
string
|undefined
-
.removeDirectory(dirPath) ⇒
Promise.<*>
-
.afterEach() ⇒
Promise.<*>
-
.exports.afterEach([exists]) ⇒
Promise.<(*|void)>
-
.exports.createTempDir() ⇒
Promise.<(*|void)>
-
.circularObject :
Multilayered node tree-like structure with parent references
Kind: static constant of test-fs
Sample object with deep references.
Kind: static constant of test-fs
Sample of domItem child with nested child and optional details
Kind: static constant of test-fs
Sample of jsonDom object containing an empty nested array and objects
Kind: static constant of test-fs
Sample LinkedList for testing circular references.
Kind: static constant of test-fs
Sample of an object containing multiple references.
Kind: static constant of test-fs
Sample NodeTree for testing circular references and arrays.
Kind: static constant of test-fs
Simple way to count string occurrences for testing.
Kind: static method of test-fs
Param | Type |
---|---|
content | string |
search | string |
Detect if a file exists and is usable.
Kind: static method of test-fs
Param | Type |
---|---|
filePath | string |
Log out an object in a nicely formatted way.
Kind: static method of test-fs
Param | Type | Default |
---|---|---|
object | Object |
|
[label] | string |
"logging" |
[outputType] | string |
"log" |
Return a promise to be completed once the specified directory is deleted.
Kind: static method of test-fs
Param | Type |
---|---|
dirPath | string |
In the Jest.afterEach function call this one to clean up and remove the temp directory.
Kind: static method of test-fs
Ensure that the del has completed, recursively attempt to delete and recreate
Kind: static method of test-fs
Param | Type | Default |
---|---|---|
[exists] | boolean |
true |
In the Jest.beforeEach function call this one to set up the temp directory.
Kind: static method of test-fs