Skip to content

Commit

Permalink
feat:搭建新的测试环境,开始使用karma&&Mocha重写所有测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jul 18, 2017
1 parent cc4c4dd commit b0f8072
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
}]
],
"comments": false
}
}
87 changes: 87 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Karma configuration
// Generated on Tue Jul 18 2017 18:01:48 GMT+0800 (CST)

const webpack = require('webpack')

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'chai'],


// list of files / patterns to load in the browser
files: ['test/spec.js'],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.js': ['webpack', 'sourcemap']
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,

webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
}
},

webpackMiddleware: {
noInfo: true
}
})
}
40 changes: 14 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,24 @@
"scripts": {
"clear": "rm -rf dist",
"eslint": "eslint src test",
"test": "npm-run-all eslint test:ava",
"test:ava": "ava --tap | tap-diff",
"test": "npm-run-all eslint test:karma",
"test:karma": "node node_modules/karma-event-driver-ext",
"build": "npm-run-all clear transpile:main",
"transpile:main": "rollup -c build/rollup.config.js"
},
"keywords": [
"base"
"react-like"
],
"repository": {
"type": "git",
"url": "git+https://github.com/o2team/nerv.git"
},
"ava": {
"files": [
"test/**/*.js"
],
"source": [
"**/*.js",
"!dist/**/*"
],
"concurrency": 5,
"failFast": true,
"failWithoutAssertions": false,
"tap": true,
"powerAssert": true,
"require": [
"babel-register",
"babel-polyfill"
],
"babel": {
"babelrc": "inherit"
}
},
"author": "luckyadam",
"license": "MIT",
"devDependencies": {
"ava": "^0.19.1",
"babel-core": "^6.24.0",
"babel-eslint": "^7.2.2",
"babel-loader": "^7.1.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-root-import": "^5.1.0",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
Expand All @@ -56,16 +35,25 @@
"babel-preset-stage-0": "^6.22.0",
"babel-register": "^6.24.0",
"babel-runtime": "^6.23.0",
"chai": "^4.1.0",
"eslint": "^3.19.0",
"eslint-plugin-react": "^6.10.3",
"global": "^4.3.1",
"karma": "^1.7.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-event-driver-ext": "^0.0.13",
"karma-mocha": "^1.3.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"mocha": "^3.4.2",
"npm-run-all": "^4.0.2",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-memory": "^2.0.0",
"rollup-plugin-node-resolve": "^3.0.0",
"tap-diff": "^0.1.1"
"webpack": "^3.3.0"
},
"bugs": {
"url": "https://github.com/o2team/nerv.git/issues"
Expand Down
9 changes: 9 additions & 0 deletions src/lib/util/shallow-equal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
if (!Object.is) {
Object.is = function (x, y) {
if (x === y) {
return x !== 0 || 1 / x === 1 / y
}
return x !== x && y !== y
}
}

export default function shallowEqual (obj1, obj2) {
if (obj1 === null || obj2 === null) {
return false
Expand Down
26 changes: 26 additions & 0 deletions test/modules/h.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { assert } from 'chai'
import h from '#/h'

describe('test generate virtual dom tree', () => {
it('test make virtual dom tree simply', () => {
const tree = h('div', {id: 'test', key: '0'}, 'test')
assert.equal(tree.tagName, 'div')
assert.equal(tree.children.length, 1)
assert.equal(tree.children[0].text, 'test')
})

it('test make virtual dom tree with children', () => {
const tree = h('ul', {key: '0', id: 'test', className: 'list'}, [
h('li', {key: '1', className: 'list_item'}, h('span', {key: '2', className: 'list_item_text'}, '1')),
h('li', {key: '3', className: 'list_item'}, h('span', {key: '4', className: 'list_item_text'}, '2')),
h('li', {key: '5', className: 'list_item'}, h('span', {key: '6', className: 'list_item_text'}, '3'))
])
assert.equal(tree.tagName, 'ul')
assert.equal(tree.key, '0')
assert.equal(tree.props.id, 'test')
assert.equal(tree.props.className, 'list')
assert.equal(tree.children.length, 3)
assert.equal(tree.children[0].key, '1')
assert.equal(tree.children[0].children[0].children[0].type, 'VirtualText')
})
})
1 change: 1 addition & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './modules/h.spec'
18 changes: 0 additions & 18 deletions test/vdom/create-element.js

This file was deleted.

41 changes: 0 additions & 41 deletions test/vdom/diff.js

This file was deleted.

24 changes: 0 additions & 24 deletions test/vdom/h.js

This file was deleted.

0 comments on commit b0f8072

Please sign in to comment.