Skip to content

Instantly share code, notes, and snippets.

View NoriSte's full-sized avatar

Stefano Magni NoriSte

View GitHub Profile
@NoriSte
NoriSte / README.md
Last active February 2, 2024 13:45
DS coverage script

DS Coverage raw script

🚨🚨🚨 UPDATE: index.js is the original script while index.ts is the most updated one! 🚨🚨

Keep in mind the script is an experiment, I need to add types, refine it, make it readable, etc.

  1. Open a Preply page (whatever environment)
  2. Copy/paste it as is in the Chrome's console and press enter
  3. Look at the logged result
@NoriSte
NoriSte / blockServerRequests.js
Created January 31, 2023 09:59
Preventing requests to hit the server during server-free Cypress tests
/**
* Ensure no requests hit the server, it's mostly a safe protection for the developers running
* server-free tests that could miss some requests are actually hitting the real server, then
* resulting in test flakiness because of partial server stubbing.
*/
export function blockServerRequests() {
cy.log('**--- Prevent any requests to hit the real server**');
cy.intercept('http://localhost:8080/**', { forceNetworkError: true });
}
@NoriSte
NoriSte / README.md
Created December 13, 2022 08:28
Using Storybook Test Runner on Hasura Console (Dec, 2022)

As of Today, we cannot use the Storybook Test Runner in Hasura's Console codebase because on some machines some tests are flaky.

As a temporary workaround, if you really need it, you can apply the following changes (without committing them) to use it locally.

PLEASE NOTE: Due to the migration to Nx, these steps will not work for a long time, use them only if you benefit a lot from running all tyhe Storybook tests from the terminal!

  1. Install "@storybook/test-runner": "0.6.2",
  2. Add a new script "test-storybook": "test-storybook",
  3. In console/.storybook, add a file called "test-runner-jest.config.js" with the following content
@NoriSte
NoriSte / useToggleMachine.ts
Last active December 5, 2022 08:40
OpenTelemetry Toggle logics with a React hook and with XState (they can be not totally aligned)
// ---------------------------------------------------------------
// CONTEXT
export type Context = {
// The current status of OpenTelemetry
status: 'enabled' | 'disabled';
// Whether the current metadata contains the configuration or not
metadataContainsConfig: boolean;
// Whether the current form state contains valid configuration or not
@NoriSte
NoriSte / README.md
Created June 23, 2022 08:03
Launch the cursor-highlighted Playwright in VSCode

Referring to this tweet, when I said that you have to run a Playwright test through the CLI, Denb, on the ItaliaJS Discord channel, shared this VSCode cuustom task with me that allows launching specifically the test the cursor is pointing.

@NoriSte
NoriSte / README.md
Last active June 1, 2022 15:02
Simple example of tests

Following Stately announcing the latest release of XState/test, I played a bit with the tool.

I have some doubts aobut the fact that XState/test does not allow (if I am not mistaken) to quickly isolate tests where each of them have their unique setup processes.

Here the gists I used to generate the screenshots I used in this series of tweets.

@NoriSte
NoriSte / README.md
Last active May 20, 2022 09:48
waitForPostCreationRequests.ts

It happened to me that the "Element is detached from the DOM" Cypress' error was related to a bunch of requests that, when settled, caused the UI to re-render.

This is anattempt of waiting for all of requests to be settled, without knowing in advance how many of them are made.

You can discuss it on Twitter.

@NoriSte
NoriSte / index.html
Last active May 9, 2022 08:17
Reading env variables from the Hasura's Console with Cypress (with sample Hasura's Console HTML page)
<!doctype html>
<html lang="en-US" data-reactroot=""><head><link rel="icon" type="image/png" href="/rstatic/favicon_green.png"/><script>
window.__env = {
dataApiUrl: 'http://localhost:8080',
isAdminSecretSet: 'true',
consoleMode: 'server',
nodeEnv: 'development',
serverVersion: 'v1.0.0',
urlPrefix: '/',
import { Login } from './Login'
import { Connect } from './Connect'
import { Content } from './Content'
import { useInit } from './hooks/useInit'
import { useAppStatus } from './hooks/useAppStatus'
import { GenericInstructions } from './GenericInstructions'
import { UserNotAllowedState } from './UserNotAllowedState'
import { AllOrdersSelectedError } from './AllOrdersSelectedError'
import { SelectOrdersInstructions } from './SelectOrdersInstructions'
@NoriSte
NoriSte / useAppStatus.ts
Created January 20, 2022 14:41
Explicit React hook-based FSM
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import {
setShopifyShop,
useAuthSession,
useConnectStatus,
useShopifyArguments,
useShopifyUserData,
} from '@/atoms'
import { useDetectPage } from './useDetectPage'