npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@avant-inc/tapestry

v0.5.0

Published

Avant Design System

Downloads

194

Readme

Tapestry Design System

Table of Contents

General Info

The purpose of this project is to build/provide custom components that can be implemented throughout all of our applications.

Technologies

Get Started

Setup

Currently Tapestry is build using node version 17.9.1.

If you don't have node installed, then install it locally nodejs or via asdf website

If you are using asdef to control your node version for your projec, you need to install nodejs version 17.9.1

Install dependencies

The generated project includes React, and ReactDOM as devDependencies. You may install other dependencies (for example, React Router) with npm:

npm install --save-dev react-router

Whenever a devDependency is installed, be sure to add it as a peer dependency as well. Our intent is to keep this component library lightweight in order to improve performance and to avoid duplication of node_modules.

Folder structure

When building out your component, you should include a main folder (named appropriately) with all the related files nested inside.

  • Required
    • index.tsx file that exports your custom component
    • [FileName].test.tsx to include your tests for that component
    • [FileName].stories.tsx to provide the UI portion of your component in storybook (not necessary for hooks/utils)
  • Optional
    • [FileName].styles.(ts/\x|css) to separate styles styles for that specific component.

Below is an example of how your file structure should appear when creating your component or customHook:

my-app/
  README.md
  node_modules/
  dist/
  src/
    components/
      Button/
        Button.tsx
        Button.stories.tsx
        Button.test.tsx
        index.ts
    customHooks/
      useDelay/
        useDelay.test.tsx
        index.tsx
    index.ts

Testing

Writing tests

To create tests, add an it() block with the name of the test and its code. The describe() command allows you to group related tests, producing clear outputs.

Jest provides a built-in expect() global function for making assertions. A basic test could look like this:

import React from 'react'
import { fireEvent, screen, render } from '@testing-library/react'
import { axe } from 'jest-axe'

import { Button, ButtonProps } from './Button'

describe('Button', () => {
  const TestComponent = (props: Partial<ButtonProps>): JSX.Element => (
    <Button {...props}>
      {props.children}
    </Button>
  )

  it('should call onClick when is clicked', () => {
    const onClickMock = jest.fn()

    render(<TestComponent onClick={onClickMock}>Button</TestComponent>)

    fireEvent.click(screen.getByRole('button', { name: 'Button' }))

    expect(onClickMock).toHaveBeenCalledTimes(1)
  })

  it('should not call onClick when is disabled', () => {
    const onClickMock = jest.fn()

    render(<TestComponent onClick={onClickMock} disabled={true}>Button</TestComponent>)

    fireEvent.click(screen.getByRole('button', { name: 'Button' }))

    expect(onClickMock).toHaveBeenCalledTimes(0)
  })

  it('should not fail any accesibility tests', async () => {
    const { container } = render(<TestComponent>Button</TestComponent>)

    expect(await axe(container)).toHaveNoViolations()
  })
})

All expect() matches supported by Jest are extensively documented here. You can also use jest.fn() and expect(fn).toBeCalled() to create "spies" or mock functions.

Things to highlight:

  • It is a good idea to create a wrapper around the component you are going to test, this helps in case the component structure change in the future
  • Always (if possible) include a test that make sure the component is accesible
  • Include as many senarios that you can think of, and try to almost always use one assertion per test (if possible)
  • Use priority list to get the elements as much as possible

Debugging

Some times you don't know why a test is failing so you can use screen.debug() to display the HTML content that is being generated by that test

import React from 'react'
import { screen, render } from '@testing-library/react'

import { Button, ButtonProps } from './Button'

describe('Button', () => {
  const TestComponent = (props: Partial<ButtonProps>): JSX.Element => (
    <Button {...props}>
      {props.children}
    </Button>
  )

  it('should call onClick when is clicked', () => {
    const onClickMock = jest.fn()

    render(<TestComponent onClick={onClickMock}>Button</TestComponent>)

    screen.debug()

    fireEvent.click(screen.getByRole('button', { name: 'Button' }))

    expect(onClickMock).toHaveBeenCalledTimes(1)
  })
})