提交 11a92737 编写于 作者: W WOSHIMAHAIFENG

修改file测试用例,防止ios测试失败

上级 5a5371a9
...@@ -1137,15 +1137,11 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1137,15 +1137,11 @@ describe('ExtApi-FileManagerTest', () => {
function isAndroid() { function isAndroid() {
if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') { if (process.env.uniTestPlatformInfo.indexOf('web') > -1 || process.env.UNI_AUTOMATOR_APP_WEBVIEW === 'true') {
it('web', () => {
expect(1).toBe(1) expect(1).toBe(1)
})
return false return false
} }
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) { if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
it('ios', () => {
expect(1).toBe(1) expect(1).toBe(1)
})
return false return false
} }
return true return true
...@@ -1247,7 +1243,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1247,7 +1243,7 @@ describe('ExtApi-FileManagerTest', () => {
logAble: false, logAble: false,
basePath: basePath basePath: basePath
}) })
await clearDir('') // await clearDir('')
await page.setData({ await page.setData({
logAble: false, logAble: false,
basePath: globalTempPath, basePath: globalTempPath,
...@@ -1341,7 +1337,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1341,7 +1337,7 @@ describe('ExtApi-FileManagerTest', () => {
if (!isAndroid()) { if (!isAndroid()) {
return return
} }
console.log('writeTest', 'start')
// await clearDir('') // await clearDir('')
await page.setData({ await page.setData({
logAble: false, logAble: false,
...@@ -1351,13 +1347,13 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1351,13 +1347,13 @@ describe('ExtApi-FileManagerTest', () => {
writeData: '我是一只小小鸟' writeData: '我是一只小小鸟'
}) })
await createFile() await createFile()
console.log('writeTest', '1')
let btnWrite = await page.$('#btn-write') let btnWrite = await page.$('#btn-write')
await btnWrite.tap() await btnWrite.tap()
await isDone() await isDone()
let bytesWritten = await getData("bytesWritten") let bytesWritten = await getData("bytesWritten")
expect(bytesWritten).toEqual(7) expect(bytesWritten).toEqual(7)
console.log('writeTest', '2')
//writeSyncTest //writeSyncTest
await page.setData({ await page.setData({
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
...@@ -1365,18 +1361,19 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1365,18 +1361,19 @@ describe('ExtApi-FileManagerTest', () => {
writeData: '我是' writeData: '我是'
}) })
btnWrite = await page.$('#btn-write') btnWrite = await page.$('#btn-write-sync')
await btnWrite.tap() await btnWrite.tap()
await isDone() await isDone()
bytesWritten = await getData("bytesWritten") bytesWritten = await getData("bytesWritten")
expect(bytesWritten).toEqual(2) expect(bytesWritten).toEqual(2)
console.log('writeTest', '3')
//fstatTest //fstatTest
let btnFstat = await page.$('#btn-fstat-file') let btnFstat = await page.$('#btn-fstat-file')
await btnFstat.tap() await btnFstat.tap()
await isDone() await isDone()
let fstat = await getData("fstat") let fstat = await getData("fstat")
expect(fstat.size > 0).toBe(true) expect(fstat.size > 0).toBe(true)
console.log('writeTest', '4')
//fstatSyncTest //fstatSyncTest
btnFstat = await page.$('#btn-fstat-file-sync') btnFstat = await page.$('#btn-fstat-file-sync')
...@@ -1384,6 +1381,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1384,6 +1381,7 @@ describe('ExtApi-FileManagerTest', () => {
await isDone() await isDone()
fstat = await getData("fstat") fstat = await getData("fstat")
expect(fstat.size > 0).toBe(true) expect(fstat.size > 0).toBe(true)
console.log('writeTest', '5')
//ftruncateFileTest //ftruncateFileTest
let btnFTruncateFile = await page.$('#btn-ftruncate-file') let btnFTruncateFile = await page.$('#btn-ftruncate-file')
...@@ -1394,15 +1392,57 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1394,15 +1392,57 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({ await page.setData({
ftruncate: '', ftruncate: '',
}) })
console.log('writeTest', '6')
//ftruncateFileSyncTest //ftruncateFileSyncTest
btnFTruncateFile = await page.$('#btn-ftruncate-file-sync') btnFTruncateFile = await page.$('#btn-ftruncate-file-sync')
await btnFTruncateFile.tap() await btnFTruncateFile.tap()
await isDone() await isDone()
ftruncateRet = await getData("ftruncateRet") ftruncateRet = await getData("ftruncateRet")
expect(fstat).not.toEqual('ftruncate:ok') expect(fstat).not.toEqual('ftruncate:ok')
console.log('writeTest', '7')
}); });
//writeTest writeSyncTest
it('ftruncateFileTest', async () => {
if (!isAndroid()) {
return
}
console.log('ftruncateFileTest', 'start')
// await clearDir('')
await page.setData({
logAble: false,
mkdirFile: 'fd',
writeFile: 'fd/1.txt',
readFile: 'fd/1.txt',
writeData: '我是一只小小鸟我是'
})
await createFile()
console.log('ftruncateFileTest', '1')
btnWrite = await page.$('#btn-write-sync')
await btnWrite.tap()
await isDone()
bytesWritten = await getData("bytesWritten")
expect(bytesWritten).toEqual(9)
console.log('ftruncateFileTest', '3')
//ftruncateFileTest
let btnFTruncateFile = await page.$('#btn-ftruncate-file')
await btnFTruncateFile.tap()
await isDone()
let ftruncateRet = await getData("ftruncateRet")
expect(ftruncateRet).toEqual('ftruncate:ok')
await page.setData({
ftruncate: '',
})
console.log('ftruncateFileTest', '6')
//ftruncateFileSyncTest
btnFTruncateFile = await page.$('#btn-ftruncate-file-sync')
await btnFTruncateFile.tap()
await isDone()
ftruncateRet = await getData("ftruncateRet")
expect(ftruncateRet).toEqual('ftruncate:ok')
console.log('ftruncateFileTest', '7')
});
//saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest //saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest
it('savefile test', it('savefile test',
async () => { async () => {
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<button class="btnstyle" type="primary" @tap="closeSyncTest" <button class="btnstyle" type="primary" @tap="closeSyncTest"
id="btn-close-file-sync">通过文件描述符同步关闭文件{{readFile}}</button> id="btn-close-file-sync">通过文件描述符同步关闭文件{{readFile}}</button>
<button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button> <button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button>
<button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-read-file">同步通过文件描述符写入文件{{readFile}}</button> <button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-write-sync">同步通过文件描述符写入文件{{readFile}}</button>
<button class="btnstyle" type="primary" @tap="fstatTest" id="btn-fstat-file">通过文件描述符获取{{statFile}}的状态信息</button> <button class="btnstyle" type="primary" @tap="fstatTest" id="btn-fstat-file">通过文件描述符获取{{statFile}}的状态信息</button>
<button class="btnstyle" type="primary" @tap="fstatSyncTest" <button class="btnstyle" type="primary" @tap="fstatSyncTest"
id="btn-fstat-file-sync">同步通过文件描述符获取{{statFile}}的状态信息</button> id="btn-fstat-file-sync">同步通过文件描述符获取{{statFile}}的状态信息</button>
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
fstat: null as Stats | null, fstat: null as Stats | null,
ftruncateRet: '', ftruncateRet: '',
readZipFile: 'to.zip', readZipFile: 'to.zip',
getSavedFileListRet:'', getSavedFileListRet: '',
/** /**
* 待测试的全局环境变量 * 待测试的全局环境变量
*/ */
...@@ -1007,19 +1007,10 @@ ...@@ -1007,19 +1007,10 @@
closeSyncTest() { closeSyncTest() {
console.log('closeSyncTest') console.log('closeSyncTest')
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.open({
filePath: `${this.basePath}${this.readFile}`,
flag: "r+",
success: (res : OpenFileSuccessResult) => {
console.log("success", res)
if (res.fd.length <= 0) {
this.done = true
return
}
try { try {
console.log('closeSync') console.log('closeSync')
fileManager.closeSync({ fileManager.closeSync({
fd: res.fd fd: this.openFileSyncTest()
} as CloseSyncOptions) } as CloseSyncOptions)
if (this.logAble) { if (this.logAble) {
this.log += 'closeSyncTest success:' + '\n\n' this.log += 'closeSyncTest success:' + '\n\n'
...@@ -1033,32 +1024,11 @@ ...@@ -1033,32 +1024,11 @@
console.log('fail', e) console.log('fail', e)
this.done = true this.done = true
} }
},
fail: (res : UniError) => {
if (this.logAble) {
this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
this.done = true
}
} as OpenFileOptions)
}, },
closeTest() { closeTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.open({
filePath: `${this.basePath}${this.readFile}`,
flag: "r+",
success: (res : OpenFileSuccessResult) => {
console.log("success", res)
if (res.fd.length <= 0) {
this.done = true
return
}
fileManager.close({ fileManager.close({
fd: res.fd, fd: this.openFileSyncTest(),
success: (res : FileManagerSuccessResult) => { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n' this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
...@@ -1079,16 +1049,6 @@ ...@@ -1079,16 +1049,6 @@
} as CloseOptions) } as CloseOptions)
}, },
fail: (res : UniError) => {
if (this.logAble) {
this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
}
console.log('fail', res)
this.lastFailError = res
this.done = true
}
} as OpenFileOptions)
},
writeTest() { writeTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.open({ fileManager.open({
...@@ -1257,7 +1217,7 @@ ...@@ -1257,7 +1217,7 @@
this.log += 'ftruncateFileSyncTest success:' + '\n\n' this.log += 'ftruncateFileSyncTest success:' + '\n\n'
} }
this.done = true this.done = true
this.ftruncateRet = '' this.ftruncateRet = 'ftruncate:ok'
} catch (e) { } catch (e) {
if (this.logAble) { if (this.logAble) {
this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n' this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册