From 48d151f431968638a9eef6aaba70c387aec08b16 Mon Sep 17 00:00:00 2001 From: Paul Pflugradt Date: Thu, 26 May 2016 12:01:08 +0200 Subject: [PATCH 1/5] parse test attribute --- lib/parser.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index a353635d1..fd99ac0eb 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -39,6 +39,7 @@ module.exports = function (content, filename, needMap) { var type = node.tagName var lang = getAttribute(node, 'lang') var src = getAttribute(node, 'src') + var test = getAttribute(node, 'test') var scoped = getAttribute(node, 'scoped') != null var warnings = null var map = null @@ -48,12 +49,9 @@ module.exports = function (content, filename, needMap) { } // node count check - if ( - (type === 'script' || type === 'template') && - output[type].length > 0 - ) { + if (type === 'template' && output[type].length > 0) { throw new Error( - '[vue-loader] Only one ') + expect(result).to.match(/__vue_script__ = require.+selector\.js\?type=script&index=0!\.\/test\.vue"\)/g) + }) + it('script test', function () { + var result = loader('') + expect(result).to.match(/\nrequire\("!!.+selector\.js\?type=script&index=0!\.\/test\.vue"\)/g) + }) + it('script test karma', function () { + var result = loader('') + expect(result).to.match(/\nif \(window\._karma__ !== "null"\) {/g) + }) + it('style', function () { + var result = loader('') + expect(result).to.match(/\nrequire.+selector\.js\?type=style&index=0!\.\/test\.vue"\)/g) + }) +}) + describe('vue-loader', function () { var testHTML = '' From c04085c648e3ce702acb9a5fdc74ff629de81b69 Mon Sep 17 00:00:00 2001 From: Paul Pflugradt Date: Thu, 26 May 2016 12:35:04 +0200 Subject: [PATCH 4/5] added karma test --- karma.conf.js | 25 ++++++++++++ package.json | 12 +++++- test/autoprefix.vue | 14 +++++++ test/basic.vue | 31 +++++++++++++++ test/fixtures/autoprefix.vue | 5 --- test/fixtures/basic.vue | 19 --------- test/fixtures/pre.vue | 19 --------- test/fixtures/script-import.vue | 1 - test/fixtures/template-import.vue | 1 - test/karma.vue | 27 +++++++++++++ test/preprocessors.vue | 36 +++++++++++++++++ test/script-import.vue | 10 +++++ test/template-import.vue | 10 +++++ test/test.js | 66 ++----------------------------- 14 files changed, 167 insertions(+), 109 deletions(-) create mode 100644 karma.conf.js create mode 100644 test/autoprefix.vue create mode 100644 test/basic.vue delete mode 100644 test/fixtures/autoprefix.vue delete mode 100644 test/fixtures/basic.vue delete mode 100644 test/fixtures/pre.vue delete mode 100644 test/fixtures/script-import.vue delete mode 100644 test/fixtures/template-import.vue create mode 100644 test/karma.vue create mode 100644 test/preprocessors.vue create mode 100644 test/script-import.vue create mode 100644 test/template-import.vue diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..31346ac39 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,25 @@ +module.exports = function (config) { + config.set({ + preprocessors: { + '**/*.vue': ['webpack', 'sourcemap'] + }, + webpack: { + devtool: 'inline-source-map', + module: { + loaders: [ + { test: /\.vue$/, loader: './index.js' } + ] + } + }, + frameworks: ['mocha', 'chai'], + files: ['test/*.vue'], + plugins: [ + require('karma-webpack'), + require('karma-mocha'), + require('karma-chai'), + require('karma-chrome-launcher'), + require('karma-phantomjs-launcher'), + require('karma-sourcemap-loader') + ] + }) +} diff --git a/package.json b/package.json index 0b6f80bea..5b93db13b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "homepage": "https://github.com/vuejs/vue-loader", "scripts": { "lint": "eslint lib", - "test": "eslint lib && mocha test/test.js --slow 5000 --timeout 10000", + "test:mocha": "mocha test/test.js --slow 5000 --timeout 10000", + "test:karma": "karma start --browsers PhantomJS --single-run", + "test": "npm run lint && npm run test:mocha && npm run test:karma", "docs": "cd docs && gitbook serve", "deploy-docs": "bash ./docs/deploy.sh" }, @@ -68,12 +70,20 @@ "expose-loader": "^0.7.1", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.8.5", + "imports-loader": "^0.6.5", "inject-loader": "^2.0.1", "jade": "^1.11.0", "jsdom": "^8.5.0", + "karma": "^0.13.22", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^1.0.1", + "karma-mocha": "^1.0.1", + "karma-phantomjs-launcher": "^1.0.0", + "karma-sourcemap-loader": "^0.3.7", "mkdirp": "^0.5.1", "mocha": "^2.2.5", "node-libs-browser": "^1.0.0", + "phantomjs-prebuilt": "^2.1.7", "postcss": "^5.0.21", "rimraf": "^2.4.0", "stylus": "^0.54.5", diff --git a/test/autoprefix.vue b/test/autoprefix.vue new file mode 100644 index 000000000..b3f073e63 --- /dev/null +++ b/test/autoprefix.vue @@ -0,0 +1,14 @@ + + diff --git a/test/basic.vue b/test/basic.vue new file mode 100644 index 000000000..d2bc71898 --- /dev/null +++ b/test/basic.vue @@ -0,0 +1,31 @@ + + + + + + diff --git a/test/fixtures/autoprefix.vue b/test/fixtures/autoprefix.vue deleted file mode 100644 index a5308b2e0..000000000 --- a/test/fixtures/autoprefix.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/test/fixtures/basic.vue b/test/fixtures/basic.vue deleted file mode 100644 index 5035c8304..000000000 --- a/test/fixtures/basic.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/test/fixtures/pre.vue b/test/fixtures/pre.vue deleted file mode 100644 index 2eafdb4fd..000000000 --- a/test/fixtures/pre.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/test/fixtures/script-import.vue b/test/fixtures/script-import.vue deleted file mode 100644 index b45d1ec73..000000000 --- a/test/fixtures/script-import.vue +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/test/fixtures/template-import.vue b/test/fixtures/template-import.vue deleted file mode 100644 index ce534539b..000000000 --- a/test/fixtures/template-import.vue +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/karma.vue b/test/karma.vue new file mode 100644 index 000000000..fbb891237 --- /dev/null +++ b/test/karma.vue @@ -0,0 +1,27 @@ + + + + + + diff --git a/test/preprocessors.vue b/test/preprocessors.vue new file mode 100644 index 000000000..a7e7cd3ed --- /dev/null +++ b/test/preprocessors.vue @@ -0,0 +1,36 @@ + + + + + + + diff --git a/test/script-import.vue b/test/script-import.vue new file mode 100644 index 000000000..a39d112b8 --- /dev/null +++ b/test/script-import.vue @@ -0,0 +1,10 @@ + + + diff --git a/test/template-import.vue b/test/template-import.vue new file mode 100644 index 000000000..8b5ca968c --- /dev/null +++ b/test/template-import.vue @@ -0,0 +1,10 @@ + + + diff --git a/test/test.js b/test/test.js index c5fb6fae6..726f6b5ac 100644 --- a/test/test.js +++ b/test/test.js @@ -99,36 +99,6 @@ describe('vue-loader', function () { }) } - it('basic', function (done) { - test({ - entry: './test/fixtures/basic.vue' - }, function (window) { - var module = window.vueModule - expect(module.template).to.contain('

{{msg}}

') - expect(module.data().msg).to.contain('Hello from Component A!') - var style = window.document.querySelector('style').textContent - expect(style).to.contain('comp-a h2 {\n color: #f00;\n}') - done() - }) - }) - - it('pre-processors', function (done) { - test({ - entry: './test/fixtures/pre.vue' - }, function (window) { - var module = window.vueModule - expect(module.template).to.contain( - '

This is the app

' + - '' + - '' - ) - expect(module.data().msg).to.contain('Hello from coffee!') - var style = window.document.querySelector('style').textContent - expect(style).to.contain('body {\n font: 100% Helvetica, sans-serif;\n color: #999;\n}') - done() - }) - }) - it('scoped style', function (done) { test({ entry: './test/fixtures/scoped-css.vue' @@ -162,29 +132,9 @@ describe('vue-loader', function () { }) }) - it('template import', function (done) { - test({ - entry: './test/fixtures/template-import.vue' - }, function (window) { - var module = window.vueModule - expect(module.template).to.contain('

hello

') - done() - }) - }) - - it('script import', function (done) { - test({ - entry: './test/fixtures/script-import.vue' - }, function (window) { - var module = window.vueModule - expect(module.data().msg).to.contain('Hello from Component A!') - done() - }) - }) - it('source map', function (done) { var config = Object.assign({}, globalConfig, { - entry: './test/fixtures/basic.vue', + entry: './test/preprocessors.vue', devtool: 'source-map' }) webpack(config, function (err) { @@ -194,7 +144,7 @@ describe('vue-loader', function () { getFile('test.build.js', function (code) { var line var col - var targetRE = /^\s+msg: 'Hello from Component A!'/ + var targetRE = /^\s+msg: 'Hello from coffee!'/ code.split(/\r?\n/g).some(function (l, i) { if (targetRE.test(l)) { line = i + 1 @@ -207,23 +157,13 @@ describe('vue-loader', function () { column: col }) expect(pos.source.indexOf('basic.vue') > -1) - expect(pos.line).to.equal(9) + expect(pos.line).to.equal(18) done() }) }) }) }) - it('autoprefix', function (done) { - test({ - entry: './test/fixtures/autoprefix.vue' - }, function (window) { - var style = window.document.querySelector('style').textContent - expect(style).to.contain('body {\n -webkit-transform: scale(1);\n transform: scale(1);\n}') - done() - }) - }) - it('media-query', function (done) { test({ entry: './test/fixtures/media-query.vue' From dd3fe07d40006954f117391418db4c761e1e9600 Mon Sep 17 00:00:00 2001 From: Paul Pflugradt Date: Thu, 26 May 2016 12:46:15 +0200 Subject: [PATCH 5/5] added missing dev deps --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index 5b93db13b..75f712577 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "karma-mocha": "^1.0.1", "karma-phantomjs-launcher": "^1.0.0", "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^1.7.0", "mkdirp": "^0.5.1", "mocha": "^2.2.5", "node-libs-browser": "^1.0.0", @@ -89,6 +90,7 @@ "stylus": "^0.54.5", "stylus-loader": "^2.0.0", "sugarss": "^0.1.3", + "vue": "^1.0.24", "vue-hot-reload-api": "^1.2.0", "vue-html-loader": "^1.0.0", "vue-style-loader": "^1.0.0", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy