1const t = require('tap') 2const tmock = require('../../fixtures/tmock') 3 4const webAuthCheckLogin = async () => { 5 return { token: 'otp-token' } 6} 7 8const webauth = tmock(t, '{LIB}/utils/web-auth.js', { 9 'npm-profile': { webAuthCheckLogin }, 10}) 11 12const initialUrl = 'https://example.com/auth' 13const doneUrl = 'https://example.com/done' 14const opts = {} 15 16t.test('returns token on success', async (t) => { 17 const opener = async () => {} 18 const result = await webauth(opener, initialUrl, doneUrl, opts) 19 t.equal(result, 'otp-token') 20}) 21 22t.test('closes opener when auth check finishes', async (t) => { 23 const opener = (_url, emitter) => { 24 return new Promise((resolve, reject) => { 25 // the only way to finish this promise is to emit aboter on the emitter 26 emitter.addListener('abort', () => { 27 resolve() 28 }) 29 }) 30 } 31 const result = await webauth(opener, initialUrl, doneUrl, opts) 32 t.equal(result, 'otp-token') 33}) 34