diff --git a/pages/API/unicloud-call-function/unicloud-call-function.test.js b/pages/API/unicloud-call-function/unicloud-call-function.test.js index ebfa88871fdbb632642047d8ba5ee8d73a796d3d..d6716a12a9823b1798b308d6ee8b1d92ff5fd4c3 100644 --- a/pages/API/unicloud-call-function/unicloud-call-function.test.js +++ b/pages/API/unicloud-call-function/unicloud-call-function.test.js @@ -12,7 +12,6 @@ describe('unicloud-call-function', () => { it('callFunction', async () => { await page.callMethod('callFunction') - await page.waitFor(3000) const { callFunctionResult, callFunctionError diff --git a/pages/API/unicloud-call-function/unicloud-call-function.uvue b/pages/API/unicloud-call-function/unicloud-call-function.uvue index 8fe004a94dcbf8719538903337aedd0808964973..77395a1594ddbd7f803c5f57b975ce227611b478 100644 --- a/pages/API/unicloud-call-function/unicloud-call-function.uvue +++ b/pages/API/unicloud-call-function/unicloud-call-function.uvue @@ -46,11 +46,11 @@ console.log(title, content) } }, - callFunction: function () { + async callFunction () : Promise { uni.showLoading({ title: '加载中...' }) - uniCloud.callFunction({ + await uniCloud.callFunction({ name: 'echo-cf', data: { num: 1, diff --git a/pages/API/unicloud-database/unicloud-database.test.js b/pages/API/unicloud-database/unicloud-database.test.js index f3ebac830c54ce0bf1c0b87d1c82838d13f4141f..80855554214ae8f9c53506ab411ba8ddcbe35334 100644 --- a/pages/API/unicloud-database/unicloud-database.test.js +++ b/pages/API/unicloud-database/unicloud-database.test.js @@ -11,20 +11,13 @@ describe('unicloud-database', () => { }) it('databaseBasic', async () => { await page.callMethod('dbRemove') - await page.waitFor(3000) await page.callMethod('dbAdd') - await page.waitFor(1500) await page.callMethod('dbBatchAdd') - await page.waitFor(1500) await page.callMethod('dbGet') - await page.waitFor(1500) await page.callMethod('dbGetWithCommand') - await page.waitFor(1500) await page.callMethod('dbUpdate') - await page.waitFor(1500) await page.callMethod('dbRemove') - await page.waitFor(1500) - + const { addId, batchAddIds, @@ -34,7 +27,7 @@ describe('unicloud-database', () => { getWithCommandData, removeDeleted, } = await page.data() - + expect(addId !== '').toBe(true) expect(batchAddIds.length).toBe(2) expect(batchAddinserted).toBe(2) @@ -42,15 +35,13 @@ describe('unicloud-database', () => { expect(getWithCommandData.length).toBe(1) expect(updateUpdated).toBe(3) expect(removeDeleted).toBe(3) - + }) - + it('databaseLookup', async () => { await page.callMethod('dbLookupInit') - await page.waitFor(3000) await page.callMethod('dbLookup') - await page.waitFor(1500) - + const { lookupData } = await page.data() @@ -58,4 +49,4 @@ describe('unicloud-database', () => { expect(lookupData[0]['foreign_id'].length).toBe(1) expect(lookupData[1]['foreign_id'].length).toBe(1) }) -}); \ No newline at end of file +}); diff --git a/pages/API/unicloud-database/unicloud-database.uvue b/pages/API/unicloud-database/unicloud-database.uvue index 03d7344dab631e207a1985b874c0b3ac13f91cec..8856a206f3e27e63d6195efbaa41005e304ce6fa 100644 --- a/pages/API/unicloud-database/unicloud-database.uvue +++ b/pages/API/unicloud-database/unicloud-database.uvue @@ -40,10 +40,15 @@ onLoad() { }, onUnload() { - if(this.isUniTest){ + if (this.isUniTest) { uni.hideToast() } }, + computed: { + dataTag() : string { + return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag' + } + }, methods: { notify(content : string, title : string) { if (!this.isUniTest) { @@ -56,18 +61,18 @@ uni.showToast({ title: content }) - console.log(title, content) + console.error(title, content) } }, - dbAdd: function () { + async dbAdd() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .add({ num: 1, - tag: 'default-tag', + tag: this.dataTag, date: new Date() }) .then(res => { @@ -82,18 +87,18 @@ this.notify(error.errMsg, '错误') }) }, - dbBatchAdd() { + async dbBatchAdd() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .add([{ num: 2, - tag: 'default-tag', + tag: this.dataTag, }, { num: 3, - tag: 'default-tag', + tag: this.dataTag, }]) .then((res) => { uni.hideLoading() @@ -109,14 +114,14 @@ this.notify(error.errMsg, '错误') }) }, - dbGet() { + async dbGet() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .field('num, tag') .orderBy('num desc') @@ -135,14 +140,15 @@ this.notify(error.errMsg, '错误') }) }, - dbGetWithCommand() { + async dbGetWithCommand() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where({ - num: db.command.gt(1) + num: db.command.gt(1), + tag: this.dataTag }) .field('num, tag') .orderBy('num desc') @@ -161,14 +167,14 @@ this.notify(error.errMsg, '错误') }) }, - dbUpdate() { + async dbUpdate() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .update({ num: 4 @@ -185,14 +191,14 @@ this.notify(error.errMsg, '错误') }) }, - dbRemove() { + async dbRemove() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('type') + await db.collection('type') .where( - 'tag == "default-tag"' + `tag == "${this.dataTag}"` ) .remove() .then(res => { @@ -207,17 +213,17 @@ this.notify(error.errMsg, '错误') }) }, - dbLookupInit() { + async dbLookupInit() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() - db.collection('local') - .where('tag == "default-tag"') + await db.collection('local') + .where(`tag == "${this.dataTag}"`) .remove() .then(() : Promise => { return db.collection('foreign') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .remove() }) .then(() : Promise => { @@ -225,12 +231,12 @@ .add([{ id: "local_1", name: "local_1_name", - tag: "default-tag", + tag: this.dataTag, foreign_id: "foreign_1" }, { id: "local_2", name: "local_2_name", - tag: "default-tag", + tag: this.dataTag, foreign_id: "foreign_2" }]) }) @@ -239,11 +245,11 @@ .add([{ id: "foreign_1", name: "foreign_1_name", - tag: "default-tag" + tag: this.dataTag }, { id: "foreign_2", name: "foreign_2_name", - tag: "default-tag" + tag: this.dataTag }]) }) .then((_) : void => { @@ -257,18 +263,18 @@ this.notify(error.errMsg, '错误') }) }, - dbLookup() { + async dbLookup() : Promise { uni.showLoading({ title: '加载中...' }) const db = uniCloud.databaseForJQL() const local = db.collection('local') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .getTemp() const foreign = db.collection('foreign') - .where('tag == "default-tag"') + .where(`tag == "${this.dataTag}"`) .getTemp() - db.collection(local, foreign) + await db.collection(local, foreign) .get() .then(res => { uni.hideLoading() diff --git a/pages/API/unicloud-import-object/unicloud-import-object.test.js b/pages/API/unicloud-import-object/unicloud-import-object.test.js index 5c53f2179314937ae5eb8177cd8e428a93a1e10e..5e8662bdad80ac85c2ea0331a69d39a4032ee8ad 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.test.js +++ b/pages/API/unicloud-import-object/unicloud-import-object.test.js @@ -13,8 +13,7 @@ describe('unicloud-import-object', () => { await page.callMethod('addTodo') await page.callMethod('fail') await page.callMethod('success') - await page.waitFor(3000) - + const { todoTitle, todoContent, @@ -23,11 +22,11 @@ describe('unicloud-import-object', () => { failErrCode, successErrCode, } = await page.data() - + expect(returnTodoTitle).toBe(todoTitle) expect(returnTodoContent).toBe(todoContent) expect(failErrCode).toBe('TEST_ERROR_CODE') expect(successErrCode).toBe(0) - + }) -}); \ No newline at end of file +}); diff --git a/pages/API/unicloud-import-object/unicloud-import-object.uvue b/pages/API/unicloud-import-object/unicloud-import-object.uvue index f4fb9a874d0eb81ac5b16b9e55d7c544dd97237d..02ebdb13ff2804446f96d8ff940972056cbd746a 100644 --- a/pages/API/unicloud-import-object/unicloud-import-object.uvue +++ b/pages/API/unicloud-import-object/unicloud-import-object.uvue @@ -39,7 +39,7 @@ } }, onUnload() { - if(this.isUniTest){ + if (this.isUniTest) { uni.hideToast() } }, @@ -58,42 +58,42 @@ console.log(title, content) } }, - addTodo() { + async addTodo() : Promise { const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) const title = this.todoTitle const content = this.todoContent - todo.add(title, content).then((res : UTSJSONObject) : void => { + await todo.add(title, content).then((res : UTSJSONObject) => { this.returnTodoTitle = res['title'] as string this.returnTodoContent = res['content'] as string this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) }) }, - randomFail() { + async randomFail() : Promise { const todoObj = uniCloud.importObject('todo', { errorOptions: { retry: true } }) - todoObj.randomFail().then((res : UTSJSONObject) : void => { + await todoObj.randomFail().then((res : UTSJSONObject) => { this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) }) }, - fail() { + async fail() { const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) - todo.fail().then((res : UTSJSONObject) : void => { + await todo.fail().then((res : UTSJSONObject) => { this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误') console.log('todo.fail: ', res); - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError this.failErrCode = error.errCode as string console.error(error) @@ -108,10 +108,10 @@ const todo = uniCloud.importObject('todo', { customUI: this.isUniTest }) - todo.success().then((res : UTSJSONObject) : void => { + todo.success().then((res : UTSJSONObject) => { this.successErrCode = res['errCode'] as number this.notify(res['showMessage'] as string, '提示') - }).catch((err : any | null) : void => { + }).catch((err : any | null) => { const error = err as UniCloudError console.error(error) })