Просмотр исходного кода

restructure for functional tests, use CasperJS

Evan You 12 лет назад
Родитель
Сommit
412873f5d8

+ 33 - 30
Gruntfile.js

@@ -1,19 +1,11 @@
-module.exports = function( grunt ) {
+var fs   = require('fs'),
+    path = require('path')
 
-    var fs = require('fs')
+module.exports = function( grunt ) {
 
     grunt.initConfig({
 
         component_build: {
-            dev: {
-                output: './dist/',
-                name: 'seed',
-                dev: true,
-                sourceUrls: true,
-                styles: false,
-                verbose: true,
-                standalone: 'Seed'
-            },
             build: {
                 output: './dist/',
                 name: 'seed',
@@ -35,7 +27,7 @@ module.exports = function( grunt ) {
                 }
             },
             test: {
-                src: ['test/e2e/**/*.js', 'test/unit/**/*.js'],
+                src: ['test/unit/specs/*.js', 'test/functional/specs/*.js'],
                 options: {
                     jshintrc: 'test/.jshintrc'
                 }
@@ -43,15 +35,8 @@ module.exports = function( grunt ) {
         },
 
         mocha: {
-            unit: {
-                src: ['test/unit/*.html'],
-                options: {
-                    reporter: 'Spec',
-                    run: true
-                }
-            },
-            e2e: {
-                src: ['test/e2e/*.html'],
+            test: {
+                src: ['test/unit/runner.html'],
                 options: {
                     reporter: 'Spec',
                     run: true
@@ -81,7 +66,7 @@ module.exports = function( grunt ) {
             },
             component: {
                 files: ['src/**/*.js', 'component.json'],
-                tasks: ['component_build:dev', 'component_build:test']
+                tasks: ['component_build']
             }
         }
 
@@ -92,14 +77,6 @@ module.exports = function( grunt ) {
     grunt.loadNpmTasks( 'grunt-contrib-uglify' )
     grunt.loadNpmTasks( 'grunt-component-build' )
     grunt.loadNpmTasks( 'grunt-mocha' )
-    grunt.registerTask( 'test', ['component_build:test', 'mocha'] )
-    grunt.registerTask( 'default', [
-        'jshint:dev',
-        'component_build:build',
-        'jshint:test',
-        'test',
-        'uglify'
-    ])
 
     grunt.registerTask( 'version', function (version) {
         ;['package', 'bower', 'component'].forEach(function (file) {
@@ -132,5 +109,31 @@ module.exports = function( grunt ) {
             return true
         }
     })
+
+    grunt.registerTask( 'casper', function () {
+        var done = this.async()
+        grunt.util.spawn({
+            cmd: 'casperjs',
+            args: ['test', 'specs/'],
+            opts: {
+                stdio: 'inherit',
+                cwd: path.resolve('test/functional')
+            }
+        }, function (err, res) {
+            if (err) grunt.fail.fatal(res.stdout)
+            grunt.log.writeln(res.stdout)
+            done()
+        })
+    })
+
+    grunt.registerTask( 'test', ['mocha', 'casper'] )
+
+    grunt.registerTask( 'default', [
+        'jshint:dev',
+        'component_build',
+        'jshint:test',
+        'test',
+        'uglify'
+    ])
     
 }

+ 2 - 1
test/.jshintrc

@@ -21,6 +21,7 @@
         "$": true,
         "mockHTMLEvent": true,
         "mockMouseEvent": true,
-        "mockKeyEvent": true
+        "mockKeyEvent": true,
+        "casper": true
     }
 }

+ 0 - 33
test/e2e/runner.html

@@ -1,33 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <title>Test</title>
-        <meta charset="utf-8">
-        <link rel="stylesheet" type="text/css" href="../lib/mocha.css">
-    </head>
-    <body>
-        <div id="mocha"></div>
-        <div id="test"></div>
-        <script src="../lib/mocha.js"></script>
-        <script src="../lib/chai.js"></script>
-        <script src="../lib/classList.js"></script>
-        <script src="../lib/mockEvent.js"></script>
-        <script src="../../dist/seed.test.js"></script>
-        <script>
-            mocha.setup('bdd')
-            var Seed = require('seed'),
-                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();
-            }
-        </script>
-    </body>
-</html>

+ 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


+ 1 - 1
examples/child-id.html → test/functional/fixtures/child-id.html

@@ -3,7 +3,7 @@
     <head>
         <title></title>
         <meta charset="utf-8">
-        <script src="../dist/seed.js"></script>
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="parent">

+ 1 - 1
examples/encapsulation.html → test/functional/fixtures/encapsulation.html

@@ -3,10 +3,10 @@
     <head>
         <title></title>
         <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="test" sd-hola="hi | nodigits"></div>
-        <script src="../dist/seed.js"></script>
         <script>
             var T = Seed.extend({
                 directives: {

+ 1 - 1
examples/expression.html → test/functional/fixtures/expression.html

@@ -3,13 +3,13 @@
     <head>
         <title></title>
         <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="demo">
             <p sd-text="one + ' ' + two + '!'"></p>
             <input sd-model="one"> <input sd-model="two">
         </div>
-        <script src="../dist/seed.js"></script>
         <script>
             Seed.config({ debug: true })
             var demo = new Seed({

+ 1 - 1
examples/nested-props.html → test/functional/fixtures/nested-props.html

@@ -3,7 +3,7 @@
     <head>
         <title></title>
         <meta charset="utf-8">
-        <script src="../dist/seed.js"></script>
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="a">

+ 2 - 1
examples/nested-viewmodels.html → test/functional/fixtures/nested-viewmodels.html

@@ -17,6 +17,7 @@
             color: #F00;
         }
     </style>
+    <script src="../../../dist/seed.js"></script>
 </head>
 <body>
     <div id="grandpa" data-name="Andy" data-family="Johnson">
@@ -55,7 +56,7 @@
             and offspring of family {{family}}.
         </p>
     </script>
-    <script src="../dist/seed.js"></script>
+    
     <script>
         Seed.config({ debug: true })
 

+ 1 - 1
examples/repeated-items.html → test/functional/fixtures/repeated-items.html

@@ -3,6 +3,7 @@
     <head>
         <title>SEED repeated items</title>
         <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="app">
@@ -24,7 +25,6 @@
                 </li>
             </ul>
         </div>
-        <script src="../dist/seed.js"></script>
         <script>
 
             Seed.config({debug: true})

+ 1 - 1
examples/repeated-vms.html → test/functional/fixtures/repeated-vms.html

@@ -3,7 +3,7 @@
     <head>
         <title></title>
         <meta charset="utf-8">
-        <script src="../dist/seed.js"></script>
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div sd-repeat="item:items" sd-viewmodel="item" sd-on="click:toggle">

+ 1 - 1
examples/share-data.html → test/functional/fixtures/share-data.html

@@ -3,6 +3,7 @@
     <head>
         <title>SEED share data</title>
         <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="a">{{shared.msg}}</div>
@@ -13,7 +14,6 @@
         <div id="d">
             <pre>{{source}}</pre>
         </div>
-        <script src="../dist/seed.js"></script>
         <script>
             var shared = {
                 msg: 'hello'

+ 1 - 1
examples/simple-dir.html → test/functional/fixtures/simple-dir.html

@@ -3,7 +3,7 @@
     <head>
         <title></title>
         <meta charset="utf-8">
-        <script src="../dist/seed.js"></script>
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <div id="hi" sd-test sd-test2></div>

+ 1 - 1
examples/simple.html → test/functional/fixtures/simple.html

@@ -6,7 +6,7 @@
         <style type="text/css">
             .red { color: red; }
         </style>
-        <script src="../dist/seed.js"></script>
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
         <input type="checkbox" sd-model="checked">

+ 1 - 1
examples/template.html → test/functional/fixtures/template.html

@@ -3,6 +3,7 @@
     <head>
         <title></title>
         <meta charset="utf-8">
+        <script src="../../../dist/seed.js"></script>
     </head>
     <body>
 
@@ -12,7 +13,6 @@
             <p>{{hi}}!</p>
         </script>
 
-        <script src="../dist/seed.js"></script>
         <script>
 
             // direct usage

+ 19 - 0
test/functional/specs/simple.js

@@ -0,0 +1,19 @@
+casper.test.begin('testing it out', 5, function (test) {
+    
+    casper
+    .start('./fixtures/simple.html', function () {
+        test.assertSelectorHasText('span', 'YOYOYO', 'filter should work')
+        test.assertNotVisible('h1', 'h1 should not be visible')
+        test.assertDoesntExist('span.red', 'span should not be .red')
+    })
+
+    .thenClick('input[type="checkbox"]', function () {
+        test.assertVisible('h1', 'h1 should be visible after clicking checkbox')
+        test.assertExists('span.red', 'span should have .red after clicking checkbox')
+    })
+
+    .run(function () {
+        test.done()
+    })
+
+})

+ 5 - 5
test/unit/runner.html

@@ -3,15 +3,15 @@
 	<head>
 		<title>Test</title>
 		<meta charset="utf-8">
-		<link rel="stylesheet" type="text/css" href="../lib/mocha.css">
+		<link rel="stylesheet" type="text/css" href="vendor/mocha.css">
 	</head>
 	<body>
 		<div id="mocha"></div>
 		<div id="test" style="display:none"></div>
-		<script src="../lib/mocha.js"></script>
-		<script src="../lib/chai.js"></script>
-		<script src="../lib/classList.js"></script>
-		<script src="../lib/mockEvent.js"></script>
+		<script src="vendor/mocha.js"></script>
+		<script src="vendor/chai.js"></script>
+		<script src="vendor/classList.js"></script>
+		<script src="vendor/mockEvent.js"></script>
 		<script src="../../dist/seed.test.js"></script>
 		<script>
 			mocha.setup('bdd')

+ 0 - 0
test/lib/chai.js → test/unit/vendor/chai.js


+ 0 - 0
test/lib/classList.js → test/unit/vendor/classList.js


+ 0 - 0
test/lib/mocha.css → test/unit/vendor/mocha.css


+ 0 - 0
test/lib/mocha.js → test/unit/vendor/mocha.js


+ 0 - 0
test/lib/mockEvent.js → test/unit/vendor/mockEvent.js