diff --git a/pages/API/get-file-system-manager/get-file-system-manager.test.js b/pages/API/get-file-system-manager/get-file-system-manager.test.js index 3aee10833732dd823527548d655f2e58fc7e1644..73473131c2806c4a3aa99b6e7559f79f8e328bd3 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.test.js +++ b/pages/API/get-file-system-manager/get-file-system-manager.test.js @@ -9,6 +9,7 @@ describe('ExtApi-FileManagerTest', () => { return } let page; + function getData(key = '') { return new Promise(async (resolve, reject) => { const data = await page.data() @@ -26,7 +27,9 @@ describe('ExtApi-FileManagerTest', () => { let isDone = await page.waitFor(async () => { return await page.data('done') }) - await page.setData({done: false}) + await page.setData({ + done: false + }) return isDone } @@ -35,16 +38,16 @@ describe('ExtApi-FileManagerTest', () => { let globalUserDataPath = await getData('globalUserDataPath') await page.setData({ - logAble:false, + logAble: false, recursiveVal: true, - copyToBasePath:globalUserDataPath, + copyToBasePath: globalUserDataPath, basePath: globalUserDataPath, - rmDirFile:'a', - readDir:'a', - writeFile:'a/1.txt', - readFile:'a/1.txt', - unlinkFile:'a/1.txt', - writeFileContent:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦' + rmDirFile: 'a', + readDir: 'a', + writeFile: 'a/1.txt', + readFile: 'a/1.txt', + unlinkFile: 'a/1.txt', + writeFileContent: '锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦' }) // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 @@ -76,7 +79,7 @@ describe('ExtApi-FileManagerTest', () => { // 先测试 recursive = false 文件夹创建,期望失败 await page.setData({ recursiveVal: false, - mkdirFile:'a/b/c' + mkdirFile: 'a/b/c' }) @@ -131,7 +134,7 @@ describe('ExtApi-FileManagerTest', () => { // 更换文件内容 获取和对比 文件md5和sha1 await page.setData({ writeFileContent: "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright.", - getFileInfoAlgorithm:"md5" + getFileInfoAlgorithm: "md5" }) await btnWriteFileButton.tap() await isDone() @@ -139,7 +142,9 @@ describe('ExtApi-FileManagerTest', () => { await btnReadFileButton.tap() await isDone() readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright.") + expect(readFileRet).toEqual( + "If you were a teardrop;In my eye,For fear of losing you,I would never cry.And if the golden sun,Should cease to shine its light,Just one smile from you,Would make my whole world bright." + ) const btnGetFileInfoButton = await page.$('#btn-get-file-info') await btnGetFileInfoButton.tap() @@ -151,7 +156,7 @@ describe('ExtApi-FileManagerTest', () => { expect(getFileInfoDigest).toEqual("29ddd02ed3c38ccebb98884eda082cb1") // 切换为 sha1 await page.setData({ - getFileInfoAlgorithm:"sha1" + getFileInfoAlgorithm: "sha1" }) await btnGetFileInfoButton.tap() @@ -165,8 +170,8 @@ describe('ExtApi-FileManagerTest', () => { // 测试 copyfile await page.setData({ - copyFromFile:"a/1.txt", - copyToFile:"a/2.txt" + copyFromFile: "a/1.txt", + copyToFile: "a/2.txt" }) const btnCopyFileButton = await page.$('#btn-copy-file') await btnCopyFileButton.tap() @@ -186,8 +191,8 @@ describe('ExtApi-FileManagerTest', () => { // 测试 rename await page.setData({ - renameFromFile:"a/2.txt", - renameToFile:"a/3.txt" + renameFromFile: "a/2.txt", + renameToFile: "a/3.txt" }) const btnRenameFileButton = await page.$('#btn-rename-file') @@ -213,19 +218,19 @@ describe('ExtApi-FileManagerTest', () => { let version = process.env.uniTestPlatformInfo version = parseInt(version.split(" ")[1]) let testDirName = "我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;," - if(version < 6){ + if (version < 6) { // android 6 以下文件名不能包含特殊字符 testDirName = "我们经历了一场兵慌马乱的战争" } await page.setData({ - logAble:false, + logAble: false, recursiveVal: true, basePath: globalTempPath, - copyToBasePath:globalTempPath, - rmDirFile:'a', + copyToBasePath: globalTempPath, + rmDirFile: 'a', mkdirFile: 'a', - unlinkFile:'a/'+ testDirName +'/中文路径/张三/name/中文文件.mock' + unlinkFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock' }) @@ -259,7 +264,7 @@ describe('ExtApi-FileManagerTest', () => { // 测试 创建多层级文件目录 await page.setData({ recursiveVal: true, - mkdirFile:'a/b/c/d/e/f/g/h/i/g/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/中文路径/张三/test', + mkdirFile: 'a/b/c/d/e/f/g/h/i/g/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/中文路径/张三/test', }) await btnMkdDirButton.tap() @@ -276,7 +281,7 @@ describe('ExtApi-FileManagerTest', () => { // 测试 创建包含中文特殊符号的目录 await page.setData({ recursiveVal: true, - mkdirFile:'a/'+ testDirName + '/中文路径/张三/name', + mkdirFile: 'a/' + testDirName + '/中文路径/张三/name', }) await btnMkdDirButton.tap() await isDone() @@ -298,8 +303,8 @@ describe('ExtApi-FileManagerTest', () => { */ await page.setData({ basePath: "", - readFile:'static/test-image/logo.ico', - readFileEncoding:'base64' + readFile: 'static/test-image/logo.ico', + readFileEncoding: 'base64' }) @@ -314,8 +319,8 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ basePath: globalTempPath, - writeFile:'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', - writeFileContent:readFileRet + writeFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', + writeFileContent: readFileRet }) @@ -325,9 +330,9 @@ describe('ExtApi-FileManagerTest', () => { // 获取文件列表,判断是否写入成功,同时置空base64内容 避免影响实时查看状态 await page.setData({ - readDir:'a/' + testDirName + '/中文路径/张三/name', - readFileRet:'', - writeFileContent:'' + readDir: 'a/' + testDirName + '/中文路径/张三/name', + readFileRet: '', + writeFileContent: '' }) // 检查目录列表数量 @@ -341,8 +346,8 @@ describe('ExtApi-FileManagerTest', () => { // 更换文件内容 获取和对比 文件md5和sha1 await page.setData({ - getFileInfoFile:'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', - getFileInfoAlgorithm:"md5", + getFileInfoFile: 'a/' + testDirName + '/中文路径/张三/name/中文文件.mock', + getFileInfoAlgorithm: "md5", }) const btnGetFileInfoButton = await page.$('#btn-get-file-info') @@ -356,7 +361,7 @@ describe('ExtApi-FileManagerTest', () => { // 切换为 sha1 await page.setData({ - getFileInfoAlgorithm:"sha1" + getFileInfoAlgorithm: "sha1" }) await btnGetFileInfoButton.tap() @@ -369,7 +374,7 @@ describe('ExtApi-FileManagerTest', () => { // 测试不支持的摘要算法,期望返回错误 await page.setData({ - getFileInfoAlgorithm:"sha256" + getFileInfoAlgorithm: "sha256" }) await btnGetFileInfoButton.tap() @@ -383,8 +388,8 @@ describe('ExtApi-FileManagerTest', () => { // rename 到一个没有提前创建过的目录,期望返回错误 await page.setData({ - renameFromFile:"a/" + testDirName + "/中文路径/张三/name/中文文件.mock", - renameToFile:"a/没有提前创建的目录/3.txt" + renameFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", + renameToFile: "a/没有提前创建的目录/3.txt" }) const btnRenameFileButton = await page.$('#btn-rename-file') @@ -399,14 +404,14 @@ describe('ExtApi-FileManagerTest', () => { // 非递归创建一级目录。期望成功 await page.setData({ recursiveVal: false, - mkdirFile:'a/提前创建的目录', + mkdirFile: 'a/提前创建的目录', }) await btnMkdDirButton.tap() await isDone() await page.setData({ - readDir:'a', + readDir: 'a', }) await btnReadDirButton.tap() @@ -421,16 +426,16 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ - copyFromFile:"a/" + testDirName + "/中文路径/张三/name/中文文件.mock", - copyToFile:"a/提前创建的目录/4.txt" + copyFromFile: "a/" + testDirName + "/中文路径/张三/name/中文文件.mock", + copyToFile: "a/提前创建的目录/4.txt" }) - const btnCopyFileButton = await page.$('#btn-copy-file') - await btnCopyFileButton.tap() - await isDone() + const btnCopyFileButton = await page.$('#btn-copy-file') + await btnCopyFileButton.tap() + await isDone() await page.setData({ - readDir:'a/提前创建的目录', + readDir: 'a/提前创建的目录', }) await btnReadDirButton.tap() @@ -442,8 +447,8 @@ describe('ExtApi-FileManagerTest', () => { expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]") await page.setData({ - unlinkFile:'a/提前创建的目录/4.txt', - rmDirFile:'a/提前创建的目录' + unlinkFile: 'a/提前创建的目录/4.txt', + rmDirFile: 'a/提前创建的目录' }) await btnUnLinkFileButton.tap() await isDone() @@ -467,13 +472,13 @@ describe('ExtApi-FileManagerTest', () => { let globalRootPath = await getData('globalRootPath') await page.setData({ recursiveVal: true, - logAble:false, + logAble: false, basePath: globalRootPath, - readDir:'a', - rmDirFile:'a', - mkdirFile:'a', - accessFile:'a/从代码目录拷贝的资源.png', - unlinkFile:'a/从代码目录拷贝的资源.png' + readDir: 'a', + rmDirFile: 'a', + mkdirFile: 'a', + accessFile: 'a/从代码目录拷贝的资源.png', + unlinkFile: 'a/从代码目录拷贝的资源.png' }) @@ -515,8 +520,8 @@ describe('ExtApi-FileManagerTest', () => { // 准备从资源目录拷贝png await page.setData({ basePath: "", - unlinkFile:'static/test-image/logo.ico', - accessFile:'static/test-image/logo.ico', + unlinkFile: 'static/test-image/logo.ico', + accessFile: 'static/test-image/logo.ico', }) // 检查资源文件,期望存在 await btnAccessFileButton.tap() @@ -537,9 +542,9 @@ describe('ExtApi-FileManagerTest', () => { expect(accessFileRet).toEqual('access:ok') // 复制资源到 root目录 await page.setData({ - copyToBasePath:globalRootPath, - copyFromFile:"static/test-image/logo.ico", - copyToFile:"a/从代码目录拷贝的资源.png" + copyToBasePath: globalRootPath, + copyFromFile: "static/test-image/logo.ico", + copyToFile: "a/从代码目录拷贝的资源.png" }) const btnCopyFileButton = await page.$('#btn-copy-file') await btnCopyFileButton.tap() @@ -547,10 +552,10 @@ describe('ExtApi-FileManagerTest', () => { // 检查期望 root 目录中图片文件存在 await page.setData({ - basePath:globalRootPath, - unlinkFile:'a/从代码目录拷贝的资源.png', - accessFile:'a/从代码目录拷贝的资源.png', - rmDirFile:'a', + basePath: globalRootPath, + unlinkFile: 'a/从代码目录拷贝的资源.png', + accessFile: 'a/从代码目录拷贝的资源.png', + rmDirFile: 'a', }) await btnAccessFileButton.tap() await isDone() @@ -602,19 +607,19 @@ describe('ExtApi-FileManagerTest', () => { let globalTempPath = await getData('globalTempPath') await page.setData({ recursiveVal: true, - logAble:false, + logAble: false, 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" + 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" }) // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 @@ -663,7 +668,7 @@ describe('ExtApi-FileManagerTest', () => { // 尝试读取base64 信息 await page.setData({ - readFileEncoding:"base64", + readFileEncoding: "base64", }) await btnReadFileButton.tap() @@ -673,9 +678,9 @@ describe('ExtApi-FileManagerTest', () => { // 测试ascii,需要特别测试 ascii 写入非法字符的情况,因为微信的常量字符编码和android原生有差异。 await page.setData({ - writeFileContent:"丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间", - writeFileEncoding:"ascii", - readFileEncoding:"base64", + writeFileContent: "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间", + writeFileEncoding: "ascii", + readFileEncoding: "base64", }) await btnWriteFileButton.tap() @@ -692,13 +697,15 @@ describe('ExtApi-FileManagerTest', () => { await btnReadFileButton.tap() await isDone() readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("GbAtywwibr7mDCeJDFxkxwx8AFAxAg4I4PYJH4pS7lIpAg3lKQqrGQzKFS9VdAIRMljOUrsMyFA8fImHDNgEDdzSAnceBAVxDFU8KLr0") + expect(readFileRet).toEqual( + "GbAtywwibr7mDCeJDFxkxwx8AFAxAg4I4PYJH4pS7lIpAg3lKQqrGQzKFS9VdAIRMljOUrsMyFA8fImHDNgEDdzSAnceBAVxDFU8KLr0" + ) // 尝试写入合法ascii await page.setData({ - writeFileContent:"hello jack.hello marry.", - writeFileEncoding:"ascii", - readFileEncoding:"ascii", + writeFileContent: "hello jack.hello marry.", + writeFileEncoding: "ascii", + readFileEncoding: "ascii", }) await btnWriteFileButton.tap() @@ -711,9 +718,9 @@ describe('ExtApi-FileManagerTest', () => { // 写入base64 获取 中文 await page.setData({ - writeFileContent:"5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0", - writeFileEncoding:"base64", - readFileEncoding:"utf-8", + writeFileContent: "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0", + writeFileEncoding: "base64", + readFileEncoding: "utf-8", }) await btnWriteFileButton.tap() @@ -722,16 +729,19 @@ describe('ExtApi-FileManagerTest', () => { await btnReadFileButton.tap() await isDone() readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间") + expect(readFileRet).toEqual( + "丙辰中秋,欢饮达旦,大醉,作此篇,兼怀子由。明月几时有?把酒问青天。不知天上宫阙,今夕是何年。我欲乘风归去,又恐琼楼玉宇,高处不胜寒。起舞弄清影,何似在人间") await page.setData({ - readFileEncoding:"base64", + readFileEncoding: "base64", }) await btnReadFileButton.tap() await isDone() readFileRet = await getData('readFileRet') - expect(readFileRet).toEqual("5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0") + expect(readFileRet).toEqual( + "5LiZ6L6w5Lit56eL77yM5qyi6aWu6L6+5pem77yM5aSn6YaJ77yM5L2c5q2k56+H77yM5YW85oCA5a2Q55Sx44CC5piO5pyI5Yeg5pe25pyJ77yf5oqK6YWS6Zeu6Z2S5aSp44CC5LiN55+l5aSp5LiK5a6r6ZiZ77yM5LuK5aSV5piv5L2V5bm044CC5oiR5qyy5LmY6aOO5b2S5Y6777yM5Y+I5oGQ55C85qW8546J5a6H77yM6auY5aSE5LiN6IOc5a+S44CC6LW36Iie5byE5riF5b2x77yM5L2V5Ly85Zyo5Lq66Ze0" + ) }); @@ -741,12 +751,12 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ recursiveVal: true, - copyToBasePath:globalRootPath, + copyToBasePath: globalRootPath, basePath: globalRootPath, - globalTempPath:globalRootPath, - rmDirFile:'a', - mkdirFile:'a', - unlinkFile:'a/1.txt', + globalTempPath: globalRootPath, + rmDirFile: 'a', + mkdirFile: 'a', + unlinkFile: 'a/1.txt', }) // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 @@ -755,13 +765,13 @@ describe('ExtApi-FileManagerTest', () => { await isDone() await page.setData({ - unlinkFile:'a/2.txt', + unlinkFile: 'a/2.txt', }) await btnUnLinkFileButton.tap() await isDone() await page.setData({ - unlinkFile:'a/m/3.txt', + unlinkFile: 'a/m/3.txt', }) await btnUnLinkFileButton.tap() await isDone() @@ -789,10 +799,10 @@ describe('ExtApi-FileManagerTest', () => { // 写入一个文件 await page.setData({ writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", - writeFileEncoding:"utf-8", - writeFile:'a/1.txt', - recursiveVal:false, - statFile:'a/1.txt', + writeFileEncoding: "utf-8", + writeFile: 'a/1.txt', + recursiveVal: false, + statFile: 'a/1.txt', }) let lastFailError = await getData('lastFailError') @@ -802,7 +812,7 @@ describe('ExtApi-FileManagerTest', () => { await btnWriteFileButton.tap() await isDone() - const btnStatFileButton = await page.$('#btn-stat-file') + let btnStatFileButton = await page.$('#btn-stat-file') await btnStatFileButton.tap() await isDone() @@ -812,17 +822,31 @@ describe('ExtApi-FileManagerTest', () => { expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) expect(statsRet[0].stats.size).toEqual(69) + // 写入一个文件 + await page.setData({ + statsRet: '' + }) + btnStatFileButton = await page.$('#btn-stat-file-sync') + await btnStatFileButton.tap() + await isDone() + + // 读取单个文件信息 + statsRet = await getData('statsRet') + expect(statsRet.length).toEqual(1) + expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) + expect(statsRet[0].stats.size).toEqual(69) + /** * 创建子目录和子目录文件,测试recursive参数 */ await page.setData({ writeFileContent: "1234567890", - writeFileEncoding:"ascii", - writeFile:'a/2.txt', + writeFileEncoding: "ascii", + writeFile: 'a/2.txt', basePath: globalRootPath, - recursiveVal:false, - statFile:'a', - mkdirFile:'a/m', + recursiveVal: false, + statFile: 'a', + mkdirFile: 'a/m', }) @@ -836,9 +860,9 @@ describe('ExtApi-FileManagerTest', () => { // 复制一份文件到 /a/m/3.txt await page.setData({ // asset 只能正式版测试,这里只能模拟返回路径 - basePath:'', - copyFromFile:'static/test-image/logo.ico', - copyToFile:'a/m/3.txt', + basePath: '', + copyFromFile: 'static/test-image/logo.ico', + copyToFile: 'a/m/3.txt', }) const btnCopyFileButton = await page.$('#btn-copy-file') await btnCopyFileButton.tap() @@ -847,8 +871,8 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ basePath: globalRootPath, - recursiveVal:true, - statFile:'a', + recursiveVal: true, + statFile: 'a', }) await btnStatFileButton.tap() @@ -857,10 +881,10 @@ describe('ExtApi-FileManagerTest', () => { // 读取全部文件信息 statsRet = await getData('statsRet') - statsRet.sort(function(a, b){ - if (a.path > b.path){ + statsRet.sort(function(a, b) { + if (a.path > b.path) { return 1 - } else if (a.path < b.path){ + } else if (a.path < b.path) { return -1 } return 0 @@ -879,22 +903,22 @@ describe('ExtApi-FileManagerTest', () => { // 清理文件,避免影响其他测试用例 await page.setData({ - unlinkFile:'a/1.txt', + unlinkFile: 'a/1.txt', }) await btnUnLinkFileButton.tap() await isDone() await page.setData({ - unlinkFile:'a/2.txt', + unlinkFile: 'a/2.txt', }) await btnUnLinkFileButton.tap() await isDone() await page.setData({ - unlinkFile:'a/m/3.txt', - rmDirFile:'a', - readDir:'a', - recursiveVal:true, + unlinkFile: 'a/m/3.txt', + rmDirFile: 'a', + readDir: 'a', + recursiveVal: true, }) await btnUnLinkFileButton.tap() await isDone() @@ -913,4 +937,363 @@ describe('ExtApi-FileManagerTest', () => { }); + it('appendFileTest', async () => { + await page.setData({ + recursiveVal: true, + logAble: false, + rmDirFile: 'appendfile', + mkdirFile: 'appendfile', + writeFileContent: "我爱北京天安门,天安门前太阳升", + appendFileContent: "再说一遍", + writeFileEncoding: "utf-8", + readFileEncoding: "utf-8", + readFile: 'appendfile/appendfile.txt', + unlinkFile: 'appendfile/appendfile.txt', + writeFile: 'appendfile/appendfile.txt', + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + 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() + + // // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file') + + await btnWriteFileButton.tap() + await isDone() + + + // //追加内容 + const btnAppendFileButton = await page.$('#btn-append-file') + await btnAppendFileButton.tap() + await isDone() + + const btnReadFileButton = await page.$('#btn-read-file') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍") + }); + //nlinkSyncTest mkdirSyncTest appendFileTest writeFileSyncTest readFileSyncTest rmdirSyncTest readDirSyncTest accessFileSyncTest + //renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest + it('sync test', + async () => { + await page.setData({ + recursiveVal: false, + logAble: false, + rmDirFile: 'sync', + mkdirFile: 'sync', + writeFileContent: "我爱北京天安门,天安门前太阳升", + appendFileContent: "再说一遍", + writeFileEncoding: "utf-8", + readFileEncoding: "utf-8", + readDir: 'sync', + rmDirFile: 'sync', + unlinkFile: 'sync/sync.txt', + readFile: 'sync/sync.txt', + writeFile: 'sync/sync.txt', + accessFile: 'sync/sync.txt', + renameToFile: 'sync/sync.txt', + renameFromFile: 'sync/sync.txt', + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('#btn-unlink-file-sync') + await btnUnLinkFileButton.tap() + await isDone() + + //清除文件夹 + const btnRmDirButton = await page.$('#btn-remove-dir-sync') + await btnRmDirButton.tap() + await isDone() + + + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 + const btnMkdDirButton = await page.$('#btn-mkdir-sync') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('#btn-read-dir-sync') + await btnReadDirButton.tap() + await isDone() + const fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file-sync') + await btnWriteFileButton.tap() + await isDone() + + let btnAccessFileButton = await page.$('#btn-access-file-sync') + await btnAccessFileButton.tap() + await isDone() + let accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + //重新命名文件 + const btnRenameFileButton = await page.$('#btn-rename-file-sync') + await btnRenameFileButton.tap() + await isDone() + let renameFileRet = await getData("renameFileRet") + expect(renameFileRet).toEqual("rename:ok") + + + //追加内容 + let btnAppendFileButton = await page.$('#btn-append-file') + await btnAppendFileButton.tap() + await isDone() + + btnAppendFileButton = await page.$('#btn-append-file-sync') + await btnAppendFileButton.tap() + + + let btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + let readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门,天安门前太阳升再说一遍再说一遍") + + //truncateFileTest + let btnTruncateFile = await page.$('#btn-truncate-file') + await btnTruncateFile.tap() + await isDone() + btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京天安门") + + btnTruncateFile = await page.$('#btn-truncate-file-sync') + await btnTruncateFile.tap() + await isDone() + btnReadFileButton = await page.$('#btn-read-file-sync') + await btnReadFileButton.tap() + await isDone() + readFileRet = await getData('readFileRet') + expect(readFileRet).toEqual("我爱北京") + + + // 测试 copyfile + await page.setData({ + copyFromFile: "sync/sync.txt", + copyToFile: "sync/syncto.txt", + accessFile: "sync/syncto.txt" + }) + const btnCopyFileButton = await page.$('#btn-copy-file-sync') + await btnCopyFileButton.tap() + await isDone() + btnAccessFileButton = await page.$('#btn-access-file-sync') + await btnAccessFileButton.tap() + await isDone() + accessFileRet = await getData("accessFileRet") + expect(accessFileRet).toEqual('access:ok') + + clearDir('sync') + }); + + async function createFile() { + // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 + const btnMkdDirButton = await page.$('#btn-mkdir-sync') + await btnMkdDirButton.tap() + await isDone() + + // 先用utf-8 写入内容 + const btnWriteFileButton = await page.$('#btn-write-file-sync') + await btnWriteFileButton.tap() + await isDone() + } + + async function clearDir(dir) { + // 最后需要清楚所有文件避免测试失败 + await page.setData({ + rmDirFile: dir, + }) + const btnClear = await page.$('#btn-clear-file') + await btnClear.tap() + await isDone() + } + //saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest + it('savefile test', + async () => { + let globalTempPath = await getData('globalTempPath') + let basePath = await getData('basePath') + await page.setData({ + basePath: basePath + }) + await clearDir('') + + + await page.setData({ + basePath: globalTempPath, + temFile: 'save/1.txt', + mkdirFile: 'save', + writeFile: 'save/1.txt', + accessFile: '1.txt' + }) + await createFile() + + + await page.setData({ + basePath: basePath, + temFile: 'save/1.txt', + }) + let btnSaveFile = await page.$('#btn-save-file') + await btnSaveFile.tap() + await isDone() + let saveFileRet = await getData("saveFileRet") + expect(saveFileRet).not.toBe(''); + await page.setData({ + saveFileRet: '' + }) + + + + await page.setData({ + basePath: globalTempPath, + temFile: 'save/2.txt', + mkdirFile: 'save', + writeFile: 'save/2.txt', + accessFile: '2.txt' + }) + await createFile() + await page.setData({ + basePath: basePath, + writeFile: 'save/2.txt', + }) + btnSaveFile = await page.$('#btn-save-file-sync') + await btnSaveFile.tap() + await isDone() + + let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') + await btnRemoveSavedFileRet.tap() + let removeSavedFileRet = await getData("removeSavedFileRet") + expect(removeSavedFileRet).toEqual('removeSavedFile:ok') + + await page.setData({ + removeSavedFileRet: '' + }) + + + let btnSavedFileList = await page.$('#btn-getsaved-filelist') + await btnSavedFileList.tap() + await isDone() + let fileListSuccess = await getData("fileListSuccess") + expect(fileListSuccess.length).toEqual(3) + + + + await clearDir('') + }); + + //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest + it('fd test', async () => { + await clearDir('') + await page.setData({ + mkdirFile: 'fd', + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt' + }) + await createFile() + //openFiletest + let btnOpenFile = await page.$('#btn-open-file') + await btnOpenFile.tap() + await isDone() + let fd = await getData("fd") + expect(fd).not.toBe(''); + await page.setData({ + fd: '', + }) + + //openFileSynctest + btnOpenFile = await page.$('#btn-open-file-sync') + await btnOpenFile.tap() + await isDone() + fd = await getData("fd") + expect(fd).not.toBe(''); + + + //closeTest + let btnCloseFile = await page.$('#btn-close-file') + await btnCloseFile.tap() + await isDone() + let closeFileRet = await getData("closeFileRet") + expect(closeFileRet).toEqual('close:ok') + await page.setData({ + closeFileRet: '', + }) + //closeTestSync + btnCloseFile = await page.$('#btn-close-file-sync') + await btnCloseFile.tap() + await isDone() + closeFileRet = await getData("closeFileRet") + expect(closeFileRet).toEqual('close:ok') + + //writeTest + await page.setData({ + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是一只小小鸟' + }) + + let btnWrite = await page.$('#btn-write') + await btnWrite.tap() + await isDone() + let bytesWritten = await getData("bytesWritten") + expect(bytesWritten).toEqual(7) + + //writeSyncTest + await page.setData({ + writeFile: 'fd/1.txt', + readFile: 'fd/1.txt', + writeData: '我是' + }) + + btnWrite = await page.$('#btn-write') + await btnWrite.tap() + await isDone() + bytesWritten = await getData("bytesWritten") + expect(bytesWritten).toEqual(2) + + //fstatTest + let btnFstat = await page.$('#btn-fstat-file') + await btnFstat.tap() + await isDone() + let fstat = await getData("fstat") + expect(fstat.size > 0).toBe(true) + + //fstatSyncTest + btnFstat = await page.$('#btn-fstat-file-sync') + await btnFstat.tap() + await isDone() + fstat = await getData("fstat") + expect(fstat.size > 0).toBe(true) + + //ftruncateFileTest + let btnFTruncateFile = await page.$('#btn-ftruncate-file') + await btnFTruncateFile.tap() + await isDone() + let ftruncateRet = await getData("ftruncateRet") + expect(fstat).not.toEqual('ftruncate:ok') + await page.setData({ + ftruncate: '', + }) + //ftruncateFileSyncTest + btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') + await btnFTruncateFile.tap() + await isDone() + ftruncateRet = await getData("ftruncateRet") + expect(fstat).not.toEqual('ftruncate:ok') + + }); }); diff --git a/pages/API/get-file-system-manager/get-file-system-manager.uvue b/pages/API/get-file-system-manager/get-file-system-manager.uvue index e17bfa8048484f9f2f84a95f9b523101e8774af7..815ba0067f56fa5cdfaab4bd3ea826cbd5e0ddbe 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.uvue +++ b/pages/API/get-file-system-manager/get-file-system-manager.uvue @@ -1,6 +1,6 @@