wechaty / puppet-whatsapp

Wechaty Puppet for Whatsapp
https://npmjs.com/package/wechaty-puppet-whatsapp
Apache License 2.0
24 stars 17 forks source link

Fix memory card #337

Closed hcfw007 closed 2 years ago

hcfw007 commented 2 years ago

336

hcfw007 commented 2 years ago

@huan I trined a new way to handle async test this time, is this kinda async/await style you mentioned?

huan commented 2 years ago

is this kinda async/await style you mentioned?

No, it's not the async/await style. It's still the callback style.

Instead of (callback style)

await puppet.start()
    .then(() => {
      t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')
      t.pass('memory test pass')
      return null
    })
    .catch(async e => {
      await puppet.stop()
      t.fail(`cannot start puppet due to ${e as any}`)
    })

The async/await style should be:

try {
  await puppet.start()
  t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')
  t.pass('memory test pass')
} catch (e) {
  await puppet.stop()
  t.fail(`cannot start puppet due to ${e as any}`)
}
hcfw007 commented 2 years ago

after await puppet.start(), puppet.stop() will be called, does this affect puppet's state?

huan commented 2 years ago

start/stop of course will affect the state.

What's the state in your context?

hcfw007 commented 2 years ago

I mean if I wrote

puppet.on('scan', () => {puppet.stop()}
await puppet.start()
t.ok((puppet.memory as any).payload !== undefined, 'memory is loaded')

will this puppet.memory.payload effected by puppet.stop()?

huan commented 2 years ago

I'm not sure about it.

My suggestion would be just write a unit test to confirm the behavior and make sure it's what you are expecting.