mirror of https://github.com/vuejs/vue.git
get ready for tests
This commit is contained in:
parent
8eb3c17214
commit
c6903e0074
23
Gruntfile.js
23
Gruntfile.js
|
@ -33,7 +33,7 @@ module.exports = function( grunt ) {
|
|||
|
||||
mocha: {
|
||||
build: {
|
||||
src: ['test/test.html'],
|
||||
src: ['test/e2e/*.html'],
|
||||
options: {
|
||||
reporter: 'Spec',
|
||||
run: true
|
||||
|
@ -70,14 +70,31 @@ module.exports = function( grunt ) {
|
|||
grunt.loadNpmTasks( 'grunt-contrib-uglify' )
|
||||
grunt.loadNpmTasks( 'grunt-component-build' )
|
||||
grunt.loadNpmTasks( 'grunt-mocha' )
|
||||
grunt.registerTask( 'test', ['mocha'] )
|
||||
grunt.registerTask( 'test', ['unit', 'mocha'] )
|
||||
grunt.registerTask( 'default', [
|
||||
'jshint',
|
||||
'component_build:build',
|
||||
//'test',
|
||||
'test',
|
||||
'uglify'
|
||||
])
|
||||
|
||||
grunt.registerTask( 'unit', function () {
|
||||
var done = this.async(),
|
||||
path = 'test/unit',
|
||||
Mocha = require('./node_modules/grunt-mocha/node_modules/mocha'),
|
||||
mocha_instance = new Mocha({
|
||||
ui: 'bdd',
|
||||
reporter: 'spec'
|
||||
})
|
||||
fs.readdirSync(path).forEach(function (file) {
|
||||
mocha_instance.addFile(path + '/' + file)
|
||||
})
|
||||
mocha_instance.run(function (errCount) {
|
||||
var withoutErrors = (errCount === 0)
|
||||
done(withoutErrors)
|
||||
})
|
||||
})
|
||||
|
||||
grunt.registerTask( 'version', function (version) {
|
||||
;['package', 'bower', 'component'].forEach(function (file) {
|
||||
file = './' + file + '.json'
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
"license": "MIT",
|
||||
"scripts": [
|
||||
"src/main.js",
|
||||
"src/emitter.js",
|
||||
"src/config.js",
|
||||
"src/utils.js",
|
||||
"src/compiler.js",
|
||||
"src/viewmodel.js",
|
||||
"src/binding.js",
|
||||
"src/observer.js",
|
||||
"src/directive-parser.js",
|
||||
"src/directive.js",
|
||||
"src/exp-parser.js",
|
||||
"src/text-parser.js",
|
||||
"src/deps-parser.js",
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<ul>
|
||||
<li sd-each="item:items" sd-text="item.title"></li>
|
||||
</ul>
|
||||
<p>Total items: {{items.length}}</p>
|
||||
<p>
|
||||
<button sd-on="click:push">push</button>
|
||||
<button sd-on="click:pop">pop</button>
|
||||
|
@ -21,6 +17,10 @@
|
|||
<button sd-on="click:sort">sort</button>
|
||||
<button sd-on="click:reverse">reverse</button>
|
||||
</p>
|
||||
<p>Total items: {{items.length}}</p>
|
||||
<ul>
|
||||
<li sd-each="item:items" sd-text="item.title"></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script src="../dist/seed.js"></script>
|
||||
<script>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
var Emitter = require('emitter'),
|
||||
Observer = require('./observer'),
|
||||
config = require('./config'),
|
||||
utils = require('./utils'),
|
||||
Binding = require('./binding'),
|
||||
DirectiveParser = require('./directive-parser'),
|
||||
TextParser = require('./text-parser'),
|
||||
DepsParser = require('./deps-parser'),
|
||||
ExpParser = require('./exp-parser'),
|
||||
slice = Array.prototype.slice,
|
||||
var Emitter = require('./emitter'),
|
||||
Observer = require('./observer'),
|
||||
config = require('./config'),
|
||||
utils = require('./utils'),
|
||||
Binding = require('./binding'),
|
||||
Directive = require('./directive'),
|
||||
TextParser = require('./text-parser'),
|
||||
DepsParser = require('./deps-parser'),
|
||||
ExpParser = require('./exp-parser'),
|
||||
slice = Array.prototype.slice,
|
||||
vmAttr,
|
||||
eachAttr
|
||||
|
||||
|
@ -168,7 +168,7 @@ CompilerProto.compileNode = function (node, root) {
|
|||
|
||||
if (eachExp) { // each block
|
||||
|
||||
directive = DirectiveParser.parse(eachAttr, eachExp)
|
||||
directive = Directive.parse(eachAttr, eachExp)
|
||||
if (directive) {
|
||||
directive.el = node
|
||||
compiler.bindDirective(directive)
|
||||
|
@ -201,7 +201,7 @@ CompilerProto.compileNode = function (node, root) {
|
|||
j = exps.length
|
||||
while (j--) {
|
||||
exp = exps[j]
|
||||
directive = DirectiveParser.parse(attr.name, exp)
|
||||
directive = Directive.parse(attr.name, exp)
|
||||
if (directive) {
|
||||
valid = true
|
||||
directive.el = node
|
||||
|
@ -236,7 +236,7 @@ CompilerProto.compileTextNode = function (node) {
|
|||
token = tokens[i]
|
||||
el = document.createTextNode('')
|
||||
if (token.key) {
|
||||
directive = DirectiveParser.parse(dirname, token.key)
|
||||
directive = Directive.parse(dirname, token.key)
|
||||
if (directive) {
|
||||
directive.el = el
|
||||
compiler.bindDirective(directive)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var Emitter = require('emitter'),
|
||||
//config = require('./config'),
|
||||
var Emitter = require('./emitter'),
|
||||
utils = require('./utils'),
|
||||
observer = new Emitter()
|
||||
|
||||
|
|
|
@ -160,26 +160,25 @@ DirProto.unbind = function (update) {
|
|||
if (!update) this.vm = this.el = this.binding = this.compiler = null
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
/*
|
||||
* make sure the directive and expression is valid
|
||||
* before we create an instance
|
||||
*/
|
||||
Directive.parse = function (dirname, expression) {
|
||||
|
||||
/*
|
||||
* make sure the directive and expression is valid
|
||||
* before we create an instance
|
||||
*/
|
||||
parse: function (dirname, expression) {
|
||||
var prefix = config.prefix
|
||||
if (dirname.indexOf(prefix) === -1) return null
|
||||
dirname = dirname.slice(prefix.length + 1)
|
||||
|
||||
var prefix = config.prefix
|
||||
if (dirname.indexOf(prefix) === -1) return null
|
||||
dirname = dirname.slice(prefix.length + 1)
|
||||
var dir = directives[dirname],
|
||||
valid = KEY_RE.test(expression)
|
||||
|
||||
var dir = directives[dirname],
|
||||
valid = KEY_RE.test(expression)
|
||||
if (!dir) utils.warn('unknown directive: ' + dirname)
|
||||
if (!valid) utils.warn('invalid directive expression: ' + expression)
|
||||
|
||||
if (!dir) utils.warn('unknown directive: ' + dirname)
|
||||
if (!valid) utils.warn('invalid directive expression: ' + expression)
|
||||
return dir && valid
|
||||
? new Directive(dirname, expression)
|
||||
: null
|
||||
}
|
||||
|
||||
return dir && valid
|
||||
? new Directive(dirname, expression)
|
||||
: null
|
||||
}
|
||||
}
|
||||
module.exports = Directive
|
|
@ -1,7 +1,7 @@
|
|||
var config = require('../config'),
|
||||
utils = require('../utils'),
|
||||
Observer = require('../observer'),
|
||||
Emitter = require('emitter'),
|
||||
Emitter = require('../emitter'),
|
||||
ViewModel // lazy def to avoid circular dependency
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// shiv to make this work for component, browserify
|
||||
// and node at the same time
|
||||
var Emitter
|
||||
try {
|
||||
Emitter = require('emitter')
|
||||
} catch (e) {}
|
||||
module.exports = Emitter || require('events').EventEmitter
|
|
@ -1,4 +1,4 @@
|
|||
var Emitter = require('emitter'),
|
||||
var Emitter = require('./emitter'),
|
||||
utils = require('./utils'),
|
||||
typeOf = utils.typeOf,
|
||||
def = Object.defineProperty,
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="../../node_modules/grunt-mocha/node_modules/mocha/mocha.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../../node_modules/grunt-mocha/node_modules/mocha/mocha.js"></script>
|
||||
<script src="../../node_modules/chai/chai.js"></script>
|
||||
<script src="../../dist/seed.js"></script>
|
||||
<script>
|
||||
mocha.setup('bdd')
|
||||
var assert = chai.assert
|
||||
|
||||
describe('E2E: Basic', function () {
|
||||
it('should have a bootstrap method', function () {
|
||||
assert.ok(seed.bootstrap)
|
||||
})
|
||||
})
|
||||
|
||||
if (navigator.userAgent.indexOf('PhantomJS') < 0) {
|
||||
mocha.run();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,24 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="../node_modules/grunt-mocha/node_modules/mocha/mocha.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../node_modules/grunt-mocha/node_modules/mocha/mocha.js"></script>
|
||||
<script src="../node_modules/chai/chai.js"></script>
|
||||
<script>
|
||||
mocha.setup('bdd')
|
||||
var assert = chai.assert
|
||||
</script>
|
||||
<script src="../dist/seed.js"></script>
|
||||
<script src="test.js"></script>
|
||||
<script>
|
||||
if (navigator.userAgent.indexOf('PhantomJS') < 0) {
|
||||
mocha.run();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +0,0 @@
|
|||
var Seed = require('seed')
|
||||
|
||||
describe('Seed', function () {
|
||||
it('should have a bootstrap method', function () {
|
||||
assert.ok(Seed.bootstrap)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,7 @@
|
|||
var assert = require('assert')
|
||||
|
||||
describe('UNIT: Binding', function () {
|
||||
it('should work', function () {
|
||||
assert.ok(true)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,13 @@
|
|||
// shiv the document to provide dummy object
|
||||
global.document = {
|
||||
createElement: function () { return {} }
|
||||
}
|
||||
|
||||
var DepsParser = require('../../src/deps-parser'),
|
||||
assert = require('assert')
|
||||
|
||||
describe('UNIT: Dependency Parser', function () {
|
||||
it('should work', function () {
|
||||
assert.ok(true)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue