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
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'
@NoriSte
NoriSte / README.md
Last active October 14, 2021 05:50
TS trap for corrupted *.d.ts files

I had to be creative with TypeScript to prevent a common problem in our codebase, where we can't validate our *.d.ts files through skipLibCheck: false and a type (Action) sometimes become any...

import type { Plugin } from 'vite'
import path from 'path'
const name = 'prevent-server-data-circular-imports'
const defaultOptions = { verbose: false }
// Detect if the module is in server-data
const serverDataFileRegexp = /(.*)?server-data\/src\//
// Extract the imported path

Cypress Protobuf example

I was asked to provide an example of a Cypress test using Protobuf.

@NoriSte
NoriSte / README.md
Last active May 28, 2021 05:50
Migrating a 150K LOC codebase to Vite and ESBuild