Jelajahi Sumber

setup unit testing

Evan You 11 tahun lalu
induk
melakukan
b41cf22720
5 mengubah file dengan 80 tambahan dan 0 penghapusan
  1. 29 0
      gruntfile.js
  2. 36 0
      package.json
  3. 1 0
      src/test.js
  4. 7 0
      src/vue.js
  5. 7 0
      test/unit/specs/main.js

+ 29 - 0
gruntfile.js

@@ -0,0 +1,29 @@
+module.exports = function (grunt) {
+
+    grunt.initConfig({
+        karma: {
+            options: {
+                frameworks: ['jasmine', 'commonjs'],
+                preprocessors: {
+                    'src/*.js': ['commonjs'],
+                    'test/unit/specs/*': ['commonjs']
+                },
+                files: [
+                    'src/*.js',
+                    'test/unit/specs/*.js'
+                ],
+                singleRun: true
+            },
+            browsers: {
+                options: {
+                   browsers: ['Chrome', 'Firefox'],
+                   reporters: ['progress']
+                }
+            }
+        }
+    })
+
+    grunt.loadNpmTasks('grunt-karma')
+    grunt.registerTask('unit', ['karma:browsers'])
+
+}

+ 36 - 0
package.json

@@ -0,0 +1,36 @@
+{
+  "name": "vue",
+  "version": "0.10.5",
+  "author": "Evan You <yyx990803@gmail.com>",
+  "license": "MIT",
+  "description": "Simple, Fast & Composable MVVM for building interative interfaces",
+  "keywords": [
+    "mvvm",
+    "browser",
+    "framework"
+  ],
+  "main": "src/vue.js",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/yyx990803/vue.git"
+  },
+  "bugs": "https://github.com/yyx990803/vue/issues",
+  "homepage": "http://vuejs.org",
+  "scripts": {
+    "test": "grunt travis"
+  },
+  "devDependencies": {
+    "browserify": "^4.2.0",
+    "grunt": "^0.4.5",
+    "grunt-browserify": "^2.1.3",
+    "grunt-karma": "^0.8.3",
+    "karma": "^0.12.16",
+    "karma-browserify": "^0.2.1",
+    "karma-chrome-launcher": "^0.1.4",
+    "karma-commonjs": "0.0.10",
+    "karma-firefox-launcher": "^0.1.3",
+    "karma-jasmine": "^0.1.5",
+    "karma-phantomjs-launcher": "^0.1.4",
+    "karma-safari-launcher": "^0.1.1"
+  }
+}

+ 1 - 0
src/test.js

@@ -0,0 +1 @@
+module.exports = 123

+ 7 - 0
src/vue.js

@@ -0,0 +1,7 @@
+var test = require('./test')
+
+module.exports = {
+    test: function () {
+        return test
+    }
+}

+ 7 - 0
test/unit/specs/main.js

@@ -0,0 +1,7 @@
+var vue = require('../../../src/vue.js')
+
+describe('test', function () {
+    it('should work', function () {
+        expect(vue.test()).toEqual(123)
+    })
+})