diff --git a/.bem/templates/js.js b/.bem/templates/js.js
index 880f2cf..e1f36a1 100644
--- a/.bem/templates/js.js
+++ b/.bem/templates/js.js
@@ -8,7 +8,7 @@ function toObjectValue(x) {
return typeof x === 'boolean' ? x : `'${x}'`;
}
-module.exports = function ({ block, elem, mod={} }, naming) {
+module.exports = function ({ block, elem, mod={} }) {
const { name : modName, val : modVal } = mod;
return `import { ${modName? 'declMod' : 'decl'} } from 'bem-react-core';
diff --git a/.bem/templates/spec.js.js b/.bem/templates/spec.js.js
new file mode 100644
index 0000000..eb4e7d6
--- /dev/null
+++ b/.bem/templates/spec.js.js
@@ -0,0 +1,26 @@
+var EOL = require('os').EOL,
+ nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;
+
+
+function toObjectKey(str) {
+ return nameRegEx.test(str) ? str : "'" + str + "'"
+}
+
+function toObjectValue(x) {
+ return typeof x === 'boolean' ? x : "'" + x + "'";
+}
+
+module.exports = function ({ block, elem, mod={} }, naming) {
+ const { name : modName, val : modVal } = mod;
+
+ return `import React from 'react';
+import { block } from '../../.jest/helpers';
+import ${block} from 'b:${block}';
+
+const renderer = block('${block}');
+
+it('should be ...', () => {
+ renderer(<${block}/>);
+});
+`;
+};
diff --git a/.bem/templates/tests-html.js b/.bem/templates/tests-html.js
new file mode 100644
index 0000000..a8475d4
--- /dev/null
+++ b/.bem/templates/tests-html.js
@@ -0,0 +1,15 @@
+module.exports = function ({ block }) {
+ return `
+
+
+
+⚠︎
+
+
+
+
+⚠︎
+
+
+`;
+};
diff --git a/.bem/templates/tests-js.js b/.bem/templates/tests-js.js
new file mode 100644
index 0000000..18467db
--- /dev/null
+++ b/.bem/templates/tests-js.js
@@ -0,0 +1,27 @@
+var EOL = require('os').EOL,
+ nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;
+
+function toObjectKey(str) {
+ return nameRegEx.test(str) ? str : "'" + str + "'"
+}
+
+function toObjectValue(x) {
+ return typeof x === 'boolean' ? x : "'" + x + "'";
+}
+
+module.exports = function ({ block, elem, mod={} }) {
+ const { name : modName, val : modVal } = mod,
+ entityName = elem || block;
+
+ return `import React from 'react';
+import ReactDom from 'react-dom';
+import ${entityName} from 'b:${block}${elem? ' e:' + elem : ''}${modName? ' m:' + modName + (modVal? '=' + modVal : ''): ''}';
+
+class App extends React.Component {
+ render() {
+ return <${entityName}${modName? ' ' + modName + (modVal? '="${modVal}"' : ''): ''}/>
+ }
+}
+ReactDom.render(, document.getElementById('root'));
+`;
+};
diff --git a/.bem/templates/tests.js b/.bem/templates/tests.js
new file mode 100644
index 0000000..232ec84
--- /dev/null
+++ b/.bem/templates/tests.js
@@ -0,0 +1,30 @@
+var EOL = require('os').EOL,
+ nameRegEx = /^[a-zA-Z_][a-zA-Z\d_]*$/;
+
+
+function toObjectKey(str) {
+ return nameRegEx.test(str) ? str : "'" + str + "'"
+}
+
+function toObjectValue(x) {
+ return typeof x === 'boolean' ? x : "'" + x + "'";
+}
+
+module.exports = function (entity, naming) {
+ return [
+ "import {decl} from 'bem-react-core';",
+ "",
+ "export default " +
+ (entity.modName ?
+ "declMod({ " +
+ toObjectKey(entity.modName) + " : " +
+ toObjectValue(entity.modVal || true) +
+ " }, {" :
+ "decl({"),
+ " block : '" + entity.block + "'" +
+ (entity.elem ?
+ "," + EOL + " elem : '" + entity.elem + "'" :
+ ""),
+ "});"
+ ].join(EOL);
+};
diff --git a/.bemrc.js b/.bemrc.js
index 9a5da48..16efd5d 100644
--- a/.bemrc.js
+++ b/.bemrc.js
@@ -5,20 +5,32 @@ module.exports = {
scheme : 'nested',
schemeOptions : 'react',
naming : 'react'
+ },
+ 'blocks/**/*.tests' : {
+ scheme : 'flat'
}
},
modules : {
'bem-tools' : {
plugins : {
create : {
+ templates : {
+ js : '.bem/templates/js.js',
+ 'spec.js' : '.bem/templates/spec.js.js',
+ 'tests' : '.bem/templates/tests.js',
+ },
levels : {
blocks : {
- default : true
+ default : true,
+ techs : ['js', 'css']
+ },
+ 'blocks/**/*.tests' : {
+ techs : ['js', 'html'],
+ templates : {
+ js : '.bem/templates/tests-js.js',
+ html : '.bem/templates/tests-html.js',
+ }
}
- },
- techs : ['js', 'css'],
- templates : {
- js : '.bem/templates/js.js'
}
}
}