Skip to content

Instantly share code, notes, and snippets.

View siddhant1's full-sized avatar
:electron:
I may be slow to respond.

Sid siddhant1

:electron:
I may be slow to respond.
View GitHub Profile
@siddhant1
siddhant1 / playwright-socketio-mock.ts
Last active December 9, 2025 12:21
Playwright Socket.io WebSocket Mock
/**
* Playwright Socket.io WebSocket Mock
*
* A reusable utility for mocking Socket.io WebSocket connections in Playwright E2E tests.
* Fully mocks the connection without hitting a real server - handles Engine.IO/Socket.io
* protocol handshakes so the browser client thinks it's connected.
*
* Usage:
* const mock = createWebSocketMock();
* await mock.setup(page, /your-ws-pattern/);
@siddhant1
siddhant1 / playwright-socketio-mock.ts
Created December 9, 2025 11:50
Playwright Socket.io WebSocket Mock
/**
* Playwright Socket.io WebSocket Mock
*
* A reusable utility for mocking Socket.io WebSocket connections in Playwright E2E tests.
* Fully mocks the connection without hitting a real server - handles Engine.IO/Socket.io
* protocol handshakes so the browser client thinks it's connected.
*
* Usage:
* const mock = createWebSocketMock();
* await mock.setup(page, /your-ws-pattern/);
import { Page, WebSocketRoute } from '@playwright/test';
/**
* A reusable WebSocket mock for Playwright tests.
* Fully mocks Socket.io connections without connecting to the real server.
*/
class WebSocketMock {
private wsRoute: WebSocketRoute | null = null;
private pingInterval: ReturnType<typeof setInterval> | null = null;
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@siddhant1
siddhant1 / gist:4a2c648b420b340897240885739b2841
Created December 9, 2025 11:47
Mock Socket.io for Playwright
/*
* Copyright 2024 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
import React, { Component } from "react";
import { Query } from "react-apollo";
import { GET_ALL_TODOS } from "../queries";
import MarkTodo from "./MarkTodo";
import DeleteTodo from "./DeleteTodo";
import {
ListGroup,
ListGroupItem,
ButtonGroup,
Grid,
import React, { Component } from "react";
import { Mutation } from "react-apollo";
import { DELETE_TODO, GET_INCOMPLETE_TODOS, GET_ALL_TODOS } from "../queries";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faTimes } from "@fortawesome/free-solid-svg-icons";
import { Button } from "react-bootstrap";
class DeleteTodo extends Component {
constructor(props) {
super(props);
import React, { Component } from "react";
import {
MARK_TODO_COMPLETE,
GET_INCOMPLETE_TODOS,
GET_ALL_TODOS
} from "../queries";
import { Mutation } from "react-apollo";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheck } from "@fortawesome/free-solid-svg-icons";
import { Button } from "react-bootstrap";
import React from "react";
import { Query } from "react-apollo";
import { GET_INCOMPLETE_TODOS } from "../queries";
import MarkTodo from "./MarkTodo";
import DeleteTodo from "./DeleteTodo";
import AddTodos from "./AddTodo";
import {
ListGroup,
ListGroupItem,
ButtonGroup,
import gql from "graphql-tag";
export const GET_ALL_TODOS = gql`
{
todos {
todo_id
todo_text
todo_completed
todo_user
}