Karma 没有 运行 Jasmine 实现回调
Karma doesn't run Jasmine implementation callbacks
我有一小部分 Jasmine 测试正在尝试 运行 使用 Karma。非常感谢任何帮助。
如果我 运行 命令 "jasmine",我可以 运行 测试就好了。但是,当我尝试使用 Karma 时,(karma start --singleRun=true),浏览器打开但没有进一步发生,直到 Karma 最终超时:
26 06 2019 14:40:24.431:INFO [karma]: Delaying execution, these browsers are not ready: Chrome 75.0.3770 (Windows 10.0.0)
26 06 2019 14:42:01.326:WARN [Chrome 75.0.3770 (Windows 10.0.0)]: Disconnected (0 times), because no message in 160000 ms.
26 06 2019 14:42:01.327:DEBUG [Chrome 75.0.3770 (Windows 10.0.0)]: CONFIGURING -> DISCONNECTED
Chrome 75.0.3770 (Windows 10.0.0) ERROR
Disconnected, because no message in 160000 ms.
26 06 2019 14:42:01.330:DEBUG [launcher]: CAPTURED -> BEING_KILLED
26 06 2019 14:42:01.332:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
26 06 2019 14:42:01.333:WARN [karma]: No captured browser, open http://localhost:9876/
Chrome 75.0.3770 (Windows 10.0.0): Executed 0 of 0 DISCONNECTED (2 mins 40.011 secs / 0 secs)
如果我使用 --singleRun=false 代替 运行 并在我的测试中设置断点,然后 运行 "karma run karma.conf.js" 来自新的命令提示符,我注意到断点 在我的测试的实现回调中永远不会被击中。其他断点被击中就好了。
例如在下面的测试中:
describe(">String Utils", function() {
it("should be able to lower case a string",function() {
expect(utils.toLowerCase).toBeDefined();
expect(utils.toLowerCase("HELLO WORLD")).toEqual("hello world");
});
"describe" 或 "it" 函数上的断点将会命中。但是 "expect" 上的断点永远不会被击中。
我已经进入 "it" 函数,看看在尝试设置 jasmine 规范时是否出现错误,但一切似乎都很好。
但是,Karma 从不调用实现回调。 And the browser continually stays "idle"
这是我的karma.conf.js。下面是我的 spec-bundle.js,下面是我的 webpack.
如果你还有什么想看的,我可以 post 或者你可以在我的 github 仓库上查看:https://github.com/webgirlwonder/karma-jasmine-test
// Karma configuration
// Generated on Fri May 17 2019 10:37:04 GMT-0500 (Central Daylight Time)
var webpackConfig = require('./webpack.config.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: [
'spec-bundle.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
// preprocessors: {
// '*.js': [ 'webpack' ],
// 'spec/*Spec.js': ['webpack' ]
// },
preprocessors: {
'spec-bundle.js': ['webpack' ]
},
webpack: webpackConfig,
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec'],
// 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_DEBUG,
/* // enable / disable watching file and executing tests whenever any file changes
autoWatch: true, */
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
/* // Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true, */
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
captureTimeout: 160000,
browserNoActivityTimeout: 160000,
})
}
规格-bundle.js
/*
* Create a context for all tests files below the src folder and all sub-folders.
*/
const context = require.context('./spec/', true, /\Spec\.js$/);
/*
* For each file, call the context function that will require the file and load it up here.
*/
context.keys().forEach(context);
webpack
const config = {
"mode": "development",
"entry": "./spec/MyJSUtilities.spec.js",
"target": "node",
"output": {
"path": __dirname+'/static',
"filename": "[name].[chunkhash:8].js"
}
}
module.exports = config;
这是适合我的配置:
.babelrc
{
"presets": ["@babel/preset-env" ]
}
karma.conf.js
const webpackConfig = require('./webpack.config');
module.exports = function (config) {
config.set({
basePath: '.',
autoWatch: false,
singleRun: true,
browsers: [ 'Chrome' ],
frameworks: [ 'jasmine' ],
files: [
'./src/test.js',
],
preprocessors: {
'./src/**/*.js': [ 'webpack' ],
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true,
stats: 'error-only',
},
});
};
webpack.config.js
module.exports = {
mode: 'development',
devtool: 'none',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
externals: {
request: {
commonjs: 'request',
commonjs2: 'request',
},
os: {
commonjs: 'os',
commonjs2: 'os',
},
process: 'process',
},
};
./src/test.js
const testsContext = require.context(".", true, /spec$/);
testsContext.keys().forEach(testsContext)
我有一小部分 Jasmine 测试正在尝试 运行 使用 Karma。非常感谢任何帮助。
如果我 运行 命令 "jasmine",我可以 运行 测试就好了。但是,当我尝试使用 Karma 时,(karma start --singleRun=true),浏览器打开但没有进一步发生,直到 Karma 最终超时:
26 06 2019 14:40:24.431:INFO [karma]: Delaying execution, these browsers are not ready: Chrome 75.0.3770 (Windows 10.0.0)
26 06 2019 14:42:01.326:WARN [Chrome 75.0.3770 (Windows 10.0.0)]: Disconnected (0 times), because no message in 160000 ms.
26 06 2019 14:42:01.327:DEBUG [Chrome 75.0.3770 (Windows 10.0.0)]: CONFIGURING -> DISCONNECTED
Chrome 75.0.3770 (Windows 10.0.0) ERROR
Disconnected, because no message in 160000 ms.
26 06 2019 14:42:01.330:DEBUG [launcher]: CAPTURED -> BEING_KILLED
26 06 2019 14:42:01.332:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
26 06 2019 14:42:01.333:WARN [karma]: No captured browser, open http://localhost:9876/
Chrome 75.0.3770 (Windows 10.0.0): Executed 0 of 0 DISCONNECTED (2 mins 40.011 secs / 0 secs)
如果我使用 --singleRun=false 代替 运行 并在我的测试中设置断点,然后 运行 "karma run karma.conf.js" 来自新的命令提示符,我注意到断点 在我的测试的实现回调中永远不会被击中。其他断点被击中就好了。
例如在下面的测试中:
describe(">String Utils", function() {
it("should be able to lower case a string",function() {
expect(utils.toLowerCase).toBeDefined();
expect(utils.toLowerCase("HELLO WORLD")).toEqual("hello world");
});
"describe" 或 "it" 函数上的断点将会命中。但是 "expect" 上的断点永远不会被击中。
我已经进入 "it" 函数,看看在尝试设置 jasmine 规范时是否出现错误,但一切似乎都很好。
但是,Karma 从不调用实现回调。 And the browser continually stays "idle"
这是我的karma.conf.js。下面是我的 spec-bundle.js,下面是我的 webpack.
如果你还有什么想看的,我可以 post 或者你可以在我的 github 仓库上查看:https://github.com/webgirlwonder/karma-jasmine-test
// Karma configuration
// Generated on Fri May 17 2019 10:37:04 GMT-0500 (Central Daylight Time)
var webpackConfig = require('./webpack.config.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: [
'spec-bundle.js'
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
// preprocessors: {
// '*.js': [ 'webpack' ],
// 'spec/*Spec.js': ['webpack' ]
// },
preprocessors: {
'spec-bundle.js': ['webpack' ]
},
webpack: webpackConfig,
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec'],
// 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_DEBUG,
/* // enable / disable watching file and executing tests whenever any file changes
autoWatch: true, */
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
/* // Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true, */
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity,
captureTimeout: 160000,
browserNoActivityTimeout: 160000,
})
}
规格-bundle.js
/*
* Create a context for all tests files below the src folder and all sub-folders.
*/
const context = require.context('./spec/', true, /\Spec\.js$/);
/*
* For each file, call the context function that will require the file and load it up here.
*/
context.keys().forEach(context);
webpack
const config = {
"mode": "development",
"entry": "./spec/MyJSUtilities.spec.js",
"target": "node",
"output": {
"path": __dirname+'/static',
"filename": "[name].[chunkhash:8].js"
}
}
module.exports = config;
这是适合我的配置:
.babelrc
{
"presets": ["@babel/preset-env" ]
}
karma.conf.js
const webpackConfig = require('./webpack.config');
module.exports = function (config) {
config.set({
basePath: '.',
autoWatch: false,
singleRun: true,
browsers: [ 'Chrome' ],
frameworks: [ 'jasmine' ],
files: [
'./src/test.js',
],
preprocessors: {
'./src/**/*.js': [ 'webpack' ],
},
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true,
stats: 'error-only',
},
});
};
webpack.config.js
module.exports = {
mode: 'development',
devtool: 'none',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
externals: {
request: {
commonjs: 'request',
commonjs2: 'request',
},
os: {
commonjs: 'os',
commonjs2: 'os',
},
process: 'process',
},
};
./src/test.js
const testsContext = require.context(".", true, /spec$/);
testsContext.keys().forEach(testsContext)