我正在使用Typescript在Node / ExpressJS中创建一个项目。我正在尝试使用Karma运行spec.ts文件,但它一直在加载(它说“实例化测试”)。
我正在WebStorm中运行测试。
测试运行输出
/usr/local/bin/node /Applications/WebStorm.app/Contents/plugins/js-karma/js_reporter/karma-intellij/lib/intellijRunner.js --karmaPackageDir=/Users/kevin/Developer/*/node_modules/karma --serverPort=9877 --urlRoot=/ --testName=Test
Karma Server输出
/usr/local/bin/node /Applications/WebStorm.app/Contents/plugins/js-
karma/js_reporter/karma-intellij/lib/intellijServer.js --karmaPackageDir=/Users/kevin/Developer/*/node_modules/karma --configFile=/Users/kevin/Developer/*/karma.conf.js
06 11 2017 15:22:04.525:WARN [karma]: Port 9876 in use
06 11 2017 15:22:04.528:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9877/
06 11 2017 15:22:04.529:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
06 11 2017 15:22:04.537:INFO [launcher]: Starting browser PhantomJS
06 11 2017 15:22:05.752:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket eZBj-sWLsllWuk1tAAAA with id 53965572
Package.json(devDependencies)
"@types/jasmine": "^2.6.2",
"grunt": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-karma": "^2.0.0",
"grunt-ts": "^6.0.0-beta.17",
"jasmine-core": "^2.8.0",
"karma": "^1.7.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-requirejs": "^1.1.0",
"karma-typescript": "^3.0.8",
"load-grunt-tasks": "^3.5.2",
"phantomjs": "^2.1.7",
"requirejs": "^2.3.5",
生成karma.conf.js
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: [
{pattern: './src/**/*.spec.ts', included: false}
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
示例测试(test.spec.ts)
describe('Test', () => {
it("should pass", () => {
let helloWorldString = "Hello World";
expect(helloWorldString).toEqual("Hello World");
});
});
我的文件结构是: ./src =>所有.ts文件(这也包括.spec.ts文件) ./dist =>所有.js文件(使用npm run grunt从.ts文件生成)
任何人都知道我做错了什么? 我不确定我是否应该运行.spec.ts文件或.spec.js文件,这可能是问题吗?