无法严格执行测试。
package.json
{
"version": "0.0.1",
"description": "",
"main": "./src/main.ts",
"scripts": {
},
"devDependencies": {
"@types/jasmine": "^2.8.9",
"concurrently": "^4.0.1",
"jasmine": "^3.3.0",
"jasmine-core": "^3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"jasmine-ts": "^0.3.0",
"karma": "^3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-typescript": "^3.0.13",
"karma-webpack": "^3.0.5",
"lite-server": "^2.4.0",
"source-map-loader": "^0.2.4",
"ts-loader": "^5.2.2",
"typescript": "^3.1.3",
"webpack": "^4.23.1"
},
"dependencies": {}
}
karma.config.ts
const webpackConfig = require('./webpack.config');
delete webpackConfig.entry;
webpackConfig.mode = "development";
webpackConfig.devtool = 'inline-source-map';
module.exports = function(config) {
config.set({
frameworks: ["jasmine", "karma-typescript"],
files: [
"spec/client.spec.ts",
{ pattern: './build/*.css', watched: true, served: true, included: true },
],
preprocessors: {
"**/*.ts": ['webpack', 'sourcemap']
},
webpack: webpackConfig,
reporters: ["progress", "kjhtml"],
browsers: ["Chrome"],
karmaTypescriptConfig: {
"compilerOptions": {
"target": "es6",
"lib": ["es5", "es6", "dom"],
}
},
/*
client: {
jasmine: {
random: false
}
}
*/
});
};
测试(spec / client.spec.ts)
/// <reference path="../node_modules/@types/jasmine/index.d.ts" />
jasmine.DEFAULT_TIMEOUT_INTERVAL = 900000;
console.log('Init');
describe('[client]', () => {
console.log('Spec declarations');
it('[Test 1]', (done) => {
console.log('Test 1: started');
// Async stuff here
// ...
// ...
expect(true).toBe(true);
done();
});
it('[Test 2]', (done) => {
console.log('Test 2: started');
// Async stuff here
// ...
// ...
expect(true).toBe(true);
done();
});
it('[Test 3]', (done) => {
console.log('Test 3: started');
// Async stuff here
// ...
// ...
expect(true).toBe(true);
done();
});
it('[Test 4]', (done) => {
console.log('Test 4: started');
// Async stuff here
// ...
// ...
expect(true).toBe(true);
done();
});
});
情况是下一个。如果我在茉莉的karma.config.js设置中注释掉:一切正常,但所有测试均以随机顺序运行。
结果是,我在浏览器控制台中看到了输出:
init
规范声明
测试4:已开始
测试1:开始
测试2:已启动
测试3:已开始
问题是我需要严格执行测试顺序:1、2、3和4。
如果我添加茉莉花的设置,例如:
客户:{ 茉莉花:{ 随机:假 } }
测试根本没有运行。在浏览器控制台的输出中,我仅看到:
init
规范声明
所有测试都是异步进行的。
我已经浪费了很多时间,如果有人建议解决方案,那会很棒。