Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@highpoint/frontend-testing
Advanced tools
Package to orchestrate configuration for storybook and cypress for testing highpoint frontend apps.
This package installs all of the necessary dependencies for Storybook.js and Cypress and includes presets and configuration for documenting and unit testing react components.
Storybook.js component documentation and development tool with preconfigured webpack config & additional settings (automatically detects and includes stories defined in *.stories.(ts|js|tsx|jsx)
files anywhere in your project)
yarn hpt-storybook
- Run the local storybook webserveryarn hpt-storybook-build
- Build a static version of the storybookCypress testing preconfigured with unit testing support, snapshot testing, cypress-axe a11y testing, and automatic report generation (automatically detects and includes tests defined in *.test.(ts|js|tsx|jsx)
files)
yarn hpt-cypress-open
- Preconfigured cypress openyarn hpt-cypress-run
- Preconfigured cypress run w/ report generationEssentially you get everything you need to develop, unit test, and document a frontend react app with all dependencies and configuration under the hood. :sunglasses:
Install the package
yarn add --dev @highpoint/frontend-testing
Add the following scripts to package.json
. These can be used to run/build Storybook and Cypress.
{
"storybook": "hpt-storybook",
"storybook:build": "hpt-storybook-build",
"test": "hpt-cypress-open",
"test:run": "hpt-cypress-run"
}
Add the Cypress types to your project's tsconfig.json includes
array
{
"includes": [..., "node_modules/@gjoneshpt/cypress-plugin-snapshots/types", "node_modules/cypress/types"]
}
Add a .storybook
folder to the root folder of the consuming project.
In that folder, add a main.ts
file. Paste in this code:
const { main } = require('@highpoint/frontend-testing');
module.exports = main;
Also in the .storybook
folder, add a preview.tsx
file. Paste in this code:
const { preview } = require('@highpoint/frontend-testing');
module.exports = preview;
Also in .storybook
, add a preview-head.html
file. Paste in this code:
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:100,200,300,400,500,600,700&display=swap" rel="stylesheet">
<style>
html, body, #root {
height: 100%;
}
@media print {
#root, #docs-root {
display: none !important;
}
}
</style>
Thats it, you're ready to run Storybook and Cypress! Run yarn storybook
to run the local storybook server and yarn test
to open the cypress test runner.
Storybook and Cypress play well together!
When you write storybook story for a component, you are essentially writing a test specification for it. Each component should have multiple stories with different variations of props passed to it. Exporting a story from a *.stories.(tsx|jsx)
file adds it to the storybook. (See storybook docs for more details)
Say we have some component called HelloWorld. Our stories file could look like this:
// HelloWorld.stories.tsx
import React from 'react';
import { HelloWorld } from '.';
export default {
title: 'HelloWorld',
component: HelloWorld,
parameters: {
componentSubtitle: 'This is the HelloWorld component.',
}
};
const Template = (args) => <HelloWorld {...args} />;
export const Standard = Template.bind({});
Standard.args = {
myProp: 1
}
export const Different = Template.bind({});
Different.args = {
myProp: 2
}
Storybook automatically detects the exported stories and adds them to the storybook, but we can also import these stories into our test files and test directly against them. This means that when we write our stories, we are not only defining our component documention but also our test cases! So our test file can look like this:
// HelloWorld.test.tsx
import React from 'react';
// This mount function is the same as the mount function in 'cypress-react-unit-test' except it also renders a decorator with the @highpoint/ui-elements theme provider.
import { mount } from '@highpoint/frontend-testing';
import { Standard, Different } from './HelloWorld.stories';
describe('HelloWorld', () => {
it('Standard', () => {
// Note we have to pass the story args to the component
mount(<Standard {...Standard.args} />);
cy.document().toMatchImageSnapshot();
});
it('Different', () => {
mount(<Different {...Different.args} />);
cy.document().toMatchImageSnapshot();
});
});
Component stories and tests should both be placed inline with the component definitions. So for our HelloWorld component, the file structure should look like this:
project
│
└───components
└───HelloWorld
│ index.tsx
│ HelloWorld.stories.tsx
│ HelloWorld.test.tsx
You can modify any configuration in main.ts
and preview.tsx
by overriding any field on the storybookDefaults object:
/* preview.tsx */
const { preview } = require('@highpoint/frontend-testing');
// Add additional parameters
preview.parameters.viewMode = 'canvas';
// Add additional decorators
preview.decorators.push(Story => <NotificationMananger><Story /></NotificationManager>);
module.exports = preview;
or
/* main.ts */
const { main } = require('@highpoint/frontend-testing');
// Use different stories glob
main.stories = ['../src/**/*.stories.@(ts|tsx|js|jsx|mdx)']
module.exports = main;
Configuration options to come...
FAQs
Package to orchestrate configuration for storybook and cypress for testing highpoint frontend apps.
The npm package @highpoint/frontend-testing receives a total of 2 weekly downloads. As such, @highpoint/frontend-testing popularity was classified as not popular.
We found that @highpoint/frontend-testing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.