Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
2f1703ab
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2f1703ab
编写于
12月 05, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file manager 增加 read/write 参数自动化测试示例
上级
01b16b8e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
143 addition
and
3 deletion
+143
-3
pages/API/filemanager/filemanager.test.js
pages/API/filemanager/filemanager.test.js
+139
-1
pages/API/filemanager/filemanager.uvue
pages/API/filemanager/filemanager.uvue
+4
-2
未找到文件。
pages/API/filemanager/filemanager.test.js
浏览文件 @
2f1703ab
...
...
@@ -291,7 +291,7 @@ describe('ExtApi-FileManagerTest', () => {
basePath
:
globalAppResourcePath
,
readFile
:
'
static/list-mock/safe.png
'
,
readFile
Fla
g
:
'
base64
'
readFile
Encodin
g
:
'
base64
'
})
...
...
@@ -561,5 +561,143 @@ describe('ExtApi-FileManagerTest', () => {
});
it
(
'
write and read
'
,
async
()
=>
{
/**
* 测试writefile readfile 各个参数是否符合预期
*/
let
globalTempPath
=
await
getData
(
'
globalTempPath
'
)
await
page
.
setData
({
recursiveVal
:
true
,
basePath
:
globalTempPath
,
readDir
:
'
d
'
,
rmDirFile
:
'
d
'
,
mkdirFile
:
'
d
'
,
writeFileContent
:
"
我爱北京天安门,天安门前太阳升
"
,
writeFileEncoding
:
"
utf-8
"
,
readFileEncoding
:
"
utf-8
"
,
unlinkFile
:
'
d/write.bing
'
,
writeFile
:
'
d/write.bing
'
,
readFile
:
'
d/write.bing
'
,
getFileInfoFile
:
'
d/write.bing
'
,
getFileInfoAlgorithm
:
"
sha1
"
})
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const
btnUnLinkFileButton
=
await
page
.
$
(
'
.btn-unlink-file
'
)
await
btnUnLinkFileButton
.
tap
()
await
isDone
()
// 清除文件夹
const
btnRmDirButton
=
await
page
.
$
(
'
.btn-remove-dir
'
)
await
btnRmDirButton
.
tap
()
await
isDone
()
// 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
const
btnMkdDirButton
=
await
page
.
$
(
'
.btn-mkdir
'
)
await
btnMkdDirButton
.
tap
()
await
isDone
()
const
btnReadDirButton
=
await
page
.
$
(
'
.btn-read-dir
'
)
await
btnReadDirButton
.
tap
()
await
isDone
()
let
fileListComplete
=
await
getData
(
'
fileListComplete
'
)
expect
(
JSON
.
stringify
(
fileListComplete
)).
toEqual
(
'
[]
'
)
let
fileListSuccess
=
await
getData
(
'
fileListSuccess
'
)
expect
(
JSON
.
stringify
(
fileListSuccess
)).
toEqual
(
'
[]
'
)
// 先用utf-8 写入内容
const
btnWriteFileButton
=
await
page
.
$
(
'
.btn-write-file
'
)
await
btnWriteFileButton
.
tap
()
await
isDone
()
const
btnReadFileButton
=
await
page
.
$
(
'
.btn-read-file
'
)
await
btnReadFileButton
.
tap
()
await
isDone
()
let
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
我爱北京天安门,天安门前太阳升
"
)
const
btnGetFileInfoButton
=
await
page
.
$
(
'
.btn-get-file-info
'
)
await
btnGetFileInfoButton
.
tap
()
await
isDone
()
let
getFileInfoSize
=
await
getData
(
'
getFileInfoSize
'
)
expect
(
getFileInfoSize
).
toEqual
(
45
)
let
getFileInfoDigest
=
await
getData
(
'
getFileInfoDigest
'
)
expect
(
getFileInfoDigest
).
toEqual
(
"
2ae9c7672ff6c1e7c7e6a0bb4e74a6f06b39350b
"
)
// 尝试读取base64 信息
await
page
.
setData
({
readFileEncoding
:
"
base64
"
,
})
await
btnReadFileButton
.
tap
()
await
isDone
()
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
5oiR54ix5YyX5Lqs5aSp5a6J6Zeo77yM5aSp5a6J6Zeo5YmN5aSq6Ziz5Y2H
"
)
// 测试ascii,需要特别测试 ascii 写入非法字符的情况,因为微信的常量字符编码和android原生有差异。
await
page
.
setData
({
writeFileContent
:
"
丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间
"
,
writeFileEncoding
:
"
ascii
"
,
readFileEncoding
:
"
base64
"
,
})
await
btnWriteFileButton
.
tap
()
await
isDone
()
await
btnGetFileInfoButton
.
tap
()
await
isDone
()
getFileInfoSize
=
await
getData
(
'
getFileInfoSize
'
)
expect
(
getFileInfoSize
).
toEqual
(
78
)
getFileInfoDigest
=
await
getData
(
'
getFileInfoDigest
'
)
expect
(
getFileInfoDigest
).
toEqual
(
"
4ac7a65055628818341c2ad86ddc4205d8503801
"
)
await
btnReadFileButton
.
tap
()
await
isDone
()
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
GbAtywwibr7mDCeJDFxkxwx8AFAxAg4I4PYJH4pS7lIpAg3lKQqrGQzKFS9VdAIRMljOUrsMyFA8fImHDNgEDdzSAnceBAVxDFU8KLr0
"
)
// 尝试写入合法ascii
await
page
.
setData
({
writeFileContent
:
"
hello jack.hello marry.
"
,
writeFileEncoding
:
"
ascii
"
,
readFileEncoding
:
"
ascii
"
,
})
await
btnWriteFileButton
.
tap
()
await
isDone
()
await
btnReadFileButton
.
tap
()
await
isDone
()
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
hello jack.hello marry.
"
)
// 写入base64 获取 中文
await
page
.
setData
({
writeFileContent
:
"
5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0
"
,
writeFileEncoding
:
"
base64
"
,
readFileEncoding
:
"
utf-8
"
,
})
await
btnWriteFileButton
.
tap
()
await
isDone
()
await
btnReadFileButton
.
tap
()
await
isDone
()
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间
"
)
await
page
.
setData
({
readFileEncoding
:
"
base64
"
,
})
await
btnReadFileButton
.
tap
()
await
isDone
()
readFileRet
=
await
getData
(
'
readFileRet
'
)
expect
(
readFileRet
).
toEqual
(
"
5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0
"
)
});
});
pages/API/filemanager/filemanager.uvue
浏览文件 @
2f1703ab
...
...
@@ -27,7 +27,6 @@
lastFailError:UniError("uni-file-manager",1300000,"mock error"),
lastCompleteError:UniError("uni-file-manager",1300000,"mock error"),
readDir:'a',
readFileFlag:"utf-8",
readFileRet:"",
writeFileContent:"锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦",
getFileInfoAlgorithm:"md5",
...
...
@@ -46,6 +45,8 @@
readFile:'a/1.txt',
recursiveVal:true,
done: false,
writeFileEncoding:"utf-8",
readFileEncoding:"utf-8",
/**
* 待测试的全局环境变量
*/
...
...
@@ -170,6 +171,7 @@
fileManager.writeFile({
filePath:`${this.basePath}${this.writeFile}`,
data:this.writeFileContent,
encoding:this.writeFileEncoding,
success:function(res){
console.log('success',res)
},
...
...
@@ -195,7 +197,7 @@
fileManager.readFile({
filePath:`${this.basePath}${this.readFile}`,
encoding:this.readFile
Fla
g,
encoding:this.readFile
Encodin
g,
success:function(res:ReadFileSuccessResult){
console.log('success',res)
this.readFileRet = res.data
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录