Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed May 7, 2024
1 parent bf02b3c commit 37ab139
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions test/e2e/unauthorized.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<script src="/.tmp/geckos.io-client.latest.min.js"></script>
Expand All @@ -7,7 +7,7 @@
<script>
'use strict'

var channel = geckos({ port: 4000, authorization: 'some-unique-token' })
var channel = geckos({ port: 4001, authorization: 'some-unique-token' })

channel.onConnect(error => {
if (error) {
Expand Down
30 changes: 15 additions & 15 deletions test/e2e/unauthorized.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import http from 'http'
import path from 'path'

import { __dirname } from './_dirname.js'
import { sleep } from '../helpers.js'
import { sleep, serverListenPromise, kill } from '../helpers.js'

const app = express()

const server = http.createServer(app)
const sockets = new Set()
server.on('connection', socket => {
sockets.add(socket)
server.once('close', () => {
sockets.delete(socket)
})
})

let theToken
const io = geckos({
authorization: async token => {
Expand All @@ -20,20 +29,21 @@ const io = geckos({
app.use('/', Static(path.join(__dirname, '../')))

io.addServer(server)
server.listen(4000)
await serverListenPromise(server, 4001)

io.onConnection(ch => {})

describe('connection', () => {
test('should have no connection', async () => {
let connections = 0

io.onConnection(ch => {
connections++
})

await page.goto('http://localhost:4000/e2e/unauthorized.html')
await page.goto('http://localhost:4001/e2e/unauthorized.html', { timeout: 2000 })

await sleep(5000)
await sleep(2000)

expect(connections).toBe(0)
})
Expand All @@ -46,15 +56,5 @@ describe('unauthorized', () => {
})

afterAll(async () => {
const close = () => {
return new Promise(resolve => {
server.close(() => {
resolve()
})
})
}

await close()
// await page.close()
// await browser.close()
await kill(server, sockets)
})
9 changes: 9 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ export const kill = async (httpServer, sockets = new Set()) => {
})
}

export const serverListenPromise = (httpServer, port) => {
return new Promise(resolve => {
httpServer.listen(port, () => {
console.log('listening on port', port)
resolve()
})
})
}

export const sleep = (ms = 1000) => new Promise(r => setTimeout(r, ms))

0 comments on commit 37ab139

Please sign in to comment.