bem-smoke
Helper library to assist smoke-testing of the bem technologies
Installation
npm install bem-smoke
Usage
Tech modules testing
You need to require bem-smoke
module and call testTech
method with a path to your
technology module:
var BEMSmoke = ; var tech = BEMSmoke;
You can use require.resolve
to get an absolute path from module id.
All TechTest
modules can be divided into three groups that should be called in order:
- setup - prepares initial state for a tech;
- action - performs action you are testing;
- assert - check the final state after the action.
Example test:
var tech = BEMTesting;tech;
Setup methods
-
withSourceFiles(fsTree)
- specifies how FS tree should look like during a test. Keys offsTree
represent files/directories names. If value of a key is an object, then it represents directory, if it's string or Buffer - file with corresponding content. -
withLevel(path)
- specify level to use during the test. If not called, level at root of a mock fs tree will be used. -
withLevels(levels)
- specifies levels to use for a create/bulid.levels
is an array of directory paths. -
withTechMap(map)
- specifies tech map to use during tests. Map format is{"techName": "/absolute/path/to/module"}
. Can be useful to resolve base technologies by names. -
withMockModules(modules)
- specifies mocks to use instead of particular modules during the test. Format is{"moduleId": mockObject}
. Note, thatfs
andq-io/fs
modules are already mocked by framework. Example:tech; -
withMockedModulesResolves(modulePaths)
- stubrequire.resolve
for tech under the test to return specified path instead of original. Doesn't affect actual module loaded viarequire
. Format is{"moduleId": "/stub/path"}
. -
touchFile(path)
- updates access and modification dates for file atpath
. Should be called afterbuild
orcreate
.
Action methods
-
create(elem)
- performs create action for the technology.elem.block
,elem.elem
,elem.mod
andelem.val
specifies entity to create. -
build(prefix, decl)
- performs build action.prefix
specifies output path prefix,decl
- declaration to use for a build.
Assert methods
producesFile(path)
- assert that file atpath
exists after action finishes.withContent(line1, line2, ...)
- assert that file specified at the lastproducesFile
has correct content after action finishes. Each argument represents one expected line of a file.writesToFile(path)
- assert that file atpath
have been written to during the test.notWritesToFile(path)
- assert that file atpath
have not been written to during test.
Utility methods
notify(callback)
- used with asynchronous test runners, such as mocha to notify runner that test is complete.asserts(callback)
- pass a function to this method to execute any additional assertions on a tech.
Example:
;
License
Licensed under MIT license.