From 9c66d5c6dc14f0f9f9f973a92847dc2f53ef271e Mon Sep 17 00:00:00 2001 From: duqingquan Date: Fri, 8 Dec 2023 18:15:37 +0800 Subject: [PATCH] =?UTF-8?q?get-file-system-manager=20=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ger.js => get-file-system-manager.test.js} | 96 ++++++++++++++++++- .../get-file-system-manager.uvue | 27 ++++++ 2 files changed, 122 insertions(+), 1 deletion(-) rename pages/API/get-file-system-manager/{get-file-system-manager.js => get-file-system-manager.test.js} (89%) diff --git a/pages/API/get-file-system-manager/get-file-system-manager.js b/pages/API/get-file-system-manager/get-file-system-manager.test.js similarity index 89% rename from pages/API/get-file-system-manager/get-file-system-manager.js rename to pages/API/get-file-system-manager/get-file-system-manager.test.js index 814eff2e..956e34b6 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.js +++ b/pages/API/get-file-system-manager/get-file-system-manager.test.js @@ -1,4 +1,4 @@ -const PAGE_PATH = '/pages/API/filemanager/filemanager' +const PAGE_PATH = '/pages/API/get-file-system-manager/get-file-system-manager' describe('ExtApi-FileManagerTest', () => { @@ -700,4 +700,98 @@ describe('ExtApi-FileManagerTest', () => { }); +// it('stat and asset test', async () => { +// // 测试 USER_DATA_PATH +// let globalInnerRootPath = await getData('globalInnerRootPath') + +// await page.setData({ +// recursiveVal: true, +// copyToBasePath:globalInnerRootPath, +// basePath: globalInnerRootPath, +// rmDirFile:'a', +// mkdirFile:'a', +// unlinkFile:'a/1.txt', +// }) + +// // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 +// const btnUnLinkFileButton = await page.$('.btn-unlink-file') +// await btnUnLinkFileButton.tap() +// await isDone() + +// await page.setData({ +// unlinkFile:'a/2.txt', +// }) +// await btnUnLinkFileButton.tap() +// await isDone() + +// await page.setData({ +// unlinkFile:'a/m/3.txt', +// }) +// await btnUnLinkFileButton.tap() +// await isDone() + +// // // 清除文件夹 +// const btnRmDirButton = await page.$('.btn-remove-dir') +// await btnRmDirButton.tap() +// await isDone() +// // // 重新创建测试目录 +// const btnMkdDirButton = await page.$('.btn-mkdir') +// await btnMkdDirButton.tap() +// await isDone() + +// const btnReadDirButton = await page.$('.btn-read-dir') +// await btnReadDirButton.tap() +// await isDone() + + +// // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 +// let fileListComplete = await getData('fileListComplete') +// expect(JSON.stringify(fileListComplete)).toEqual('[]') +// let fileListSuccess = await getData('fileListSuccess') +// expect(JSON.stringify(fileListSuccess)).toEqual('[]') + +// // 写入一个文件 +// await page.setData({ +// writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", +// writeFileEncoding:"utf-8", +// writeFile:'a/1.txt', +// recursiveVal:false, +// statFile:'a/1.txt', +// }) + + + +// let lastFailError = await getData('lastFailError') +// console.log(lastFailError) + +// // const btnWriteFileButton = await page.$('.btn-write-file') +// // await btnWriteFileButton.tap() +// // await isDone() + +// // const btnStatFileButton = await page.$('.btn-stat-file') +// // await btnStatFileButton.tap() +// // await isDone() + +// // // 读取单个文件信息 +// // let statsRet = await getData('statsRet') +// // console.log(statsRet) +// // expect(statsRet.path).toEqual('') + +// // await page.setData({ +// // recursiveVal:true, +// // statFile:'a/1.txt', +// // }) + +// // await btnStatFileButton.tap() +// // await isDone() + +// // // 读取单个文件信息 +// // statsRet = await getData('statsRet') +// // console.log(statsRet) +// // expect(statsRet.path).toEqual('') + + + +// }); + }); 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 625093b0..d4d78335 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 @@ -11,6 +11,7 @@ + @@ -40,6 +41,7 @@ renameFromFile:'a/2.txt', renameToFile:'a/3.txt', getFileInfoFile:'a/1.txt', + statFile:'a/1.txt', rmDirFile:'a', mkdirFile:'a', readFile:'a/1.txt', @@ -47,6 +49,7 @@ done: false, writeFileEncoding:"utf-8", readFileEncoding:"utf-8", + statsRet:[] as Array, /** * 待测试的全局环境变量 */ @@ -65,6 +68,30 @@ methods: { + statFileInfoTest:function(e:any){ + let fileManager = uni.getFileSystemManager() + + fileManager.stat({ + path:`${this.basePath}${this.statFile}`, + recursive:this.recursiveVal, + success:function(res:StatSuccessResult){ + console.log('success',res) + this.statsRet = res.stats + console.log('this.statsRet',this.statsRet) + }, + fail:function(res:any){ + console.log('fail',res) + this.lastFailError = res + }, + complete:function(res:any){ + console.log("complete",res) + this.done = true + if(res instanceof UniError){ + this.lastCompleteError = res + } + } + } as StatOptions) + }, getFileInfoTest:function(e:any){ let fileManager = uni.getFileSystemManager() -- GitLab