Skip to content

Commit

Permalink
test: Ditch done() promise
Browse files Browse the repository at this point in the history
  • Loading branch information
simnalamburt committed Feb 5, 2025
1 parent 75a27b2 commit 9ac20fd
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 473 deletions.
20 changes: 9 additions & 11 deletions test/away.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should emit "away"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "away"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('away', (e) => {
expect(e.nick).toStrictEqual('colinm')
expect(e.message).toStrictEqual('brb food time')
done()
})
client.on('away', (e) => {
expect(e.nick).toStrictEqual('colinm')
expect(e.message).toStrictEqual('brb food time')
})

stream.write(':irc.host.net 301 me colinm :brb food time\r\n')
}))
stream.write(':irc.host.net 301 me colinm :brb food time\r\n')
})
30 changes: 14 additions & 16 deletions test/invite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should emit "invite"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "invite"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('invite', (e) => {
expect(e.from).toStrictEqual('test')
expect(e.to).toStrictEqual('astranger')
expect(e.channel).toStrictEqual('#something')
expect(e.hostmask.nick).toStrictEqual('test')
expect(e.hostmask.username).toStrictEqual('~user')
expect(e.hostmask.hostname).toStrictEqual('example.com')
expect(e.hostmask.string).toStrictEqual('[email protected]')
done()
})
client.on('invite', (e) => {
expect(e.from).toStrictEqual('test')
expect(e.to).toStrictEqual('astranger')
expect(e.channel).toStrictEqual('#something')
expect(e.hostmask.nick).toStrictEqual('test')
expect(e.hostmask.username).toStrictEqual('~user')
expect(e.hostmask.hostname).toStrictEqual('example.com')
expect(e.hostmask.string).toStrictEqual('[email protected]')
})

stream.write(':[email protected] INVITE astranger :#something\r\n')
}))
stream.write(':[email protected] INVITE astranger :#something\r\n')
})
40 changes: 19 additions & 21 deletions test/join.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should emit "join"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "join"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('join', (e) => {
expect(e.nick).toStrictEqual('tjholowaychuk')
expect(e.channel).toStrictEqual('#express')
expect(e.hostmask.nick).toStrictEqual('tjholowaychuk')
expect(e.hostmask.username).toStrictEqual('~tjholoway')
expect(e.hostmask.hostname).toStrictEqual(
'S01067cb21b2fd643.gv.shawcable.net',
)
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
done()
})

stream.write(
':[email protected] JOIN #express\r\n',
client.on('join', (e) => {
expect(e.nick).toStrictEqual('tjholowaychuk')
expect(e.channel).toStrictEqual('#express')
expect(e.hostmask.nick).toStrictEqual('tjholowaychuk')
expect(e.hostmask.username).toStrictEqual('~tjholoway')
expect(e.hostmask.hostname).toStrictEqual(
'S01067cb21b2fd643.gv.shawcable.net',
)
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
}))
})

stream.write(
':[email protected] JOIN #express\r\n',
)
})
42 changes: 20 additions & 22 deletions test/kick.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should emit "kick"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "kick"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('kick', (e) => {
expect(e.nick).toStrictEqual('tjholowaychuk')
expect(e.client).toStrictEqual('tobi')
expect(e.channel).toStrictEqual('#express')
expect(e.hostmask.nick).toStrictEqual('tjholowaychuk')
expect(e.hostmask.username).toStrictEqual('~tjholoway')
expect(e.hostmask.hostname).toStrictEqual(
'S01067cb21b2fd643.gv.shawcable.net',
)
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
done()
})

stream.write(
':[email protected] KICK #express tobi :Too ferrety\r\n',
client.on('kick', (e) => {
expect(e.nick).toStrictEqual('tjholowaychuk')
expect(e.client).toStrictEqual('tobi')
expect(e.channel).toStrictEqual('#express')
expect(e.hostmask.nick).toStrictEqual('tjholowaychuk')
expect(e.hostmask.username).toStrictEqual('~tjholoway')
expect(e.hostmask.hostname).toStrictEqual(
'S01067cb21b2fd643.gv.shawcable.net',
)
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
}))
})

stream.write(
':[email protected] KICK #express tobi :Too ferrety\r\n',
)
})
148 changes: 70 additions & 78 deletions test/names.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,81 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should respond with user names', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should respond with user names', () => {
const stream = new Stream()
const client = irc(stream)

client.names('#luna-lang', (err, names) => {
if (err) return done(err)
expect(names).toStrictEqual([
{ name: 'owner', mode: '~' },
{ name: 'foo', mode: '@' },
{ name: 'halfop', mode: '%' },
{ name: 'bar', mode: '+' },
{ name: 'baz', mode: '' },
{ name: 'some', mode: '' },
{ name: 'more', mode: '' },
])
done()
})
client.names('#luna-lang', (err, names) => {
expect(err).toBeNull()
expect(names).toStrictEqual([
{ name: 'owner', mode: '~' },
{ name: 'foo', mode: '@' },
{ name: 'halfop', mode: '%' },
{ name: 'bar', mode: '+' },
{ name: 'baz', mode: '' },
{ name: 'some', mode: '' },
{ name: 'more', mode: '' },
])
})

setImmediate(() => {
stream.write(
':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n',
)
stream.write(
':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n',
)
stream.write(
':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n',
)
})
}))
stream.write(
':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :~owner @foo %halfop +bar baz\r\n',
)
stream.write(
':pratchett.freenode.net 353 tjholowaychuk = #luna-lang :some more\r\n',
)
stream.write(
':pratchett.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n',
)
})

it('should emit "names"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "names"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('names', (e) => {
expect(e.channel).toStrictEqual('#luna-lang')
expect(e.names).toStrictEqual([
{ name: 'one', mode: '' },
{ name: 'two', mode: '~' },
{ name: 'three', mode: '' },
{ name: 'foo', mode: '@' },
{ name: 'bar', mode: '@' },
{ name: 'baz', mode: '%' },
])
done()
})
client.on('names', (e) => {
expect(e.channel).toStrictEqual('#luna-lang')
expect(e.names).toStrictEqual([
{ name: 'one', mode: '' },
{ name: 'two', mode: '~' },
{ name: 'three', mode: '' },
{ name: 'foo', mode: '@' },
{ name: 'bar', mode: '@' },
{ name: 'baz', mode: '%' },
])
})

stream.write(':[email protected] JOIN #luna-lang\r\n')
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n',
)
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n',
)
stream.write(
':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n',
)
}))
stream.write(':[email protected] JOIN #luna-lang\r\n')
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :one ~two three\r\n',
)
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk = #luna-lang :@foo @bar %baz\r\n',
)
stream.write(
':rothfuss.freenode.net 366 tjholowaychuk #luna-lang :End of /NAMES list.\r\n',
)
})

it('should retain ~ / @ / % / +', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should retain ~ / @ / % / +', () => {
const stream = new Stream()
const client = irc(stream)

client.on('names', (e) => {
expect(e.channel).toStrictEqual('##luna-lang')
expect(e.names).toStrictEqual([
{ name: 'owner', mode: '~' },
{ name: 'tjholowaychuk', mode: '@' },
{ name: 'halfop', mode: '%' },
{ name: 'tobi', mode: '+' },
])
done()
})
client.on('names', (e) => {
expect(e.channel).toStrictEqual('##luna-lang')
expect(e.names).toStrictEqual([
{ name: 'owner', mode: '~' },
{ name: 'tjholowaychuk', mode: '@' },
{ name: 'halfop', mode: '%' },
{ name: 'tobi', mode: '+' },
])
})

stream.write(':[email protected] JOIN #luna-lang\r\n')
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n',
)
stream.write(
':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n',
)
}))
stream.write(':[email protected] JOIN #luna-lang\r\n')
stream.write(
':rothfuss.freenode.net 353 tjholowaychuk @ ##luna-lang :~owner @tjholowaychuk %halfop +tobi\r\n',
)
stream.write(
':rothfuss.freenode.net 366 tjholowaychuk ##luna-lang :End of /NAMES list.\r\n',
)
})
36 changes: 17 additions & 19 deletions test/nick.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ import { expect, it } from 'vitest'
import irc from '..'
import { PassThrough as Stream } from 'stream'

it('should emit "nick"', () =>
new Promise((done) => {
const stream = new Stream()
const client = irc(stream)
it('should emit "nick"', () => {
const stream = new Stream()
const client = irc(stream)

client.on('nick', (e) => {
expect(e.nick).toStrictEqual('colinm')
expect(e.new).toStrictEqual('cmilhench')
expect(e.hostmask.nick).toStrictEqual('colinm')
expect(e.hostmask.username).toStrictEqual('~colinm')
expect(e.hostmask.hostname).toStrictEqual('host-92-17-247-88.as13285.net')
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
done()
})

stream.write(
':[email protected] NICK :cmilhench\r\n',
client.on('nick', (e) => {
expect(e.nick).toStrictEqual('colinm')
expect(e.new).toStrictEqual('cmilhench')
expect(e.hostmask.nick).toStrictEqual('colinm')
expect(e.hostmask.username).toStrictEqual('~colinm')
expect(e.hostmask.hostname).toStrictEqual('host-92-17-247-88.as13285.net')
expect(e.hostmask.string).toStrictEqual(
'[email protected]',
)
}))
})

stream.write(
':[email protected] NICK :cmilhench\r\n',
)
})
Loading

0 comments on commit 9ac20fd

Please sign in to comment.