Skip to content

Commit

Permalink
add a cypress story based test
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed May 8, 2021
1 parent e5fb27c commit c8ba055
Show file tree
Hide file tree
Showing 10 changed files with 1,092 additions and 270 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path');

module.exports = {
stories: ['../src/**/*.stories.@(tsx|mdx)'],
logLevel: 'debug',
addons: [
'@storybook/preset-create-react-app',
{
name: '@storybook/addon-essentials',
options: {
viewport: false,
},
},
],
webpackFinal: (config) => {
// add monorepo root as a valid directory to import modules from
config.resolve.plugins.forEach((p) => {
if (Array.isArray(p.appSrcs)) {
p.appSrcs.push(path.join(__dirname, '..', '..', '..'));
}
});
return config;
},
core: {
builder: 'webpack4',
},
};
27 changes: 27 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

export const decorators = [
(StoryFn, { globals: { locale = 'en' } }) => (
<>
<div>{locale}</div>
<StoryFn />
</>
),
];

export const globalTypes = {
locale: {
name: 'Locale',
description: 'Internationalization locale',
defaultValue: 'en',
toolbar: {
icon: 'globe',
items: [
{ value: 'en', right: '🇺🇸', title: 'English' },
{ value: 'es', right: '🇪🇸', title: 'Español' },
{ value: 'zh', right: '🇨🇳', title: '中文' },
{ value: 'kr', right: '🇰🇷', title: '한국어' },
],
},
},
};
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"fixturesFolder": false,
"testFiles": "**/*.test.tsx",
"componentFolder": "src"
}
10 changes: 10 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const injectCraDevServer = require("@cypress/react/plugins/react-scripts");

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
injectCraDevServer(on, config);

return config;
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
"global": "^4.4.0",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-scripts": "^4.0.2",
"react-scripts": "^4.0.3",
"typescript": "^3.9.7"
},
"devDependencies": {
"@storybook/addon-essentials": "6.3.0-alpha.21",
"@storybook/addons": "6.3.0-alpha.21",
"@storybook/builder-webpack4": "6.3.0-alpha.21",
"@cypress/react": "^5.5.0",
"@cypress/webpack-dev-server": "^1.1.6",
"@storybook/addon-essentials": "^6.2.0",
"@storybook/addons": "^6.2.0",
"@storybook/builder-webpack4": "^6.2.0",
"@storybook/preset-create-react-app": "^3.1.6",
"@storybook/react": "6.3.0-alpha.21",
"webpack": "4"
"@storybook/react": "^6.2.0",
"@storybook/testing-react": "^0.0.10",
"cypress": "^7.2.0",
"webpack": "4",
"webpack-dev-server": "3"
},
"storybook": {
"chromatic": {
Expand Down
10 changes: 10 additions & 0 deletions src/stories/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from "react";
import { mount } from "@cypress/react";
import { composeStories } from "@storybook/testing-react";
import * as rawStories from "./Button.stories";

const { Primary } = composeStories(rawStories);

it("playground", () => {
mount(<Primary />);
});
Loading

0 comments on commit c8ba055

Please sign in to comment.