Kaynağa Gözat

test structure changes

Evan You 12 yıl önce
ebeveyn
işleme
206e3bce64

+ 1 - 1
examples/nested-viewmodels.html

@@ -68,7 +68,7 @@
                 }
             }
         })
-        seed.bootstrap('#grandpa')
+        seed.compile('#grandpa')
     </script>
 </body>
 </html>

+ 0 - 23
examples/watch.html

@@ -1,23 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-    <head>
-        <title>watch</title>
-        <meta charset="utf-8">
-    </head>
-    <body>
-        <div id="output"></div>
-        <input sd-value="input">
-        <script src="../dist/seed.js"></script>
-        <script>
-            new seed.ViewModel({
-                el: document.body,
-                init: function () {
-                    var output = document.getElementById('output')
-                    this.$watch('input', function (val) {
-                        output.textContent = val
-                    })
-                }
-            })
-        </script>
-    </body>
-</html>

+ 3 - 1
src/compiler.js

@@ -515,7 +515,9 @@ CompilerProto.destroy = function () {
         }
     }
     // remove el
-    if (el.parentNode) {
+    if (el === document.body) {
+        el.innerHTML = ''
+    } else if (el.parentNode) {
         el.parentNode.removeChild(el)
     }
 }

+ 4 - 4
src/main.js

@@ -33,12 +33,12 @@ api.config = function (opts) {
 }
 
 /*
- *  Angular style bootstrap
+ *  Compile a node
  */
-api.bootstrap = function (el) {
-    el = (typeof el === 'string'
+api.compile = function (el) {
+    el = typeof el === 'string'
         ? document.querySelector(el)
-        : el) || document.body
+        : el
     var Ctor = ViewModel,
         vmAttr = config.prefix + '-viewmodel',
         vmExp = el.getAttribute(vmAttr)

+ 12 - 6
src/text-parser.js

@@ -1,6 +1,15 @@
 var config     = require('./config'),
     ESCAPE_RE  = /[-.*+?^${}()|[\]\/\\]/g,
-    BINDING_RE
+    BINDING_RE = build()
+
+/*
+ *  Build interpolate tag regex from config settings
+ */
+function build () {
+    var open = escapeRegex(config.interpolateTags.open),
+        close = escapeRegex(config.interpolateTags.close)
+    return new RegExp(open + '(.+?)' + close)
+}
 
 /*
  *  Escapes a string so that it can be used to construct RegExp
@@ -15,7 +24,6 @@ module.exports = {
      *  Parse a piece of text, return an array of tokens
      */
     parse: function (text) {
-        if (!BINDING_RE) module.exports.buildRegex()
         if (!BINDING_RE.test(text)) return null
         var m, i, tokens = []
         do {
@@ -31,11 +39,9 @@ module.exports = {
     },
 
     /*
-     *  Build interpolate tag regex from config settings
+     *  External build
      */
     buildRegex: function () {
-        var open = escapeRegex(config.interpolateTags.open),
-            close = escapeRegex(config.interpolateTags.close)
-        BINDING_RE = new RegExp(open + '(.+?)' + close)
+        BINDING_RE = build()
     }
 }

+ 8 - 3
test/e2e/basic.html → test/e2e/runner.html

@@ -14,9 +14,14 @@
         <script>
             mocha.setup('bdd')
             var assert = chai.assert
-
-            //...
-
+        </script>
+        <script src="specs/basic.js"></script>
+        <script src="specs/expressions.js"></script>
+        <script src="specs/computed-props.js"></script>
+        <script src="specs/nested-props.js"></script>
+        <script src="specs/nested-vms.js"></script>
+        <script src="specs/repeated-items.js"></script>
+        <script>
             if (navigator.userAgent.indexOf('PhantomJS') < 0) {
                 mocha.run();
             }

+ 0 - 0
test/e2e/specs/basic.js


+ 0 - 0
test/e2e/specs/computed-props.js


+ 0 - 0
test/e2e/specs/expressions.js


+ 0 - 0
test/e2e/specs/nested-props.js


+ 0 - 0
test/e2e/specs/nested-vms.js


+ 0 - 0
test/e2e/specs/repeated-items.js


+ 0 - 0
test/e2e/specs/template.js


+ 4 - 1
test/unit/test.html → test/unit/runner.html

@@ -7,6 +7,7 @@
 	</head>
 	<body>
 		<div id="mocha"></div>
+		<div id="test" style="display:none"></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>
@@ -14,7 +15,6 @@
 			mocha.setup('bdd')
 			var assert = chai.assert
 		</script>
-		<script src="specs/api.js"></script>
 		<script src="specs/binding.js"></script>
 		<script src="specs/directive.js"></script>
 		<script src="specs/observer.js"></script>
@@ -22,6 +22,9 @@
 		<script src="specs/text-parser.js"></script>
 		<script src="specs/deps-parser.js"></script>
 		<script src="specs/filters.js"></script>
+		<script src="specs/directives.js"></script>
+		<script src="specs/api.js"></script>
+		<script src="specs/viewmodel.js"></script>
 		<script>
 			if (navigator.userAgent.indexOf('PhantomJS') < 0) {
             	mocha.run();

+ 1 - 5
test/unit/specs/api.js

@@ -38,11 +38,7 @@ describe('UNIT: API', function () {
 
     })
 
-    describe('bootstrap()', function () {
-        
-        it('should compile document.body when no arg is given', function () {
-            // body...
-        })
+    describe('compile()', function () {
 
         it('should querySelector target node if arg is a string', function () {
             // body...

+ 11 - 0
test/unit/specs/directives.js

@@ -0,0 +1,11 @@
+/*
+ *  Only tests directives in `src/directives/index.js`
+ *  and the non-delegated case for `sd-on`
+ *
+ *  The combination of `sd-each` and `sd-on` are covered in
+ *  the E2E test case for repeated items.
+ */
+
+describe('UNIT: Directives', function () {
+    // body...
+})

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

@@ -0,0 +1,3 @@
+describe('UNIT: Filters', function () {
+    // body...
+})

+ 13 - 2
test/unit/specs/text-parser.js

@@ -47,13 +47,16 @@ describe('UNIT: TextNode Parser', function () {
     })
 
     describe('.buildRegex()', function () {
-        
-        it('should update the interpolate tags and work', function () {
+
+        before(function () {
             config.interpolateTags = {
                 open: '<%',
                 close: '%>'
             }
             TextParser.buildRegex()
+        })
+        
+        it('should update the interpolate tags and work', function () {
             var tokens = TextParser.parse('hello <%a%>! <% bcd %><%d.e.f%> <%a + (b || c) ? d : e%>')
             assert.strictEqual(tokens.length, 7)
             assert.strictEqual(typeof tokens[0], 'string')
@@ -65,6 +68,14 @@ describe('UNIT: TextNode Parser', function () {
             assert.strictEqual(tokens[6].key, 'a + (b || c) ? d : e')
         })
 
+        after(function () {
+            config.interpolateTags = {
+                open: '{{',
+                close: '}}'
+            }
+            TextParser.buildRegex()
+        })
+
     })
 
 })

+ 11 - 0
test/unit/specs/viewmodel.js

@@ -0,0 +1,11 @@
+/*
+ *  Only tests the following:
+ *  - .$get()
+ *  - .$set()
+ *  - .$watch()
+ *  - .$unwatch()
+ */
+
+describe('UNIT: ViewModel', function () {
+    // body...
+})