Преглед изворни кода

make all unit tests run in real browsers

Evan You пре 12 година
родитељ
комит
6bc19e6e66

+ 2 - 1
.gitignore

@@ -2,4 +2,5 @@
 .sass-cache
 node_modules
 components
-explorations
+explorations
+test/seed.test.js

+ 15 - 20
Gruntfile.js

@@ -19,6 +19,11 @@ module.exports = function( grunt ) {
                 name: 'seed',
                 styles: false,
                 standalone: true
+            },
+            test: {
+                output: './test/',
+                name: 'seed.test',
+                styles: false
             }
         },
 
@@ -32,8 +37,15 @@ module.exports = function( grunt ) {
         },
 
         mocha: {
-            build: {
-                src: ['test/integration/*.html'],
+            unit: {
+                src: ['test/unit/*.html'],
+                options: {
+                    reporter: 'Spec',
+                    run: true
+                }
+            },
+            e2e: {
+                src: ['test/e2e/*.html'],
                 options: {
                     reporter: 'Spec',
                     run: true
@@ -70,7 +82,7 @@ module.exports = function( grunt ) {
     grunt.loadNpmTasks( 'grunt-contrib-uglify' )
     grunt.loadNpmTasks( 'grunt-component-build' )
     grunt.loadNpmTasks( 'grunt-mocha' )
-    grunt.registerTask( 'test', ['unit', 'mocha'] )
+    grunt.registerTask( 'test', ['component_build:test', 'mocha'] )
     grunt.registerTask( 'default', [
         'jshint',
         'component_build:build',
@@ -78,23 +90,6 @@ module.exports = function( grunt ) {
         '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'

+ 108 - 67
dist/seed.js

@@ -399,8 +399,10 @@ api.filter = function (name, fn) {
  *  Set config options
  */
 api.config = function (opts) {
-    if (opts) utils.extend(config, opts)
-    textParser.buildRegex()
+    if (opts) {
+        utils.extend(config, opts)
+        textParser.buildRegex()
+    }
 }
 
 /*
@@ -762,7 +764,7 @@ CompilerProto.compileNode = function (node, root) {
  *  Compile a text node
  */
 CompilerProto.compileTextNode = function (node) {
-    var tokens = TextParser.parse(node)
+    var tokens = TextParser.parse(node.nodeValue)
     if (!tokens) return
     var compiler = this,
         dirname = config.prefix + '-text',
@@ -852,12 +854,21 @@ CompilerProto.createBinding = function (key, isExp) {
     if (binding.isExp) {
         // a complex expression binding
         // we need to generate an anonymous computed property for it
-        var getter = ExpParser.parseGetter(key, this)
-        if (getter) {
+        var result = ExpParser.parse(key)
+        if (result) {
             utils.log('  created anonymous binding: ' + key)
-            binding.value = { get: getter }
+            binding.value = { get: result.getter }
             this.markComputed(binding)
             this.expressions.push(binding)
+            // need to create the bindings for keys
+            // that do not exist yet
+            var i = result.vars.length, v
+            while (i--) {
+                v = result.vars[i]
+                if (!bindings[v]) {
+                    this.rootCompiler.createBinding(v)
+                }
+            }
         } else {
             utils.warn('  invalid expression: ' + key)
         }
@@ -1199,6 +1210,18 @@ BindingProto.refresh = function () {
     while (i--) {
         this.instances[i].refresh()
     }
+    this.pub()
+}
+
+/*
+ *  Notify computed properties that depend on this binding
+ *  to update themselves
+ */
+BindingProto.pub = function () {
+    var i = this.subs.length
+    while (i--) {
+        this.subs[i].refresh()
+    }
 }
 
 /*
@@ -1215,21 +1238,9 @@ BindingProto.unbind = function () {
         subs = this.deps[i].subs
         subs.splice(subs.indexOf(this), 1)
     }
-    // TODO if this is a root level binding
     this.compiler = this.pubs = this.subs = this.instances = this.deps = null
 }
 
-/*
- *  Notify computed properties that depend on this binding
- *  to update themselves
- */
-BindingProto.pub = function () {
-    var i = this.subs.length
-    while (i--) {
-        this.subs[i].refresh()
-    }
-}
-
 module.exports = Binding
 });
 require.register("seed/src/observer.js", function(exports, require, module){
@@ -1246,17 +1257,18 @@ var Emitter = require('./emitter'),
 var arrayMutators = {
     remove: function (index) {
         if (typeof index !== 'number') index = this.indexOf(index)
-        this.splice(index, 1)
+        return this.splice(index, 1)[0]
     },
     replace: function (index, data) {
         if (typeof index !== 'number') index = this.indexOf(index)
-        this.splice(index, 1, data)
+        return this.splice(index, 1, data)[0]
     },
     mutateFilter: function (fn) {
         var i = this.length
         while (i--) {
             if (!fn(this[i])) this.splice(i, 1)
         }
+        return this
     }
 }
 
@@ -1269,6 +1281,7 @@ methods.forEach(function (method) {
             args: slice.call(arguments),
             result: result
         })
+        return result
     }
 })
 
@@ -1331,8 +1344,8 @@ function bind (obj, key, path, observer) {
         },
         set: function (newVal) {
             values[fullKey] = newVal
-            watch(newVal, fullKey, observer)
             observer.emit('set', fullKey, newVal)
+            watch(newVal, fullKey, observer)
         }
     })
     watch(val, fullKey, observer)
@@ -1370,9 +1383,17 @@ function emitSet (obj, observer) {
     if (typeOf(obj) === 'Array') {
         observer.emit('set', 'length', obj.length)
     } else {
-        var values = obj.__values__
+        emit(obj.__values__)
+    }
+    function emit (values, path) {
+        var val
+        path = path ? path + '.' : ''
         for (var key in values) {
-            observer.emit('set', key, values[key])
+            val = values[key]
+            observer.emit('set', path + key, val)
+            if (typeOf(val) === 'Object') {
+                emit(val, key)
+            }
         }
     }
 }
@@ -1446,9 +1467,9 @@ var config     = require('./config'),
     directives = require('./directives'),
     filters    = require('./filters')
 
-var KEY_RE          = /^[^\|<]+/,
+var KEY_RE          = /^[^\|]+/,
     ARG_RE          = /([^:]+):(.+)$/,
-    FILTERS_RE      = /[^\|]\|[^\|<]+/g,
+    FILTERS_RE      = /\|[^\|]+/g,
     FILTER_TOKEN_RE = /[^\s']+|'[^']+'/g,
     NESTING_RE      = /^\^+/,
     SINGLE_VAR_RE   = /^[\w\.]+$/
@@ -1457,7 +1478,7 @@ var KEY_RE          = /^[^\|<]+/,
  *  Directive class
  *  represents a single directive instance in the DOM
  */
-function Directive (directiveName, expression) {
+function Directive (directiveName, expression, rawKey) {
 
     var definition = directives[directiveName]
 
@@ -1476,15 +1497,24 @@ function Directive (directiveName, expression) {
 
     this.directiveName = directiveName
     this.expression    = expression.trim()
-    this.rawKey        = expression.match(KEY_RE)[0].trim()
+    this.rawKey        = rawKey
     
-    this.parseKey(this.rawKey)
+    parseKey(this, rawKey)
+
     this.isExp = !SINGLE_VAR_RE.test(this.key)
     
     var filterExps = expression.match(FILTERS_RE)
-    this.filters = filterExps
-        ? filterExps.map(parseFilter)
-        : null
+    if (filterExps) {
+        this.filters = []
+        var i = 0, l = filterExps.length, filter
+        for (; i < l; i++) {
+            filter = parseFilter(filterExps[i])
+            if (filter) this.filters.push(filter)
+        }
+        if (!this.filters.length) this.filters = null
+    } else {
+        this.filters = null
+    }
 }
 
 var DirProto = Directive.prototype
@@ -1492,7 +1522,7 @@ var DirProto = Directive.prototype
 /*
  *  parse a key, extract argument and nesting/root info
  */
-DirProto.parseKey = function (rawKey) {
+function parseKey (dir, rawKey) {
 
     var argMatch = rawKey.match(ARG_RE)
 
@@ -1500,41 +1530,47 @@ DirProto.parseKey = function (rawKey) {
         ? argMatch[2].trim()
         : rawKey.trim()
 
-    this.arg = argMatch
+    dir.arg = argMatch
         ? argMatch[1].trim()
         : null
 
     var nesting = key.match(NESTING_RE)
-    this.nesting = nesting
+    dir.nesting = nesting
         ? nesting[0].length
         : false
 
-    this.root = key.charAt(0) === '$'
+    dir.root = key.charAt(0) === '$'
 
-    if (this.nesting) {
+    if (dir.nesting) {
         key = key.replace(NESTING_RE, '')
-    } else if (this.root) {
+    } else if (dir.root) {
         key = key.slice(1)
     }
 
-    this.key = key
+    dir.key = key
 }
 
-
 /*
  *  parse a filter expression
  */
 function parseFilter (filter) {
 
-    var tokens = filter.slice(2)
-        .match(FILTER_TOKEN_RE)
-        .map(function (token) {
-            return token.replace(/'/g, '').trim()
-        })
+    var tokens = filter.slice(1).match(FILTER_TOKEN_RE)
+    if (!tokens) return
+    tokens = tokens.map(function (token) {
+        return token.replace(/'/g, '').trim()
+    })
+
+    var name = tokens[0],
+        apply = filters[name]
+    if (!apply) {
+        utils.warn('Unknown filter: ' + name)
+        return
+    }
 
     return {
-        name  : tokens[0],
-        apply : filters[tokens[0]],
+        name  : name,
+        apply : apply,
         args  : tokens.length > 1
                 ? tokens.slice(1)
                 : null
@@ -1567,7 +1603,6 @@ DirProto.refresh = function (value) {
     if (value && value === this.computedValue) return
     this.computedValue = value
     this.apply(value)
-    this.binding.pub()
 }
 
 /*
@@ -1588,7 +1623,6 @@ DirProto.applyFilters = function (value) {
     var filtered = value, filter
     for (var i = 0, l = this.filters.length; i < l; i++) {
         filter = this.filters[i]
-        if (!filter.apply) utils.warn('Unknown filter: ' + filter.name)
         filtered = filter.apply(filtered, filter.args)
     }
     return filtered
@@ -1596,8 +1630,13 @@ DirProto.applyFilters = function (value) {
 
 /*
  *  Unbind diretive
+ *  @ param {Boolean} update
+ *    Sometimes we call unbind before an update (i.e. not destroy)
+ *    just to teardown previousstuff, in that case we do not want
+ *    to null everything.
  */
 DirProto.unbind = function (update) {
+    // this can be called before the el is even assigned...
     if (!this.el) return
     if (this._unbind) this._unbind(update)
     if (!update) this.vm = this.el = this.binding = this.compiler = null
@@ -1613,14 +1652,15 @@ Directive.parse = function (dirname, expression) {
     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],
+        keyMatch = expression.match(KEY_RE),
+        rawKey = keyMatch && keyMatch[0].trim()
 
     if (!dir) utils.warn('unknown directive: ' + dirname)
-    if (!valid) utils.warn('invalid directive expression: ' + expression)
+    if (!rawKey) utils.warn('invalid directive expression: ' + expression)
 
-    return dir && valid
-        ? new Directive(dirname, expression)
+    return dir && rawKey
+        ? new Directive(dirname, expression, rawKey)
         : null
 }
 
@@ -1664,28 +1704,27 @@ module.exports = {
      *  Parse and create an anonymous computed property getter function
      *  from an arbitrary expression.
      */
-    parseGetter: function (exp, compiler) {
+    parse: function (exp) {
         // extract variable names
         var vars = getVariables(exp)
         if (!vars.length) return null
         var args = [],
-            v, i = vars.length,
+            v, i, l = vars.length,
             hash = {}
-        while (i--) {
+        for (i = 0; i < l; i++) {
             v = vars[i]
             // avoid duplicate keys
             if (hash[v]) continue
-            hash[v] = 1
+            hash[v] = v
             // push assignment
             args.push(v + '=this.$get("' + v + '")')
-            // need to create the binding if it does not exist yet
-            if (!compiler.bindings[v]) {
-                compiler.rootCompiler.createBinding(v)
-            }
         }
         args = 'var ' + args.join(',') + ';return ' + exp
         /* jshint evil: true */
-        return new Function(args)
+        return {
+            getter: new Function(args),
+            vars: Object.keys(hash)
+        }
     }
 }
 });
@@ -1706,9 +1745,8 @@ module.exports = {
     /*
      *  Parse a piece of text, return an array of tokens
      */
-    parse: function (node) {
+    parse: function (text) {
         if (!BINDING_RE) module.exports.buildRegex()
-        var text = node.nodeValue
         if (!BINDING_RE.test(text)) return null
         var m, i, tokens = []
         do {
@@ -1716,7 +1754,7 @@ module.exports = {
             if (!m) break
             i = m.index
             if (i > 0) tokens.push(text.slice(0, i))
-            tokens.push({ key: m[1] })
+            tokens.push({ key: m[1].trim() })
             text = text.slice(i + m[0].length)
         } while (true)
         if (text.length) tokens.push(text)
@@ -1838,7 +1876,11 @@ module.exports = {
         bindings.forEach(catchDeps)
         observer.isObserving = false
         utils.log('\ndone.')
-    }
+    },
+
+    // for testing only
+    cdvm: createDummyVM,
+    pcd: parseContextDependency
 }
 });
 require.register("seed/src/filters.js", function(exports, require, module){
@@ -2146,7 +2188,6 @@ module.exports = {
         // the collection has been augmented during Binding.set()
         if (!collection.__observer__) Observer.watchArray(collection, null, new Emitter())
         collection.__observer__.on('mutate', this.mutationListener)
-        // this.compiler.observer.emit('set', this.key + '.length', collection.length)
 
         // create child-seeds and append to DOM
         for (var i = 0, l = collection.length; i < l; i++) {

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
dist/seed.min.js


+ 4 - 2
src/main.js

@@ -26,8 +26,10 @@ api.filter = function (name, fn) {
  *  Set config options
  */
 api.config = function (opts) {
-    if (opts) utils.extend(config, opts)
-    textParser.buildRegex()
+    if (opts) {
+        utils.extend(config, opts)
+        textParser.buildRegex()
+    }
 }
 
 /*

+ 25 - 0
test/e2e/basic.html

@@ -0,0 +1,25 @@
+<!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>
+        <div id="test"></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
+
+            //...
+
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 4 - 8
test/integration/basic.html → test/unit/api.html

@@ -9,17 +9,13 @@
 		<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 src="../seed.test.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)
-			    })
-			})
-
+		</script>
+		<script src="specs/api.js"></script>
+		<script>
 			if (navigator.userAgent.indexOf('PhantomJS') < 0) {
             	mocha.run();
         	}

+ 24 - 0
test/unit/binding.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/binding.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 24 - 0
test/unit/deps-parser.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/deps-parser.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 24 - 0
test/unit/directive.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/directive.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 24 - 0
test/unit/exp-parser.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/exp-parser.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 24 - 0
test/unit/filters.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/filters.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 24 - 0
test/unit/observer.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/observer.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

+ 97 - 0
test/unit/specs/api.js

@@ -0,0 +1,97 @@
+var seed = require('seed')
+
+describe('UNIT: API', function () {
+
+    describe('ViewModel.extend()', function () {
+        
+        it('should return a subclass of seed.ViewModel', function () {
+            var Test = seed.ViewModel.extend({})
+            assert.ok(Test.prototype instanceof seed.ViewModel)
+        })
+
+        it('should mixin options.props', function () {
+            var props = {
+                a: 1,
+                b: 2,
+                c: function () {}
+            }
+            var Test = seed.ViewModel.extend({ props: props })
+            for (var key in props) {
+                assert.strictEqual(Test.prototype[key], props[key])
+            }
+        })
+
+        it('should register VM in utils if options.id exists', function () {
+            var Test = seed.ViewModel.extend({ id: 'test' }),
+                utils = require('seed/src/utils')
+            assert.strictEqual(utils.getVM('test'), Test)
+        })
+
+        it('should call options.init when instantiating', function () {
+            var called = false,
+                Test = seed.ViewModel.extend({ init: function () {
+                    called = true                           
+                }}),
+                test = new Test({ el: document.createElement('div') })
+            assert.ok(called)
+        })
+
+    })
+
+    describe('bootstrap()', function () {
+        
+        it('should compile document.body when no arg is given', function () {
+            // body...
+        })
+
+        it('should querySelector target node if arg is a string', function () {
+            // body...
+        })
+
+        it('should directly compile if arg is a node', function () {
+            // body...
+        })
+
+        it('should use correct VM constructor if sd-viewmodel is present', function () {
+            // body...
+        })
+
+    })
+
+    describe('config()', function () {
+        
+        it('should work when changing prefix', function () {
+            // body...
+        })
+
+        it('should work when changing interpolate tags', function () {
+            // body...
+        })
+
+    })
+
+    describe('filter()', function () {
+        
+        it('should create custom filter', function () {
+            // body...
+        })
+
+        it('should return filter function if only one arg is given', function () {
+            // body...
+        })
+
+    })
+
+    describe('directive()', function () {
+        
+        it('should create custom directive', function () {
+            // body...
+        })
+
+        it('should return directive object/fn if only one arg is given', function () {
+            // body...
+        })
+
+    })
+
+})

+ 1 - 2
test/unit/binding.js → test/unit/specs/binding.js

@@ -1,5 +1,4 @@
-var assert = require('assert'),
-    Binding = require('../../src/binding')
+var Binding = require('seed/src/binding')
 
 describe('UNIT: Binding', function () {
 

+ 1 - 7
test/unit/deps-parser.js → test/unit/specs/deps-parser.js

@@ -7,13 +7,7 @@
  *  it has to work with multiple compilers.
  */
 
-// shiv the document to provide dummy object
-global.document = {
-    createElement: function () { return {} }
-}
-
-var DepsParser = require('../../src/deps-parser'),
-    assert     = require('assert')
+var DepsParser = require('seed/src/deps-parser')
 
 describe('UNIT: Dependency Parser', function () {
 

+ 2 - 3
test/unit/directive.js → test/unit/specs/directive.js

@@ -1,6 +1,5 @@
-var assert = require('assert'),
-    Directive = require('../../src/directive'),
-    directives = require('../../src/directives')
+var Directive = require('seed/src/directive'),
+    directives = require('seed/src/directives')
 
 describe('UNIT: Directive', function () {
 

+ 1 - 2
test/unit/exp-parser.js → test/unit/specs/exp-parser.js

@@ -1,5 +1,4 @@
-var ExpParser = require('../../src/exp-parser'),
-    assert    = require('assert')
+var ExpParser = require('seed/src/exp-parser')
 
 describe('UNIT: Expression Parser', function () {
     

+ 0 - 0
test/unit/filters.js → test/unit/specs/filters.js


+ 2 - 3
test/unit/observer.js → test/unit/specs/observer.js

@@ -1,6 +1,5 @@
-var Observer = require('../../src/observer'),
-    assert = require('assert'),
-    Emitter = require('events').EventEmitter
+var Observer = require('seed/src/observer'),
+    Emitter = require('emitter')
 
 describe('UNIT: Observer', function () {
     

+ 2 - 3
test/unit/text-parser.js → test/unit/specs/text-parser.js

@@ -1,6 +1,5 @@
-var TextParser = require('../../src/text-parser'),
-    assert = require('assert'),
-    config = require('../../src/config')
+var TextParser = require('seed/src/text-parser'),
+    config = require('seed/src/config')
 
 describe('UNIT: TextNode Parser', function () {
 

+ 24 - 0
test/unit/text-parser.html

@@ -0,0 +1,24 @@
+<!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="../seed.test.js"></script>
+        <script>
+            mocha.setup('bdd')
+            var assert = chai.assert
+        </script>
+        <script src="specs/text-parser.js"></script>
+        <script>
+            if (navigator.userAgent.indexOf('PhantomJS') < 0) {
+                mocha.run();
+            }
+        </script>
+    </body>
+</html>

Неке датотеке нису приказане због велике количине промена