Helper library to assist smoke-testing of the bem technologies
npm install bem-smoke
You need to require bem-smoke
module and call testTech
method with a path to your
technology module:
var BEMSmoke = require('bem-smoke');
var tech = BEMSmoke.testTech('/absolute/path/to/tech');
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.
var tech = BEMTesting.testTech(require.resolve('path/to/css-tech'));
tech.withSourceFiles({
'menu': {
'menu.css': '.test1 {}',
'__item': {
'menu__item.css': '.test2 {}'
}
}
})
.build('/name', {
deps: [
{block: 'menu'},
{block: 'menu', elem: 'item'}
]
})
.producesFile('name.css')
.withContent('@import url(menu/menu.css);',
'@import url(menu/__item/menu__item.css);',
'');
-
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.withMockedModules({ 'net': { createServer: function() { ... } } });
-
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
.
-
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.
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.
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:
describe('example', function() {
it('completes', function(done) {
tech.withSourceFiles({
})
...
.notify(done);
});
});
Licensed under MIT license.