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 c8f4c83bbac6fbba71d1776d78fa050eb4f356b4..82e6471a817730ca872ee95c0af5d7fbed124780 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 @@ -116,9 +116,11 @@ describe('ExtApi-FileManagerTest', () => { await btnReadDirButton.tap() await isDone() fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\"]") + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"b\"]") // 获取和对比 文件内容 const btnReadFileButton = await page.$('#btn-read-file') await btnReadFileButton.tap() @@ -176,9 +178,11 @@ describe('ExtApi-FileManagerTest', () => { // 1.txt 2.txt 两个文件都存在 fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]") + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") // 测试 rename await page.setData({ @@ -195,10 +199,11 @@ describe('ExtApi-FileManagerTest', () => { // 1.txt 3.txt 两个文件都存在 fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]") - + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") }); it('TEMP_PATH test', async () => { @@ -281,8 +286,10 @@ describe('ExtApi-FileManagerTest', () => { // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 fileListComplete = await getData('fileListComplete') + fileListComplete.sort() expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\"]") fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\"]") /** @@ -406,13 +413,14 @@ describe('ExtApi-FileManagerTest', () => { await isDone() fileListComplete = await getData('fileListComplete') + fileListComplete.sort() expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") await page.setData({ - copyFromFile:"a/" + testDirName + "/中文路径/张三/name/中文文件.mock", copyToFile:"a/提前创建的目录/4.txt" }) @@ -800,7 +808,7 @@ describe('ExtApi-FileManagerTest', () => { // 读取单个文件信息 let statsRet = await getData('statsRet') expect(statsRet.length).toEqual(1) - expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/1.txt')) + expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) expect(statsRet[0].stats.size).toEqual(69) /** @@ -828,7 +836,7 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ // asset 只能正式版测试,这里只能模拟返回路径 basePath:'', - copyFromFile:'file:///android_asset/uni-uts/uni-prompt/toast_error.png', + copyFromFile:'static/test-image/logo.ico', copyToFile:'a/m/3.txt', }) const btnCopyFileButton = await page.$('#btn-copy-file') @@ -847,16 +855,25 @@ describe('ExtApi-FileManagerTest', () => { // 读取全部文件信息 statsRet = await getData('statsRet') + + statsRet.sort(function(a, b){ + if (a.path > b.path){ + return 1 + } else if (a.path < b.path){ + return -1 + } + return 0 + }) console.log(statsRet) expect(statsRet.length).toEqual(5) - expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a')) - expect(statsRet[0].stats.size).toEqual(0) + expect(statsRet[0].path).toMatch(new RegExp('.*/a$')) + // expect(statsRet[0].stats.size).toEqual(0) - expect(statsRet[2].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/2.txt')) + expect(statsRet[2].path).toMatch(new RegExp('.*/a/2.txt$')) expect(statsRet[2].stats.size).toEqual(10) - expect(statsRet[4].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/m/3.txt')) - expect(statsRet[4].stats.size).toEqual(5842) + expect(statsRet[4].path).toMatch(new RegExp('.*/a/m/3.txt$')) + expect(statsRet[4].stats.size).toEqual(156406) // 清理文件,避免影响其他测试用例