Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/HBuilderXCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Common {
*/
async checkAndSetEnv(platform = undefined, projectPath) {
let testEnv = true;
if (nodeStatus == undefined || nodeStatus == 'N') {
if (nodeStatus == undefined || nodeStatus === 'N') {
try {
nodeStatus = await checkNode();
} catch (error) {
Expand Down Expand Up @@ -145,7 +145,7 @@ class Common {
// 判断是否安装测试环境必须的插件
let uni_plugin_check = true;
for (let e of Object.keys(plugin_list)) {
if (fs.existsSync(plugin_list[e]) == false) {
if (fs.existsSync(plugin_list[e]) === false) {
uni_plugin_check = false;
const pluginDisplayName = config.HX_PLUGINS_DISPLAYNAME_LIST[e] ? config.HX_PLUGINS_DISPLAYNAME_LIST[e] : e;
const log_for_plugin = `[提示]:测试环境检查,未安装 ${e} 。点击菜单【工具 - 插件安装】,安装【${pluginDisplayName}】插件。`;
Expand All @@ -169,12 +169,12 @@ class Common {
*/
async checkAndSetUTSTestEnv() {
let path_gradleHome = await getPluginConfig('uts-development-android.gradleHome');
if (path_gradleHome != undefined && path_gradleHome.trim() != "" && fs.existsSync(path_gradleHome)) {
if (path_gradleHome != undefined && path_gradleHome.trim() !== "" && fs.existsSync(path_gradleHome)) {
config.UTS_GRADLE_HOME = path_gradleHome;
};

let path_Android_sdkDir = await getPluginConfig('uts-development-android.sdkDir');
if (path_Android_sdkDir != undefined && path_Android_sdkDir.trim() != "" && fs.existsSync(path_Android_sdkDir)) {
if (path_Android_sdkDir != undefined && path_Android_sdkDir.trim() !== "" && fs.existsSync(path_Android_sdkDir)) {
config.UTS_JDK_PATH = path_Android_sdkDir;
};
};
Expand Down
18 changes: 9 additions & 9 deletions src/Initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Initialize extends Common {
let isPrintLog = is_hbuidlerx_cli ? false : true;

// 检查jest.config.js是否存在,如不存在,则创建
if (file_type == 'all' || file_type == 'jest.config.js') {
if (file_type === 'all' || file_type === 'jest.config.js') {
if (!fs.existsSync(jestConfigFile)){
let jest_template_path = path.join(path.resolve(__dirname), 'template', 'jest.config.js');
await this.createFile("jest.config.js", jest_template_path, jestConfigFile, isPrintLog);
Expand All @@ -80,7 +80,7 @@ class Initialize extends Common {


// 检查env.js是否存在,如不存在,则创建
if (file_type == 'all' || file_type == 'env.js') {
if (file_type === 'all' || file_type === 'env.js') {
if (!fs.existsSync(jestEnvFile)){
let env_template_path = path.join(path.resolve(__dirname), 'template', 'env.js');
await this.createFile('env.js', env_template_path, jestEnvFile, isPrintLog);
Expand All @@ -97,20 +97,20 @@ class Initialize extends Common {
* @param {String} cmd
*/
async installTestLibs(runDir, actions, cmd) {
if (cmd == undefined) {
if (cmd === undefined) {
cmd = `"${HBuilderX_NPM_PATH}" install --save --registry=https://registry.npmmirror.com`
};
let { action, source_file, target_file} = actions;
let Notes = `\n\n安装方式:\n1. 命令行进入 ${runDir}目录 \n2. 输入 ${cmd}`

let prompt = action == 'upgrade'
let prompt = action === 'upgrade'
? `自动化测试环境,依赖的jest、adbkit、puppeteer等库有更新,请选择是否更新? \n\n强烈建议您选择更新。更新升级命令,请参考控制台输出。`
: `自动化测试环境,需要安装jest、adbkit、puppeteer等库,是否安装?安装环境之后,才可以正常使用此插件。 ${Notes}`;
let title = action == 'upgrade' ? '更新uni-app自动化测试依赖' : '安装uni-app自动化测试依赖';
let title = action === 'upgrade' ? '更新uni-app自动化测试依赖' : '安装uni-app自动化测试依赖';
let btn = await hxShowMessageBox(title, prompt, ['去升级', '忽略升级']).then( btn => {
return btn;
});
if (['好的', '去升级'].includes(btn) && action == 'upgrade') {
if (['好的', '去升级'].includes(btn) && action === 'upgrade') {
await this.createFile("package.json", source_file, target_file);

const cmd_npm_install = `npm install --save --registry=https://registry.npmmirror.com`;
Expand Down Expand Up @@ -191,7 +191,7 @@ class Initialize extends Common {
'target_file': lib_package_path,
};

if (lib_version != template_version && terminal_id == "") {
if (lib_version !== template_version && terminal_id === "") {
if (current_ignore_upgrade) return true;
actions['action'] = 'upgrade';
const _i_result = await this.installTestLibs(test_lib_dir, actions);
Expand All @@ -201,7 +201,7 @@ class Initialize extends Common {
};
return false;
};
if (lib_version != template_version && terminal_id != "") {
if (lib_version !== template_version && terminal_id !== "") {
await logger(`[uniapp.test] 建议:uni-app自动化测试插件,检测到依赖库有更新,请在菜单【运行 - uni-app自动化测试辅助插件 - 重装测试环境依赖】中,重新安装依赖。`, 'warning');
};

Expand Down Expand Up @@ -265,7 +265,7 @@ class Initialize extends Common {
if (msg) {
await logger(`uniapp-cli项目,${projectPath} 自动化测试运行缺少必要的依赖 ${msg},需要安装相关依赖。`, 'warning');
await logger(`如果自动安装失败,打开终端,进入 ${projectPath} 目录,运行命令: npm install --save ${msg}`, 'info');
if (terminal_id == "") {
if (terminal_id === "") {
this.installTestLibs(projectPath, {}, `npm install --save ${msg}`);
};
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/TestCaseRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Common {
*/
async checkAndSetEnv(platform = undefined, projectPath) {
let testEnv = true;
if (nodeStatus == undefined || nodeStatus == 'N') {
if (nodeStatus == undefined || nodeStatus === 'N') {
nodeStatus = await checkNode().catch(error => {
createOutputChannel(config.i18n.msg_env_node_check, "error");
return error;
Expand Down Expand Up @@ -146,18 +146,18 @@ class Common {
let uni_plugin_check = true;
for (let e of Object.keys(plugin_list)) {
// console.error("=============", plugin_list[e], fs.existsSync(plugin_list[e]));
if (fs.existsSync(plugin_list[e]) == false) {
if (fs.existsSync(plugin_list[e]) === false) {
uni_plugin_check = false;
const pluginDisplayName = config.HX_PLUGINS_DISPLAYNAME_LIST[e] ? config.HX_PLUGINS_DISPLAYNAME_LIST[e] : e;
const log_for_plugin = `[提示]:测试环境检查,未安装 ${e} 。点击菜单【工具 - 插件安装】,安装【${pluginDisplayName}】插件。`;
createOutputChannel(log_for_plugin, 'info');
};
};

if (uni_plugin_check == false && is_uniapp_x) {
if (uni_plugin_check === false && is_uniapp_x) {
createOutputChannel(config.i18n.msg_warning_uniappx_env, 'info');
};
if (uni_plugin_check == false && is_uts_project) {
if (uni_plugin_check === false && is_uts_project) {
createOutputChannel(config.i18n.msg_warning_uts_env, 'info');
};
return testEnv;
Expand All @@ -168,12 +168,12 @@ class Common {
*/
async checkAndSetUTSTestEnv() {
let path_gradleHome = await getPluginConfig('uts-development-android.gradleHome');
if (path_gradleHome != undefined && path_gradleHome.trim() != "" && fs.existsSync(path_gradleHome)) {
if (path_gradleHome != undefined && path_gradleHome.trim() !== "" && fs.existsSync(path_gradleHome)) {
config.UTS_GRADLE_HOME = path_gradleHome;
};

let path_Android_sdkDir = await getPluginConfig('uts-development-android.sdkDir');
if (path_Android_sdkDir != undefined && path_Android_sdkDir.trim() != "" && fs.existsSync(path_Android_sdkDir)) {
if (path_Android_sdkDir != undefined && path_Android_sdkDir.trim() !== "" && fs.existsSync(path_Android_sdkDir)) {
config.UTS_JDK_PATH = path_Android_sdkDir;
};
};
Expand Down
20 changes: 10 additions & 10 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function isUniAppCli(projectPath) {
let t2 = fs.existsSync(path.join(projectPath, "src/pages"));
let t3 = fs.existsSync(path.join(projectPath, "src/manifest.json"));
let t4 = fs.existsSync(path.join(projectPath, "package.json"));
return t1 && t2 && t3 && t4 ? true : false;
return t1 && t2 && t3 && t4;
};

/**
Expand All @@ -39,7 +39,7 @@ async function isUniAppX(projectPath) {
let result = await hx.util.readJSONValue(manifestPath, "uni-app-x").then((data) => {
return data;
});
return result["data"] != null && is_main_ts ? true : false;
return result["data"] != null && is_main_ts;
} catch (error) {
return false;
};
Expand All @@ -58,7 +58,7 @@ async function isUniAppX(projectPath) {
function hxShowMessageBox(title, text, buttons = ['关闭']) {
return new Promise((resolve, reject) => {
if ( buttons.length > 1 && (buttons.includes('关闭') || buttons.includes('取消')) ) {
if (osName == 'darwin') {
if (osName === 'darwin') {
buttons = buttons.reverse();
};
};
Expand All @@ -82,7 +82,7 @@ function hxShowMessageBox(title, text, buttons = ['关闭']) {
* @param {version} String 插件版本
*/
function installPlugin() {
let terminalName = osName == "win32" ? "builtincef3terminal" : "builtinterminal";
let terminalName = osName === "win32" ? "builtincef3terminal" : "builtinterminal";
return new Promise((resolve, reject) => {
let info = {
"id": terminalName,
Expand Down Expand Up @@ -129,8 +129,8 @@ async function getPluginConfig(options) {
*/
const uniMap = new Map();
function createOutputChannel(msg, msgLevel = 'info', viewID = undefined) {
let oID = viewID == undefined || viewID == '' ? 'hbuilderx.uniapp.test' : 'hbuilderx.uniapp.test' + `.${viewID}`;
let title = viewID != 'log' ? "uni-app自动化测试" : "uni-app自动化测试 - 运行日志";
let oID = viewID == undefined || viewID === '' ? 'hbuilderx.uniapp.test' : 'hbuilderx.uniapp.test' + `.${viewID}`;
let title = viewID !== 'log' ? "uni-app自动化测试" : "uni-app自动化测试 - 运行日志";
let output = uniMap.get(oID);
// console.error("..........output", output?.timer?._destroyed);
// if(output?.timer?._destroyed === undefined || output?.timer?._destroyed === false) {
Expand Down Expand Up @@ -235,10 +235,10 @@ function printTestRunLog(MessagePrefix, msg) {
if ((msg.includes("Module Error") && msg.includes("Errors compiling")) || msg.includes("语法错误")) {
lastMsg = lastMsg + "\n";
msgLevel = "error";
} else if (theFour == "FAIL" || msg.includes('TypeError') || (msg.includes('Expected') && msg.includes('Received')) || msg.includes('Test suite failed to run')) {
} else if (theFour === "FAIL" || msg.includes('TypeError') || (msg.includes('Expected') && msg.includes('Received')) || msg.includes('Test suite failed to run')) {
lastMsg = lastMsg + "\n";
msgLevel = "error";
} else if (theFour == "PASS") {
} else if (theFour === "PASS") {
lastMsg = lastMsg + "\n";
msgLevel = "success";
} else if (msg.includes('Ran all test suites.') && msg.includes("Tests") && msg.includes("total")) {
Expand All @@ -256,10 +256,10 @@ async function printTestRunLogForHBuilderXCli(MessagePrefix, msg, logger) {
if ((msg.includes("Module Error") && msg.includes("Errors compiling")) || msg.includes("语法错误")) {
lastMsg = lastMsg + "\n";
msgLevel = "error";
} else if (theFour == "FAIL" || msg.includes('TypeError') || (msg.includes('Expected') && msg.includes('Received')) || msg.includes('Test suite failed to run')) {
} else if (theFour === "FAIL" || msg.includes('TypeError') || (msg.includes('Expected') && msg.includes('Received')) || msg.includes('Test suite failed to run')) {
lastMsg = lastMsg + "\n";
msgLevel = "error";
} else if (theFour == "PASS") {
} else if (theFour === "PASS") {
lastMsg = lastMsg + "\n";
msgLevel = "success";
} else if (msg.includes('Ran all test suites.') && msg.includes("Tests") && msg.includes("total")) {
Expand Down
20 changes: 10 additions & 10 deletions src/core/edit_env_js_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function editEnvjsFile(env_js_path="", testPlatform="", deviceId="", uniPr
launcherExecutablePath = envjs['app-plus'][testPlatform]['executablePath'];
};
} catch (error) {};
if (launcherExecutablePath == undefined || launcherExecutablePath == "") {
if (launcherExecutablePath == undefined || launcherExecutablePath === "") {
launcherExecutablePath = await getPluginConfig("harmony.devTools.path");
};
};
Expand All @@ -80,13 +80,13 @@ async function editEnvjsFile(env_js_path="", testPlatform="", deviceId="", uniPr

if (is_uniapp_x) {
let oldLauncherVersion = envjs["app-plus"]?.["uni-app-x"]?.version;
if (oldLauncherVersion == undefined || oldLauncherVersion.trim() == '' || oldLauncherVersion != config.UNIAPP_X_LAUNCHER_VERSION_TXT) {
if (!oldLauncherVersion || oldLauncherVersion.trim() === '' || oldLauncherVersion !== config.UNIAPP_X_LAUNCHER_VERSION_TXT) {
envjs['app-plus']['uni-app-x'] = {};
envjs['app-plus']['uni-app-x']['version'] = config.UNIAPP_X_LAUNCHER_VERSION_TXT;
};
} else {
let oldLauncherVersion = envjs['app-plus']['version'];
if (oldLauncherVersion.trim() == '' || oldLauncherVersion == undefined || oldLauncherVersion != config.LAUNCHER_VERSION_TXT) {
if (!oldLauncherVersion || oldLauncherVersion.trim() === '' || oldLauncherVersion !== config.LAUNCHER_VERSION_TXT) {
envjs['app-plus']['version'] = config.LAUNCHER_VERSION_TXT;
};
};
Expand All @@ -95,28 +95,28 @@ async function editEnvjsFile(env_js_path="", testPlatform="", deviceId="", uniPr
envjs['app-plus']['uni-app-x']?.[testPlatform] :
envjs['app-plus'][testPlatform];

if (oldPhoneData == undefined || typeof oldPhoneData != 'object') {
if (oldPhoneData == undefined || typeof oldPhoneData !== 'object') {
oldPhoneData = {};
};

let {id,executablePath} = oldPhoneData;
// console.log("=======", oldPhoneData, launcherExecutablePath);

if (id != deviceId || executablePath != launcherExecutablePath) {
if (id !== deviceId || executablePath !== launcherExecutablePath) {
if (is_uniapp_x) {
if (envjs['app-plus']['uni-app-x'][testPlatform] == undefined) {
if (envjs['app-plus']['uni-app-x'][testPlatform] === undefined) {
envjs['app-plus']['uni-app-x'][testPlatform] = {};
};
envjs['app-plus']['uni-app-x'][testPlatform]["id"] = deviceId;
if (isCustomRuntime == false || isCustomRuntime == undefined) {
if (isCustomRuntime === false || isCustomRuntime === undefined) {
envjs['app-plus']['uni-app-x'][testPlatform]["executablePath"] = launcherExecutablePath;
};
} else {
if (envjs['app-plus'][testPlatform] == undefined) {
if (envjs['app-plus'][testPlatform] === undefined) {
envjs['app-plus'][testPlatform] = {};
};
envjs['app-plus'][testPlatform]['id'] = deviceId;
if (isCustomRuntime == false || isCustomRuntime == undefined) {
if (isCustomRuntime === false || isCustomRuntime === undefined) {
envjs['app-plus'][testPlatform]['executablePath'] = launcherExecutablePath;
};
};
Expand All @@ -125,7 +125,7 @@ async function editEnvjsFile(env_js_path="", testPlatform="", deviceId="", uniPr
let lastContent = `module.exports = ${tmp_data}`;
let writeResult = await fsWriteFile(env_js_path, lastContent);

if (writeResult != 'success') {
if (writeResult !== 'success') {
await logger(`将测试设备( $deviceInfo )信息写入 ${envjs} 文件时失败,终止后续操作。`, 'warning');
return false;
};
Expand Down
10 changes: 5 additions & 5 deletions src/core/edit_jest_config_js_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function modifyJestConfigJSFile(scope="", proj={}, client_id) {
// 插件配置项:是否自动修改jest.config.js文件中的testMatch
let userConfig = await getPluginConfig('hbuilderx-for-uniapp-test.AutomaticModificationTestMatch');
// console.error("=========>", userConfig);
if (userConfig == false) {
if (userConfig === false) {
await logger(`[uniapp.test] 您已关闭自动修改 jest.config.js 配置文件中的 testMatch 字段,跳过此操作。`);
return true;
};
Expand All @@ -55,13 +55,13 @@ async function modifyJestConfigJSFile(scope="", proj={}, client_id) {
: "<rootDir>/pages/**/*test.[jt]s?(x)";

// one:代指仅测试单条用例
if (scope == 'one') {
if (scope === 'one') {
let testcase_file_relative_path = selectedFile.slice(projectPath.length + 1);
projectTestMatch = `<rootDir>/${testcase_file_relative_path}`;

// 用于特定测试项目:dcloud-uts和uni-api
let test_js_path = path.basename(selectedFile) + ".test.js";
if (testcase_file_relative_path.substr(0,19) == "pages/autotest/uni-" && fs.existsSync(path.join(selectedFile, test_js_path))) {
if (testcase_file_relative_path.substr(0,19) === "pages/autotest/uni-" && fs.existsSync(path.join(selectedFile, test_js_path))) {
projectTestMatch = `<rootDir>/${testcase_file_relative_path}/${test_js_path}`;
};

Expand All @@ -82,7 +82,7 @@ async function modifyJestConfigJSFile(scope="", proj={}, client_id) {
};

try {
if (oldTestMatch[0] == projectTestMatch) {
if (oldTestMatch[0] === projectTestMatch) {
return true;
};
let jestFileContent = fs.readFileSync(jest_config_js_path, 'utf-8');
Expand All @@ -92,7 +92,7 @@ async function modifyJestConfigJSFile(scope="", proj={}, client_id) {
let lastContent = jestFileContent.replace(/testMatch\s*:{1}\s*\[\S*\]/gi, replaceText);

let writeResult = await fsWriteFile(jest_config_js_path, lastContent);
if (writeResult != 'success') {
if (writeResult !== 'success') {
await logger(`${jest_config_js_path} 修改测试配置文件失败,终止后续操作,请检查此文件。`, 'warning');
return false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/check_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function checkPhoneDeviceNetworkStatus(platform, deviceId) {
deviceWlanData = await execCommand(`hdc -t ${deviceId} shell ifconfig wlan0`);
};

if (deviceWlanData != "") {
if (deviceWlanData !== "") {
const isCheckInetAddr = deviceWlanData.includes("inet addr:");
if (!isCheckInetAddr) {
isConnected = false;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function fsWriteFile(fpath, filecontent) {
return new Promise(function(resolve, reject) {
fs.writeFile(fpath, filecontent, function (err) {
if (err) {
console.eror(err);
console.error(err);
reject(err);
};
resolve('success');
Expand Down
3 changes: 2 additions & 1 deletion src/utils/utils_public.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ function checkNode() {
}, function(error, stdout, stderr) {
if (error) {
reject("N");
return;
};
try {
let version = stdout.match(/(\d{1,3}.\d{1,3}.\d{1,3})/g)[0];
let version = stdout.match(/(\d{1,3}\.\d{1,3}\.\d{1,3})/g)[0];
resolve('Y');
} catch (e) {
reject('N');
Expand Down