Skip to content

Instantly share code, notes, and snippets.

View ahayes91's full-sized avatar

Aislinn Hayes ahayes91

View GitHub Profile
#!/bin/bash
read -p "Before commencing the script to remove the files, have you made a backup of your repository? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Have you created a mirror clone of your repository, and have you removed any references to the files from the .gitignore file in your repo, and pushed this change? (y/n) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Is this laptop connected to LAN, connected to power, and have you ensured that this laptop will not sleep by changing Energy Settings on Mac? (y/n) " -n 1 -r
Action Timeframe Who Full instructions Start date Done
Communicate code freeze to UI teams. 5 mins Aislinn Hayes Post on Slack channels. Day 1
Check that all PRs are closed and branches are deleted where possible. 15 mins Aislinn Hayes N/A
... ... ... ... ... ...
@ahayes91
ahayes91 / purgingresults.md
Last active December 5, 2019 17:56
Test purging files from git history
Approach Time Taken
Git filter branch on a forked copy of the repo 15 hours
BFG with aggressive flag on a duplicated copy of the repo 36 hours
BFG without aggressive flag on a duplicated copy of the repo 5 minutes
@ahayes91
ahayes91 / App.js
Last active June 12, 2021 20:17
create-react-app App.js file with some simple and quick modifications to display a button that makes an API request, and shows the result in a table, or an error message based on the response of that request.
import { useState, useCallback } from 'react';
import axios from 'axios';
import './App.css';
function App() {
const [posts, setPosts] = useState([]);
const [error, setError] = useState(false);
const fetchRequest = useCallback(() => {
axios.get('https://jsonplaceholder.typicode.com/posts')
@ahayes91
ahayes91 / DisplaysFailureMessage.integration.test.js
Last active June 12, 2021 20:29
App-level integration test that tests the error message displayed to the user when the API request fails.
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import getAndSetupServer from './getAndSetupServer';
import { rest } from 'msw';
import App from './App';
getAndSetupServer([
rest.get(
`https://jsonplaceholder.typicode.com/posts`,
async (req, res, ctx) =>
@ahayes91
ahayes91 / DisplaysButtonAndPosts.integration.test.js
Last active June 12, 2021 20:29
App-level integration test that shows what the app should do when the API endpoint is mocked to return 1 result
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import getAndSetupServer from './getAndSetupServer';
import { rest } from 'msw';
import App from './App';
const mockTitle = 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit';
getAndSetupServer([
rest.get(
@ahayes91
ahayes91 / getAndSetupServer.js
Last active June 12, 2021 20:47
Helper file for setting up a Mock Service Worker node server for integration testing
import { setupServer } from 'msw/node';
export default function getAndSetupServer(handlers = []) {
const server = setupServer(...handlers);
beforeAll(() => {
server.listen({
onUnhandledRequest(req) {
const errorMessage = `Found an unhandled ${req.method} request to ${req.url.href}`;
console.error(errorMessage);
throw errorMessage;
@ahayes91
ahayes91 / App.test.js
Last active June 12, 2021 20:47
Starter file needed for an app-level integration test.
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import getAndSetupServer from './getAndSetupServer';
import App from './App';
getAndSetupServer();
describe('Posts app: ', () => {
test('renders button and mocked post in a table on button click', async () => {
render(<App />);
@ahayes91
ahayes91 / initialTestResults.txt
Last active June 12, 2021 20:50
Results of the integration test when the endpoints are not yet mocked to return a response.
FAIL src/App.test.js
● Console
console.error
Found an unhandled GET request to https://jsonplaceholder.typicode.com/posts
7 | onUnhandledRequest(req) {
8 | const errorMessage = `Found an unhandled ${req.method} request to ${req.url.href}`;
> 9 | console.error(errorMessage);
| ^
@ahayes91
ahayes91 / requestSpy.utils.js
Created June 12, 2021 23:34
Reusable function for putting a spy on all requests received by a Mock Service Worker server during a test
/**
* Function creating a spy on requests handled by MSW
* @param server - MSW server instance
* @returns {jest.Mock} - spy on requests handled by MSW
*/
export const createRequestSpy = server => {
const requestSpy = jest.fn(); // eslint-disable-line no-undef
server.on('request:end', requestSpy);
return requestSpy;
};