提交 482b642f 编写于 作者: 雪洛's avatar 雪洛

feat: 移除uniCloud相关测试例的page.waitFor(3000)

上级 e46c31f1
...@@ -12,7 +12,6 @@ describe('unicloud-call-function', () => { ...@@ -12,7 +12,6 @@ describe('unicloud-call-function', () => {
it('callFunction', async () => { it('callFunction', async () => {
await page.callMethod('callFunction') await page.callMethod('callFunction')
await page.waitFor(3000)
const { const {
callFunctionResult, callFunctionResult,
callFunctionError callFunctionError
......
...@@ -46,11 +46,11 @@ ...@@ -46,11 +46,11 @@
console.log(title, content) console.log(title, content)
} }
}, },
callFunction: function () { async callFunction () : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
uniCloud.callFunction({ await uniCloud.callFunction({
name: 'echo-cf', name: 'echo-cf',
data: { data: {
num: 1, num: 1,
......
...@@ -11,20 +11,13 @@ describe('unicloud-database', () => { ...@@ -11,20 +11,13 @@ describe('unicloud-database', () => {
}) })
it('databaseBasic', async () => { it('databaseBasic', async () => {
await page.callMethod('dbRemove') await page.callMethod('dbRemove')
await page.waitFor(3000)
await page.callMethod('dbAdd') await page.callMethod('dbAdd')
await page.waitFor(1500)
await page.callMethod('dbBatchAdd') await page.callMethod('dbBatchAdd')
await page.waitFor(1500)
await page.callMethod('dbGet') await page.callMethod('dbGet')
await page.waitFor(1500)
await page.callMethod('dbGetWithCommand') await page.callMethod('dbGetWithCommand')
await page.waitFor(1500)
await page.callMethod('dbUpdate') await page.callMethod('dbUpdate')
await page.waitFor(1500)
await page.callMethod('dbRemove') await page.callMethod('dbRemove')
await page.waitFor(1500)
const { const {
addId, addId,
batchAddIds, batchAddIds,
...@@ -34,7 +27,7 @@ describe('unicloud-database', () => { ...@@ -34,7 +27,7 @@ describe('unicloud-database', () => {
getWithCommandData, getWithCommandData,
removeDeleted, removeDeleted,
} = await page.data() } = await page.data()
expect(addId !== '').toBe(true) expect(addId !== '').toBe(true)
expect(batchAddIds.length).toBe(2) expect(batchAddIds.length).toBe(2)
expect(batchAddinserted).toBe(2) expect(batchAddinserted).toBe(2)
...@@ -42,15 +35,13 @@ describe('unicloud-database', () => { ...@@ -42,15 +35,13 @@ describe('unicloud-database', () => {
expect(getWithCommandData.length).toBe(1) expect(getWithCommandData.length).toBe(1)
expect(updateUpdated).toBe(3) expect(updateUpdated).toBe(3)
expect(removeDeleted).toBe(3) expect(removeDeleted).toBe(3)
}) })
it('databaseLookup', async () => { it('databaseLookup', async () => {
await page.callMethod('dbLookupInit') await page.callMethod('dbLookupInit')
await page.waitFor(3000)
await page.callMethod('dbLookup') await page.callMethod('dbLookup')
await page.waitFor(1500)
const { const {
lookupData lookupData
} = await page.data() } = await page.data()
...@@ -58,4 +49,4 @@ describe('unicloud-database', () => { ...@@ -58,4 +49,4 @@ describe('unicloud-database', () => {
expect(lookupData[0]['foreign_id'].length).toBe(1) expect(lookupData[0]['foreign_id'].length).toBe(1)
expect(lookupData[1]['foreign_id'].length).toBe(1) expect(lookupData[1]['foreign_id'].length).toBe(1)
}) })
}); });
\ No newline at end of file
...@@ -40,10 +40,15 @@ ...@@ -40,10 +40,15 @@
onLoad() { onLoad() {
}, },
onUnload() { onUnload() {
if(this.isUniTest){ if (this.isUniTest) {
uni.hideToast() uni.hideToast()
} }
}, },
computed: {
dataTag() : string {
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
}
},
methods: { methods: {
notify(content : string, title : string) { notify(content : string, title : string) {
if (!this.isUniTest) { if (!this.isUniTest) {
...@@ -56,18 +61,18 @@ ...@@ -56,18 +61,18 @@
uni.showToast({ uni.showToast({
title: content title: content
}) })
console.log(title, content) console.error(title, content)
} }
}, },
dbAdd: function () { async dbAdd() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.add({ .add({
num: 1, num: 1,
tag: 'default-tag', tag: this.dataTag,
date: new Date() date: new Date()
}) })
.then(res => { .then(res => {
...@@ -82,18 +87,18 @@ ...@@ -82,18 +87,18 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbBatchAdd() { async dbBatchAdd() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.add([{ .add([{
num: 2, num: 2,
tag: 'default-tag', tag: this.dataTag,
}, { }, {
num: 3, num: 3,
tag: 'default-tag', tag: this.dataTag,
}]) }])
.then((res) => { .then((res) => {
uni.hideLoading() uni.hideLoading()
...@@ -109,14 +114,14 @@ ...@@ -109,14 +114,14 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbGet() { async dbGet() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.where( .where(
'tag == "default-tag"' `tag == "${this.dataTag}"`
) )
.field('num, tag') .field('num, tag')
.orderBy('num desc') .orderBy('num desc')
...@@ -135,14 +140,15 @@ ...@@ -135,14 +140,15 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbGetWithCommand() { async dbGetWithCommand() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.where({ .where({
num: db.command.gt(1) num: db.command.gt(1),
tag: this.dataTag
}) })
.field('num, tag') .field('num, tag')
.orderBy('num desc') .orderBy('num desc')
...@@ -161,14 +167,14 @@ ...@@ -161,14 +167,14 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbUpdate() { async dbUpdate() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.where( .where(
'tag == "default-tag"' `tag == "${this.dataTag}"`
) )
.update({ .update({
num: 4 num: 4
...@@ -185,14 +191,14 @@ ...@@ -185,14 +191,14 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbRemove() { async dbRemove() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('type') await db.collection('type')
.where( .where(
'tag == "default-tag"' `tag == "${this.dataTag}"`
) )
.remove() .remove()
.then(res => { .then(res => {
...@@ -207,17 +213,17 @@ ...@@ -207,17 +213,17 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbLookupInit() { async dbLookupInit() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
db.collection('local') await db.collection('local')
.where('tag == "default-tag"') .where(`tag == "${this.dataTag}"`)
.remove() .remove()
.then(() : Promise<UniCloudDBRemoveResult> => { .then(() : Promise<UniCloudDBRemoveResult> => {
return db.collection('foreign') return db.collection('foreign')
.where('tag == "default-tag"') .where(`tag == "${this.dataTag}"`)
.remove() .remove()
}) })
.then(() : Promise<UniCloudDBBatchAddResult> => { .then(() : Promise<UniCloudDBBatchAddResult> => {
...@@ -225,12 +231,12 @@ ...@@ -225,12 +231,12 @@
.add([{ .add([{
id: "local_1", id: "local_1",
name: "local_1_name", name: "local_1_name",
tag: "default-tag", tag: this.dataTag,
foreign_id: "foreign_1" foreign_id: "foreign_1"
}, { }, {
id: "local_2", id: "local_2",
name: "local_2_name", name: "local_2_name",
tag: "default-tag", tag: this.dataTag,
foreign_id: "foreign_2" foreign_id: "foreign_2"
}]) }])
}) })
...@@ -239,11 +245,11 @@ ...@@ -239,11 +245,11 @@
.add([{ .add([{
id: "foreign_1", id: "foreign_1",
name: "foreign_1_name", name: "foreign_1_name",
tag: "default-tag" tag: this.dataTag
}, { }, {
id: "foreign_2", id: "foreign_2",
name: "foreign_2_name", name: "foreign_2_name",
tag: "default-tag" tag: this.dataTag
}]) }])
}) })
.then((_) : void => { .then((_) : void => {
...@@ -257,18 +263,18 @@ ...@@ -257,18 +263,18 @@
this.notify(error.errMsg, '错误') this.notify(error.errMsg, '错误')
}) })
}, },
dbLookup() { async dbLookup() : Promise<void> {
uni.showLoading({ uni.showLoading({
title: '加载中...' title: '加载中...'
}) })
const db = uniCloud.databaseForJQL() const db = uniCloud.databaseForJQL()
const local = db.collection('local') const local = db.collection('local')
.where('tag == "default-tag"') .where(`tag == "${this.dataTag}"`)
.getTemp() .getTemp()
const foreign = db.collection('foreign') const foreign = db.collection('foreign')
.where('tag == "default-tag"') .where(`tag == "${this.dataTag}"`)
.getTemp() .getTemp()
db.collection(local, foreign) await db.collection(local, foreign)
.get() .get()
.then(res => { .then(res => {
uni.hideLoading() uni.hideLoading()
......
...@@ -13,8 +13,7 @@ describe('unicloud-import-object', () => { ...@@ -13,8 +13,7 @@ describe('unicloud-import-object', () => {
await page.callMethod('addTodo') await page.callMethod('addTodo')
await page.callMethod('fail') await page.callMethod('fail')
await page.callMethod('success') await page.callMethod('success')
await page.waitFor(3000)
const { const {
todoTitle, todoTitle,
todoContent, todoContent,
...@@ -23,11 +22,11 @@ describe('unicloud-import-object', () => { ...@@ -23,11 +22,11 @@ describe('unicloud-import-object', () => {
failErrCode, failErrCode,
successErrCode, successErrCode,
} = await page.data() } = await page.data()
expect(returnTodoTitle).toBe(todoTitle) expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent) expect(returnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE') expect(failErrCode).toBe('TEST_ERROR_CODE')
expect(successErrCode).toBe(0) expect(successErrCode).toBe(0)
}) })
}); });
\ No newline at end of file
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
} }
}, },
onUnload() { onUnload() {
if(this.isUniTest){ if (this.isUniTest) {
uni.hideToast() uni.hideToast()
} }
}, },
...@@ -58,42 +58,42 @@ ...@@ -58,42 +58,42 @@
console.log(title, content) console.log(title, content)
} }
}, },
addTodo() { async addTodo() : Promise<void> {
const todo = uniCloud.importObject('todo', { const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest customUI: this.isUniTest
}) })
const title = this.todoTitle const title = this.todoTitle
const content = this.todoContent 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.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示') this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => { }).catch((err : any | null) => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
}) })
}, },
randomFail() { async randomFail() : Promise<void> {
const todoObj = uniCloud.importObject('todo', { const todoObj = uniCloud.importObject('todo', {
errorOptions: { errorOptions: {
retry: true retry: true
} }
}) })
todoObj.randomFail().then((res : UTSJSONObject) : void => { await todoObj.randomFail().then((res : UTSJSONObject) => {
this.notify(res['showMessage'] as string, '提示') this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => { }).catch((err : any | null) => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
}) })
}, },
fail() { async fail() {
const todo = uniCloud.importObject('todo', { const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest customUI: this.isUniTest
}) })
todo.fail().then((res : UTSJSONObject) : void => { await todo.fail().then((res : UTSJSONObject) => {
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误') this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
console.log('todo.fail: ', res); console.log('todo.fail: ', res);
}).catch((err : any | null) : void => { }).catch((err : any | null) => {
const error = err as UniCloudError const error = err as UniCloudError
this.failErrCode = error.errCode as string this.failErrCode = error.errCode as string
console.error(error) console.error(error)
...@@ -108,10 +108,10 @@ ...@@ -108,10 +108,10 @@
const todo = uniCloud.importObject('todo', { const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest customUI: this.isUniTest
}) })
todo.success().then((res : UTSJSONObject) : void => { todo.success().then((res : UTSJSONObject) => {
this.successErrCode = res['errCode'] as number this.successErrCode = res['errCode'] as number
this.notify(res['showMessage'] as string, '提示') this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => { }).catch((err : any | null) => {
const error = err as UniCloudError const error = err as UniCloudError
console.error(error) console.error(error)
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册