forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~ZOUPERS.ZOU/fineui:research/test to research/test * commit 'cfe8ce1d6cc8883808b13320f20cfc292c3df18c': 修复单测问题 && 优化tsconfig.json配置 jest流程打通,mocha用例转为jest用例,但是karma配置暂时还保留 karma单测配置research/test
Zoupers.Zou-邹清原
6 months ago
93 changed files with 1434 additions and 1102 deletions
@ -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/ |
@ -0,0 +1,51 @@
|
||||
import type { Config } from "jest"; |
||||
// import webpackConfig from "./webpack/webpack.dev";
|
||||
|
||||
export default { |
||||
// testEnvironment: "<rootDir>/test/testEnvironmentJsdom.ts",
|
||||
testEnvironment: "jsdom", |
||||
testEnvironmentOptions: { |
||||
// html: fs.readFileSync(path.join(__dirname, "test/index.html")),
|
||||
}, |
||||
testMatch: ["<rootDir>/src/**/*.test.js"], |
||||
collectCoverage: false, |
||||
collectCoverageFrom: ["src/**/*.js", "!src/**/*.test.js"], |
||||
coverageDirectory: "coverage", |
||||
coverageReporters: ["html", "json-summary", "cobertura"], |
||||
|
||||
reporters: [ |
||||
"default", |
||||
[ |
||||
"jest-html-reporters", |
||||
{ |
||||
publicPath: "./html-report", |
||||
openReport: true, |
||||
}, |
||||
], |
||||
], |
||||
|
||||
transform: { |
||||
"^.+\\.jsx?$": "babel-jest", |
||||
"^.+\\.tsx?$": "babel-jest", |
||||
}, |
||||
|
||||
preset: "jest-puppeteer", |
||||
verbose: true, |
||||
watchman: true, |
||||
injectGlobals: true, |
||||
globals: { |
||||
"ts-jest": { |
||||
tsconfig: "tsconfig.json", |
||||
}, |
||||
}, |
||||
setupFilesAfterEnv: [ |
||||
"<rootDir>/src/bundle.js", |
||||
"<rootDir>/src/core/platform/web/config.js", |
||||
"<rootDir>/../demo/i18n/i18n.cn.js", |
||||
"<rootDir>/test/utils.js", |
||||
"<rootDir>/test/prepare.js", |
||||
], |
||||
moduleNameMapper: { |
||||
"@/(.*)$": "<rootDir>/src/$1", |
||||
}, |
||||
} as Config; |
@ -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", |
||||
] |
||||
}); |
||||
}; |
@ -1,31 +1,31 @@
|
||||
/** |
||||
* Created by windy on 2018/01/23. |
||||
*/ |
||||
describe("dateFunctionTest", function () { |
||||
describe("dateFunctionTest", () => { |
||||
|
||||
before(function () { |
||||
beforeAll(() => { |
||||
|
||||
}); |
||||
|
||||
/** |
||||
* test_author_windy |
||||
*/ |
||||
it("getWeekNumber", function () { |
||||
expect(BI.print(BI.getDate(2005, 0, 1), "%Y-%W")).to.equal("2004-53"); |
||||
expect(BI.print(BI.getDate(2005, 0, 2), "%Y-%W")).to.equal("2004-53"); |
||||
expect(BI.print(BI.getDate(2005, 11, 31), "%Y-%W")).to.equal("2005-52"); |
||||
expect(BI.print(BI.getDate(2007, 0, 1), "%Y-%W")).to.equal("2007-01"); |
||||
expect(BI.print(BI.getDate(2007, 11, 30), "%Y-%W")).to.equal("2007-52"); |
||||
expect(BI.print(BI.getDate(2007, 11, 31), "%Y-%W")).to.equal("2008-01"); |
||||
expect(BI.print(BI.getDate(2008, 0, 1), "%Y-%W")).to.equal("2008-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 28), "%Y-%W")).to.equal("2008-52"); |
||||
expect(BI.print(BI.getDate(2008, 11, 29), "%Y-%W")).to.equal("2009-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 30), "%Y-%W")).to.equal("2009-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 31), "%Y-%W")).to.equal("2009-01"); |
||||
expect(BI.print(BI.getDate(2009, 0, 1), "%Y-%W")).to.equal("2009-01"); |
||||
expect(BI.print(BI.getDate(2009, 11, 31), "%Y-%W")).to.equal("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 1), "%Y-%W")).to.equal("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 2), "%Y-%W")).to.equal("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 3), "%Y-%W")).to.equal("2009-53"); |
||||
it("getWeekNumber", () => { |
||||
expect(BI.print(BI.getDate(2005, 0, 1), "%Y-%W")).toBe("2004-53"); |
||||
expect(BI.print(BI.getDate(2005, 0, 2), "%Y-%W")).toBe("2004-53"); |
||||
expect(BI.print(BI.getDate(2005, 11, 31), "%Y-%W")).toBe("2005-52"); |
||||
expect(BI.print(BI.getDate(2007, 0, 1), "%Y-%W")).toBe("2007-01"); |
||||
expect(BI.print(BI.getDate(2007, 11, 30), "%Y-%W")).toBe("2007-52"); |
||||
expect(BI.print(BI.getDate(2007, 11, 31), "%Y-%W")).toBe("2008-01"); |
||||
expect(BI.print(BI.getDate(2008, 0, 1), "%Y-%W")).toBe("2008-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 28), "%Y-%W")).toBe("2008-52"); |
||||
expect(BI.print(BI.getDate(2008, 11, 29), "%Y-%W")).toBe("2009-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 30), "%Y-%W")).toBe("2009-01"); |
||||
expect(BI.print(BI.getDate(2008, 11, 31), "%Y-%W")).toBe("2009-01"); |
||||
expect(BI.print(BI.getDate(2009, 0, 1), "%Y-%W")).toBe("2009-01"); |
||||
expect(BI.print(BI.getDate(2009, 11, 31), "%Y-%W")).toBe("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 1), "%Y-%W")).toBe("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 2), "%Y-%W")).toBe("2009-53"); |
||||
expect(BI.print(BI.getDate(2010, 0, 3), "%Y-%W")).toBe("2009-53"); |
||||
}); |
||||
}); |
||||
|
@ -0,0 +1,3 @@
|
||||
while (BI.prepares && BI.prepares.length > 0) { |
||||
BI.prepares.shift()() |
||||
} |
@ -0,0 +1,71 @@
|
||||
const onetimeAfterEach = [] |
||||
afterEach(() => { |
||||
while(onetimeAfterEach.length > 0) { |
||||
onetimeAfterEach.shift()() |
||||
} |
||||
}); |
||||
|
||||
function registeCloser(...f) { |
||||
onetimeAfterEach.unshift(...f) |
||||
}; |
||||
|
||||
function sleep(t) { |
||||
return new Promise(resolve => setTimeout(() => { |
||||
resolve() |
||||
}, t)) |
||||
}; |
||||
|
||||
function createWidget(widgetJson) { |
||||
var widget = BI.createWidget(BI.extend(widgetJson, { |
||||
root: true |
||||
})); |
||||
widget.element.appendTo("body"); |
||||
registeCloser(() => { |
||||
widget.destroy() |
||||
}); |
||||
return widget; |
||||
}; |
||||
|
||||
/** |
||||
* 模拟一次输入框的keydown事件 |
||||
*/ |
||||
function triggerKeyDown (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 |
||||
*/ |
||||
function triggerMouseover(element, callback) { |
||||
// keydown
|
||||
var e = BI.$.Event("mouseover"); |
||||
element.trigger(e); |
||||
callback && callback(); |
||||
}; |
||||
|
||||
BI.Test = {}; |
||||
BI.extend(BI.Test, { |
||||
registeCloser, |
||||
sleep, |
||||
createWidget, |
||||
triggerKeyDown, |
||||
triggerMouseover |
||||
}) |
Loading…
Reference in new issue