Vue.js + Karma + Jasmine错误

问题描述 投票:0回答:1

我试图在我的项目中设置单元测试。但是当我运行“npm run unit”时,我得到错误:

Hash: 4b252f47b3e4ee498d09
Version: webpack 3.10.0
Time: 57ms
webpack: Compiled successfully.
webpack: Compiling...
Hash: 57781e8d3b2b42032aef
Version: webpack 3.10.0
Time: 6882ms
                                 Asset     Size  Chunks                    Chunk Names
static/img/app-store-badge.d0558d9.svg  12.4 kB          [emitted]
         static/img/bg-cta.36ddbb2.jpg   337 kB          [emitted]  [big]
  static/img/demo-screen-1.82bcf3c.jpg   183 kB          [emitted]
                              index.js  3.92 MB       0  [emitted]  [big]  index.js
  [11] ./node_modules/vue/dist/vue.esm.js 288 kB {0} [built]
  [12] ./src/components/Register.vue 1.99 kB {0} [built]
  [21] ./src/components/Login.vue 1.97 kB {0} [built]
  [22] ./src/router/index.js 2.1 kB {0} [optional] [built]
  [33] ./src/components/Introduce.vue 1.99 kB {0} [built]
 [173] ./src/App.vue 1.63 kB {0} [optional] [built]
 [179] ./test/unit/index.js 657 bytes {0} [built]
 [183] ./test/unit/specs \.spec$ 180 bytes {0} [built]
 [237] ./src ^\.\/(?!main(\.js)?$) 936 bytes {0} [built]
 [240] ./src/assets/img/bg-cta.jpg 75 bytes {0} [optional] [built]
 [242] ./src/assets/img/google-play-badge.svg 9.47 kB {0} [optional] [built]
 [243] ./src/assets/logo.png 9.17 kB {0} [optional] [built]
 [245] ./src/components/Feed.html 0 bytes {0} [optional] [built]
 [249] ./src/components/Introduce.html 282 bytes {0} [optional] [built] [failed] [1 error]
 [252] ./src/components/Main.html 262 bytes {0} [optional] [built] [failed] [1 error]
    + 240 hidden modules

WARNING in ./src/components/Login.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <div class="container" id="main">
|     <h1>Авторизация</h1>
|     <b-form id="form" @submit="onSubmit">
 @ ./src ^\.\/(?!main(\.js)?$)
 @ ./test/unit/index.js

WARNING in ./src/components/Register.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <div id="first">
|   <div class="container" id="main">
|     <h1>Регистрация</h1>
 @ ./src ^\.\/(?!main(\.js)?$)
 @ ./test/unit/index.js

WARNING in ./src/components/Introduce.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <div id="main">
|     <b-navbar toggleable type="dark" variant="dark">
|         <b-navbar-toggle target="nav_text_collapse"></b-navbar-toggle>
 @ ./src ^\.\/(?!main(\.js)?$)
 @ ./test/unit/index.js

WARNING in ./src/components/Main.html
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <div id="main">
|   <!-- <div id="cards" v-for="day in days">
|     <b-card :header="day.date" header-tag="header">
 @ ./src ^\.\/(?!main(\.js)?$)
 @ ./test/unit/index.js
webpack: Compiled with warnings.
01 01 2018 19:51:53.788:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/01 01 2018 19:51:53.791:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency01 01 2018 19:51:53.852:INFO [launcher]: Starting browser PhantomJS
01 01 2018 19:51:56.916:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket fyMui8vnFBG13D6aAAAA with id 5808061
01 01 2018 19:55:16.922:WARN [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Disconnected (1 times), because no message in 200000 ms.
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
  Disconnected, because no message in 200000 ms.

PhantomJS 2.1.1 (Windows 7 0.0.0): Executed 0 of 0 DISCONNECTED (3 mins 20.007 secs / 0 secs)

这也会使用Chrome作为浏览器。在test / unit / specs中,我只有一个简单的测试:Register.spec.js:

import Vue from "vue"
import Register from "@/components/Register.vue";
describe("Register", () => {
    it("sets the correct data", () => {
        const registerData = Register.data();
        expect(registerData.password).toBe("");
    })
});

在karma.conf.js我已经设置了browserNoActivityTimeout:200000,但是没有差异。

Karma.conf.js

// This is a karma config file. For more details see
//   http://karma-runner.github.io/0.13/config/configuration-file.html
// we are also using it with karma-webpack
//   https://github.com/webpack/karma-webpack

var webpackConfig = require('../../build/webpack.test.conf')

module.exports = function (config) {
  config.set({
    // to run in additional browsers:
    // 1. install corresponding karma launcher
    //    http://karma-runner.github.io/0.13/config/browsers.html
    // 2. add it to the `browsers` array below.

    browsers: ['PhantomJS'],
    frameworks: ['jasmine', 'phantomjs-shim'],
    reporters: ['spec', 'coverage'],
    files: ['./index.js'],
    preprocessors: {
      './index.js': ['webpack', 'sourcemap']
    },

    webpack: webpackConfig,
    webpackMiddleware: {
      noInfo: false
    },
    browserNoActivityTimeout: 200000,
    coverageReporter: {
      dir: './coverage',
      reporters: [
        { type: 'lcov', subdir: '.' },
        { type: 'text-summary' }
      ]
    }
  })
}

我究竟做错了什么?谢谢。

javascript webpack vue.js karma-jasmine
1个回答
0
投票

好的,删除node_modules文件夹并运行npm我解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.