我已经能够设置一个支持打字稿的VueJs项目。 ts文件已成功编译,并且运行正常。我正在尝试使用Karma,mocha和chai启用单元测试。
此guide来自官方vue网站。
我的karma.config.js
如下:
var webpackConfig = require('./webpack.config.common.js');
module.exports = function(config) {
config.set({
basePath: ".",
frameworks: [
'mocha',
'chai',
'sinon'
],
files: ['../src/test/**/*.spec.ts'],
preprocessors: {
'**/*.spec.ts': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
reporters: [
'spec'
],
browsers: [
'Firefox'
]
});
};
使用karma start ./config/karma.config.js --single-run
运行测试会得到以下结果:
clean-webpack-plugin: /home/saurabh/DevEnv/SticyNotes/vuejs-template/dist has been removed.
(node:2343) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
02 02 2019 16:49:12.050:INFO [karma-server]: Karma v4.0.0 server started at http://0.0.0.0:9876/
02 02 2019 16:49:12.076:INFO [launcher]: Launching browsers Firefox with concurrency unlimited
02 02 2019 16:49:12.128:INFO [launcher]: Starting browser Firefox
02 02 2019 16:49:15.522:INFO [Firefox 65.0.0 (Linux 0.0.0)]: Connected on socket 3sTV50Hji3SAvgh8AAAA with id 20821983
02 02 2019 16:49:16.074:WARN [middleware:karma]: Invalid file type, defaulting to js. ts
Firefox 65.0.0 (Linux 0.0.0): Executed 0 of 0 ERROR (0.053 secs / 0 secs)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
似乎业力无法识别ts文件格式。我希望它能识别与将webpack作为预处理器传递给我的身份相同的预处理器,其中ts-loader配置为Typescript的默认加载器。
这也是整个代码的链接:https://gitlab.com/saurabh-harwande-repos/vuejs-template
编辑::正在按照在浏览器中的方式加载Index.spec.ts。因此,测试根本不会被移植。无法理解为什么配置对我来说合适。