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

generator-spike

v0.0.1-beta.6

Published

Generator for React apps, reducers, components, and mock api.

Downloads

14

Readme

Build Status

NPM

What

Spike is a complete development solution React applications. Among other things we support:

  • webpack configuration - including CSS module support.
  • server side rendering.
  • redux (as of this writing, redux-observable specifically).
  • unit and integration tests.

Why

React it is not a framework. There exist a number of scaffoldings, but we aim to be a complete framework solution with specific emphasis on easy configuration, best Redux practices, and testing.

How

Spike is a Yeoman generator. Rather than clone our repo or copy and paste code, simply use the yeoman cli to produce the code you want.

Notes on Yeoman installation

First, make sure you have npm correctly installed. Doing this will save you time both when running code locally and when configuring Dockerfiles. If you use nvm make sure you are using the same nvm Node version when you install yo and generator-spike.

npm install -g yo
npm install -g generator-spike
yo spike
# Add additional reducers to your redux app.
yo spike:reducer
# Add additional redux-observable epics to your redux app.
yo spike:epics
# Add additional action creators to your redux app.
yo spike:actions
# Create and configure integration tests.
yo spike:integrationTests

Redux Dependencies

  • redux-observable: Abstracts all async out of reducers and components using ReactiveX.
  • redux-act: Provides structure for action creator pattern.
  • react-redux: Create containers for injecting redux state and actions into components.
  • reselect: Modular pattern for destructuring and deriving additional data from state.
  • redux-storage: Generic module for initializing Redux store with stored data. Accepts different storage engine plugins, we can easily configure our app to accept localStorage from browser, cookies from server, and native storage from mobile.
    • Initially, we'll use cookies to support server side rendering.
  • redux-catch: Tested pattern for catching errors during redux updates. Can configure this to log errors to console, or save them through an API such as Firebase.
  • redux-logger: Log changes to redux state for development purposes.

Server Side rendering with Styles

We explored a few options:

Important Note about importing images

If you import images within a component, you should not expect it to render on the server - so there will be a discrepancy between server and client. To avoid this issue:

  • Use CSS to set images using the background property rather than importing within components.
  • Do not import any images within components that will render on the server. If necessary, replace those components with a loader that will be replaced when the app has mounted on the client.

Integration Tests

Configure your app for integration tests yo spike:integrationTests.

This will create Docker file as well as docker-compose files that will launch a selenium server connected through the example test cases and pages you generate.

This scaffolding encourages practices of the Page Object Design Pattern for writing selenium tests. While it's tempting to cram driver actions and validations into your tests and you'll find it saves you time, keeps your tests more readable and stable if you follow these patterns. It also makes it much easier to include wait timeout parameters and failure messages the will make your tests run faster and provide you with more detailed test failure messages. For instance:

export async function expectFooterText(expectedText, wait = 2500) {
  const driver = getDriver();
  await driver.wait(until.elementLocated(By.css('footer')),
    wait, 'expectFooterText - footer not found.');
  const footer = await driver.findElement(By.css('footer'));
  await driver.wait(async () => {
    const actualText = await footer.getText();
    return actualText === expectedText;
  }, wait, `expectFooterText - text did not match '${expectedText}'`);
}

See more examples in tests/integration/pages of this repository.

Writing Integration tests locally

You will notice the above command creates a docker-compose.ci.yml file, as well as a docker-compose.integrationTest.yml file. The former is for use within you integration tool (Jenkins, travis, CircleCI, etc). The latter is for devloping locally.

During development you may run tests by:

docker-compose -f docker-compose.integrationTests.yml up -d
docker-compose -f docker-compose.integrationTests.yml run --rm -w"/home/app/code" app npm run test:integration

Note the development file:

  • mounts your local directory to the container so you can update the tests without having to rebuild your image.
  • Uses -debug Docker Selenium images so that you can use a VCN client to watch the browser Selenium is controlling.

Mac OSx has a VCN client pre-instaled. To view tests, simply open vcn://127.0.0.1:5900 (or 5901 in Firefox - see docker-compose.integrationTests.yml) in Safari.