mocha 加上
//add templates/main.test.js
import "../src/main.js"
let assert = require("assert")
it('your tetst title', ()=>{
assert.equal(5,2);
})
add templates/.babelrc & templates/.nycrc
// templates/.babelrc
{
"presets": ["@babel/preset-env"],
"plugins": [
"babel-plugin-istanbul",
["@babel/plugin-transform-react-jsx", {"pragma": "createElement"}]
]
}
// templates/.nycrc
{
"all": true,
"include": [
"src/*.js"
],
"extends": "@istanbuljs/nyc-config-babel"
}
// index.js
this.fs.copyTpl(
this.templatePath('.babelrc'),
this.destinationPath('.babelrc')
);
this.fs.copyTpl(
this.templatePath('.nycrc'),
this.destinationPath('.nycrc')
);
this.npmInstall([
'@babel/register'
], { 'save-dev': true });
npm run coverage
//package.json
"scripts": {
"test": "mocha --require @babel/register",
"coverage": "nyc mocha",
"start": "webpack-dev-server",
"build": "webpack"
},
注释掉 component.mountTo(document.body)
import {createElement, Text, Wrapper} from "../lib/createElement";
let component =<div>Hello world!</div>
// component.mountTo(document.body)
yo toytool
npm run test