Add: Container test

This commit is contained in:
surunzi
2017-11-05 11:31:09 +08:00
parent 9917383830
commit a38006fe49
6 changed files with 32 additions and 19 deletions

View File

@@ -21,7 +21,8 @@ module.exports = function (config)
'test/resources.js',
'test/snippets.js',
'test/sources.js',
'test/settings.js'
'test/settings.js',
'test/eruda.js'
],
plugins: [
'karma-jasmine',

View File

@@ -9,7 +9,7 @@ var remappedJson = require('../coverage/coverage-remapped.json');
var coverage = util.reduce(util.keys(remappedJson), function (result, source)
{
if (source.match(/src.*\.js$/) && source.indexOf('node_modules') < 0)
if (isSrc())
{
var correctPath = source.replace(path.resolve(__dirname, '../src'), path.resolve(__dirname, '../'));
@@ -18,6 +18,13 @@ var coverage = util.reduce(util.keys(remappedJson), function (result, source)
result[correctPath] = val;
}
function isSrc(src)
{
return source.match(/src.*\.js$/) &&
source.indexOf('node_modules') < 0 &&
source.indexOf('modernizr') < 0;
}
return result;
}, {});

View File

@@ -3,7 +3,7 @@ var webpack = require('webpack');
exports = require('./webpack.base');
exports.output.filename = 'eruda.js';
exports.devtool = false;
exports.devtool = 'source-map';
exports.plugins = exports.plugins.concat([
new webpack.DefinePlugin({
ENV: '"development"',

View File

@@ -53,8 +53,8 @@ export default class DevTools extends util.Emitter
}
add(tool)
{
let {init, show, hide} = new Tool();
util.defaults(tool, {init, show, hide});
let {init, show, hide, destroy} = new Tool();
util.defaults(tool, {init, show, hide, destroy});
let name = tool.name;
if (!name) return logger.error('You must specify a name for a tool');

View File

@@ -16,12 +16,12 @@ import logger from './lib/logger'
import extraUtil from './lib/extraUtil'
module.exports = {
init({el, tool, autoScale = true} = {})
init({container, tool, autoScale = true} = {})
{
this._isInit = true;
this._scale = 1;
this._initContainer(el);
this._initContainer(container);
this._initStyle();
this._initDevTools();
this._initEntryBtn();
@@ -81,26 +81,28 @@ module.exports = {
{
this._devTools.destroy();
delete this._devTools;
this.entryBtn.destroy();
delete this.entryBtn;
this._entryBtn.destroy();
delete this._entryBtn;
this._unregisterListener();
this._$el.remove();
util.evalCss.clear();
},
getScale()
scale(s)
{
if (util.isNum(s))
{
this._scale = s;
emitter.emit(emitter.SCALE, s);
return this;
}
return this._scale;
},
setScale(scale)
{
this._scale = scale;
emitter.emit(emitter.SCALE, scale);
},
_autoScale()
{
if (!util.isMobile()) return;
this.setScale(1 / util.viewportScale());
this.scale(1 / util.viewportScale());
},
_registerListener()
{
@@ -161,8 +163,8 @@ module.exports = {
},
_initEntryBtn()
{
this.entryBtn = new EntryBtn(this._$el);
this.entryBtn.on('click', () => this._devTools.toggle());
this._entryBtn = new EntryBtn(this._$el);
this._entryBtn.on('click', () => this._devTools.toggle());
},
_initSettings()
{
@@ -171,7 +173,7 @@ module.exports = {
devTools.add(settings);
this.entryBtn.initCfg(settings);
this._entryBtn.initCfg(settings);
devTools.initCfg(settings);
},
_initTools(tool = ['console', 'elements', 'network', 'resources', 'sources', 'info', 'snippets', 'features'])

View File

@@ -11,6 +11,9 @@
<header>ERUDA TEST PAGE</header>
<nav id="test-list">
<ul>
<li>
<a href="eruda.html">eruda</a>
</li>
<li>
<a href="console.html">console</a>
</li>