Browse Source

karma单测配置

research/test^2
Zoupers 6 months ago
parent
commit
feca9ef16b
  1. 2
      .npmrc
  2. 2
      packages/fineui/.gitignore
  3. 167
      packages/fineui/karma.conf.js
  4. 16
      packages/fineui/package.json
  5. 3
      packages/fineui/test/prepare.js
  6. 45
      packages/fineui/test/utils.js

2
.npmrc

@ -1,2 +1,2 @@
puppeteer_download_host=https://npm.taobao.org/mirrors
PUPPETEER_DOWNLOAD_BASE_URL=https://cdn.npmmirror.com/binaries/chrome-for-testing
@fui:registry=https://npm.fineres.com/

2
packages/fineui/.gitignore vendored

@ -0,0 +1,2 @@
logs/*
coverage/*

167
packages/fineui/karma.conf.js

@ -0,0 +1,167 @@
// Karma configuration
// Generated on Mon Nov 27 2017 11:16:26 GMT+0800 (中国标准时间)
const os = require("os");
const webpackConfig = require("./webpack/webpack.dev")
process.env.CHROME_BIN = require("puppeteer").executablePath();
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: ["webpack", "mocha", "chai"],
// list of files / patterns to load in the browser
files: [].concat(
webpackConfig.entry.fineui,
["test/**/*.js", "src/**/*.test.js"]
),
exclude: [
"src/base/tree/ztree/jquery.ztree.core-3.5.js",
"src/base/tree/ztree/jquery.ztree.excheck-3.5.js",
"src/base/single/input/file.js",
"src/case/loading/loading_pane.js",
"src/base/tree/ztree/**/*.js",
"src/case/tree/ztree/*.js",
"src/widget/multitree/**/*.js",
"src/widget/multiselecttree/**/*.js",
"src/component/treevaluechooser/*.js"
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"src/less/**/*.less": ["webpack"],
"ui/**/*.less": ["webpack"],
"src/*.js": ["webpack"],
"src/**/!(*.test).js": ["webpack"],
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ["progress", "coverage", "html"],
browserDisconnectTolerance: 3,
browserDisconnectTimeout : 300000,
browserNoActivityTimeout : 300000,
coverageReporter: {
// specify a common output directory
dir: "coverage/",
reporters: [
// reporters not supporting the `file` property
{ type: "html", subdir: "report-html" },
{ type: "json-summary", subdir: "report-json-summary" },
{ type: "cobertura", subdir: "report-cobertura"}
]
},
htmlReporter: {
outputFile: "logs/test-report.html"
},
// web server port
port: 9878,
// 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,
loggers: [
{
type: "console"
},
{
type: "file",
filename: "logs/karma.log"
}
],
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// you can define custom flags
customLaunchers: {
HeadlessChrome: {
base: "ChromeHeadless",
flags: [
"--no-sandbox",
"--remote-debugging-port=9222",
"--enable-logging",
"--user-data-dir=./karma-chrome",
"--v=1",
"--disable-background-timer-throttling",
"--disable-renderer-backgrounding",
"--proxy-bypass-list=*",
"--disable-web-security",
"--disable-gpu",
],
},
ChromeDebug: {
base: "Chrome",
flags: [
"--no-sandbox",
"--remote-debugging-port=9222",
"--enable-logging",
"--user-data-dir=./karma-chrome",
"--v=1",
"--disable-background-timer-throttling",
"--disable-renderer-backgrounding",
"--proxy-bypass-list=*",
"--disable-web-security",
"--disable-gpu",
],
},
},
// // start these browsers
// // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [os.platform() === "win32"
&& parseFloat(os.release()
.split(".")
.slice(0, 2)
.join(".")) <= 6.1
? "HeadlessChrome" : "ChromeHeadless"],
retryLimit: 30,
captureTimeout: 30000,
// 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,
webpack: webpackConfig,
plugins: [
"karma-webpack",
"karma-mocha",
"karma-chai",
"karma-chrome-launcher",
"karma-coverage",
"karma-htmlfile-reporter",
]
});
};

16
packages/fineui/package.json

@ -30,7 +30,8 @@
"tsc": "tsc",
"link": "pnpm link --global",
"build:biCss": "cross-env LESS_CONFIG_PATH=bi.lessconfig.json LESS_FILE_NAME=bi npm run webpack:css",
"build:jsyCss": "cross-env LESS_CONFIG_PATH=jsy.lessconfig.json LESS_FILE_NAME=jsy npm run webpack:css"
"build:jsyCss": "cross-env LESS_CONFIG_PATH=jsy.lessconfig.json LESS_FILE_NAME=jsy npm run webpack:css",
"test": "karma start"
},
"files": [
"dist",
@ -57,7 +58,18 @@
"jquery": "3.6.3"
},
"devDependencies": {
"chai": "4.2.0",
"core-js": "^3.30.2",
"cross-env": "^7.0.3"
"cross-env": "^7.0.3",
"karma": "3.1.4",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.2",
"karma-htmlfile-reporter": "^0.3.8",
"karma-mocha": "1.3.0",
"karma-typescript": "^5.5.4",
"karma-webpack": "^5.0.1",
"mocha": "5.2.0",
"puppeteer": "^22.8.2"
}
}

3
packages/fineui/test/prepare.js

@ -0,0 +1,3 @@
while (BI.prepares && BI.prepares.length > 0) {
BI.prepares.shift()()
}

45
packages/fineui/test/utils.js

@ -0,0 +1,45 @@
BI.Test = {};
BI.extend(BI.Test, {
createWidget: function (widgetJson) {
var widget = BI.createWidget(BI.extend(widgetJson, {
root: true
}));
widget.element.appendTo("body");
return widget;
},
/**
* 模拟一次输入框的keydown事件
*/
triggerKeyDown: function (element, value, keyCode, callback) {
// keydown
var e = BI.$.Event("keydown");
e.keyCode = keyCode;
element.trigger(e);
// input
BI.isNotNull(value) && element.val(value);
var e1 = BI.$.Event("input");
e1.originalEvent = {};
e1.keyCode = keyCode;
element.trigger(e1);
// keyup 至少等300ms后触发
var e2 = BI.$.Event("keyup");
e2.keyCode = keyCode;
element.trigger(e2);
BI.delay(function () {
callback();
}, 300);
},
/**
* 模拟一次鼠标hover
*/
triggerMouseover: function (element, callback) {
// keydown
var e = BI.$.Event("mouseover");
element.trigger(e);
callback && callback();
}
})
Loading…
Cancel
Save