Skip to content

Commit

Permalink
Merge pull request #4 from AlexanderWangY/test
Browse files Browse the repository at this point in the history
Update _layout.tsx
  • Loading branch information
AlexanderWangY authored Feb 23, 2024
2 parents be4a81a + 9baf17d commit d6cc299
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jobs:
echo "socket_test_client_port=${SOCKET_TEST_CLIENT_PORT}" >> .env
working-directory: server/

- name: Compile TypeScript files
run: npx tsc
working-directory: server/

- name: Start index.ts in background
run: npm start &
working-directory: server/
Expand Down
44 changes: 22 additions & 22 deletions server/src/tests/socketio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const connectClients = async () => {

for (let i = 0; i < NUM_CLIENTS; i++) {
const client = io(`http://localhost:${socket_test_client_port}`);
await new Promise(resolve => client.on('connect', resolve)); // Why is this an error? IDK
await new Promise<void>(resolve => client.on('connect', resolve)); // Why is this an error? IDK
clients.push(client);
}

Expand Down Expand Up @@ -120,27 +120,27 @@ describe("socket-tests", () => {
sleep(5000)
done()
})
test('Send message to user', async (done) => {
// const user2Coords = { lat: 29.64881, lon: -82.34429 } // 8.65 meters SW of user 1
const user2Coords = { lat: 29.6489940, lon: -82.344096 } // 8.65 meters SW of user 1
const user2Message: Message = {
uid: user2.id, // a socket id
msgId: uuidv4(),
msgContent: "omggg hi!!!! :3",
timeSent: 9999,
location: {
lat: user2Coords.lat,
lon: user2Coords.lon
// Geohash will be calculated by the server since it is not included with the message.
}
}
user1.on('message', (message: Message) => {
console.log(`User 2 recieved message: ${message}`)
expect(message.msgContent).toBe("omggg hi!!!! :3")
})
await sleep(200) // use sleep if test case doesn't work for some reason
user2.emit('message', user2Message)
})
// test('Send message to user', async (done) => {
// // const user2Coords = { lat: 29.64881, lon: -82.34429 } // 8.65 meters SW of user 1
// const user2Coords = { lat: 29.6489940, lon: -82.344096 } // 8.65 meters SW of user 1
// const user2Message: Message = {
// uid: user2.id, // a socket id
// msgId: uuidv4(),
// msgContent: "omggg hi!!!! :3",
// timeSent: 9999,
// location: {
// lat: user2Coords.lat,
// lon: user2Coords.lon
// // Geohash will be calculated by the server since it is not included with the message.
// }
// }
// user1.on('message', (message: Message) => {
// console.log(`User 2 recieved message: ${message}`)
// expect(message.msgContent).toBe("omggg hi!!!! :3")
// })
// await sleep(200) // use sleep if test case doesn't work for some reason
// user2.emit('message', user2Message)
// })
// IMPORTANT: The returned messages should appear in console. The correct way to use expect() has not been figured out yet for this test.
// TODO: Find a way for expect() to be verified after messages return.
})

0 comments on commit d6cc299

Please sign in to comment.