Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cypress to Storybook CI #8397

Merged
merged 39 commits into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4fb8e87
ADD first cypress test
ndelangen Oct 12, 2019
c447b0f
log error message for build-storybooks to the console
kroeder Oct 12, 2019
41b7143
fix spawn call on windows machines
kroeder Oct 12, 2019
4995cb4
make test:e2e-start cross-platform compatible
kroeder Oct 12, 2019
642d623
fix ember example prebuild-storybook command on windows machines
kroeder Oct 12, 2019
0833478
kill serve process with exit(0) instead of (1) after e2e succeeds
kroeder Oct 12, 2019
2ad87bb
add bootstrapped cypress files
kroeder Oct 12, 2019
d691941
add script for opening the cypress gui; update e2e ci script
kroeder Oct 12, 2019
d135fae
fix spec errors using cypress eslint plugin
kroeder Oct 12, 2019
aa9dfbd
add typescript support to cypress
kroeder Oct 12, 2019
a7cf250
extract the visit url in a separate helper file accessible for all tests
kroeder Oct 12, 2019
561c9e9
add navigation click, routing and searching navigation items
kroeder Oct 12, 2019
89d0cfa
remove example fixture
kroeder Oct 12, 2019
34c4908
update navigation e2e tests
kroeder Oct 13, 2019
887447d
add e2e test for knobs
kroeder Oct 13, 2019
fe82ad7
Merge branch 'next' into tech/add-cypress
ndelangen Oct 15, 2019
fb84d88
REMOVE the acceptance stories, the cypress tests give the same if not…
ndelangen Oct 15, 2019
36fcc73
ADD cypress to CI && CHANGE build examples to use script in CI
ndelangen Oct 15, 2019
94ced7b
EXTRACT bootstrap from build-storybooks command
ndelangen Oct 15, 2019
b8ef6a7
Run cypress step in cypress container
ndelangen Oct 15, 2019
3ab4bba
CHANGE circleci config to orbs and run cypress in a orb
ndelangen Oct 15, 2019
7169f05
maybe parallel build-examples is faster?
ndelangen Oct 15, 2019
250099a
FIX missing yarn command
ndelangen Oct 15, 2019
85a3f2f
REMOVE built-storybooks static dir
ndelangen Oct 15, 2019
5a2084d
Revert "maybe parallel build-examples is faster?"
ndelangen Oct 15, 2019
e08b297
use get
ndelangen Oct 15, 2019
d0b9c09
CHANGE await into yarn script
ndelangen Oct 16, 2019
bbf48ca
do not use orb
ndelangen Oct 16, 2019
bdcda23
WIP
ndelangen Oct 16, 2019
0d6a657
FIX cypress install
ndelangen Oct 16, 2019
bde5ec0
make it better maybe
ndelangen Oct 16, 2019
9a9584e
cache invalidation
ndelangen Oct 16, 2019
3e25563
ADD cypress install
ndelangen Oct 16, 2019
4dff6a7
CLEANUP
ndelangen Oct 16, 2019
b4a9933
Tech/cypress in orbs (#8430)
ndelangen Oct 16, 2019
e277ed9
ADD reject
ndelangen Oct 17, 2019
1f09b88
FIX warning of a github action
ndelangen Oct 17, 2019
8e01e91
maybe add parallelism to circleci examples generation
ndelangen Oct 17, 2019
1518b5d
Tech/split examples generation (#8453)
ndelangen Oct 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -32,3 +32,4 @@ htpasswd
storybook-out
/addons/docs/common/config-*
built-storybooks
cypress/videos
1 change: 1 addition & 0 deletions cypress.json
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/.eslintrc.json
@@ -0,0 +1,5 @@
{
"extends": [
"plugin:cypress/recommended"
]
}
17 changes: 17 additions & 0 deletions cypress/helper.ts
@@ -0,0 +1,17 @@
const baseUrl = 'http://localhost:8001';

type StorybookApps = 'official-storybook';

type Addons = 'Knobs';

export const visitExample = (app: StorybookApps, route = '') => {
return cy.visit(`${baseUrl}/${app}/${route}`);
};

export const clickAddon = (addonName: Addons) => {
return cy.get(`[role=tablist] button[role=tab]`).contains(addonName);
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
};

export const getStorybookPreview = () => {
return cy.get('.sb-show-main');
};
14 changes: 14 additions & 0 deletions cypress/integration/knobs.spec.ts
@@ -0,0 +1,14 @@
import { clickAddon, getStorybookPreview, visitExample } from '../helper';

describe('Knobs', () => {
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
visitExample('official-storybook', '?path=/story/addons-knobs-withknobs--tweaks-static-values');
});

it('[text] it should change a string value', () => {
clickAddon('Knobs');

cy.get('#Name').type('John Doe');
getStorybookPreview().should('contain', 'My name is John Doe');
});
});
39 changes: 39 additions & 0 deletions cypress/integration/navigation.spec.ts
@@ -0,0 +1,39 @@
import { getStorybookPreview, visitExample } from '../helper';

describe('Navigation', () => {
beforeEach(() => {
visitExample('official-storybook');
});

it('should search navigation item', () => {
cy.get('#storybook-explorer-searchfield')
.click()
.type('persisting the action logger');

cy.get('.sidebar-container a')
.should('contain', 'Persisting the action logger')
.and('not.contain', 'a11y');
});

it('should display no results after searching a non-existing navigation item', () => {
cy.get('#storybook-explorer-searchfield')
.click()
.type('zzzzzzzzzz');

cy.get('.sidebar-container').should('contain', 'This filter resulted in 0 results');
});
});

describe('Routing', () => {
it('should navigate to story addons-a11y-basebutton--default', () => {
visitExample('official-storybook');
cy.get('#exploreraddons-a11y-basebutton--label').click();

cy.url().should('include', 'path=/story/addons-a11y-basebutton--label');
});

it('should directly visit a certain story and render correctly', () => {
visitExample('official-storybook', '?path=/story/addons-a11y-basebutton--label');
getStorybookPreview().should('contain', 'Testing the a11y addon');
});
});
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
@@ -0,0 +1,22 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

const wp = require('@cypress/webpack-preprocessor');
const webpackConfig = require('./webpack.config');

module.exports = on => {
const options = {
webpackOptions: webpackConfig,
};
on('file:preprocessor', wp(options));
};
21 changes: 21 additions & 0 deletions cypress/plugins/webpack.config.js
@@ -0,0 +1,21 @@
module.exports = {
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
],
},
};
25 changes: 25 additions & 0 deletions cypress/support/commands.js
@@ -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 is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
@@ -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')
10 changes: 10 additions & 0 deletions cypress/tsconfig.json
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es2017", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion examples/ember-cli/package.json
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "ember build",
"prebuild-storybook": "yarn build && cp -r public/* dist",
"prebuild-storybook": "yarn build && shx cp -r public/* dist",
"build-storybook": "build-storybook -s dist",
"dev": "ember serve",
"storybook": "yarn build && start-storybook -p 9009 -s dist",
Expand Down
13 changes: 11 additions & 2 deletions package.json
Expand Up @@ -68,10 +68,13 @@
"publish:latest": "lerna publish --exact --concurrency 1 --force-publish",
"publish:next": "npm run publish:latest -- --npm-tag=next",
"repo-dirty-check": "node ./scripts/repo-dirty-check",
"serve-storybooks": "serve ./built-storybooks -l 8001",
"start": "yarn --cwd examples/official-storybook storybook",
"test": "node ./scripts/test.js",
"test-latest-cra": "yarn --prefix --cwd lib/cli run test-latest-cra",
"test:cli": "npm --prefix lib/cli run test"
"test:cli": "npm --prefix lib/cli run test",
"test:e2e-ci": "concurrently --success first --kill-others \"wait-on http://localhost:8001 && cypress run\" \"yarn serve-storybooks\"",
"test:e2e-gui": "concurrently --success first --kill-others \"cypress open\" \"yarn serve-storybooks\""
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -114,7 +117,13 @@
},
"browserslist": "defaults",
"dependencies": {
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
"node-sass": "^4.12.0"
"@cypress/webpack-preprocessor": "^4.1.0",
"cypress": "^3.4.1",
"eslint-plugin-cypress": "^2.7.0",
"node-sass": "^4.12.0",
"serve": "^11.2.0",
"shx": "^0.3.2",
"wait-on": "^3.3.0"
},
"devDependencies": {
"@angular/common": "^8.2.8",
Expand Down
22 changes: 13 additions & 9 deletions scripts/build-storybooks.js
Expand Up @@ -22,15 +22,19 @@ const logger = console;

const exec = async (command, args = [], options = {}) =>
new Promise((resolve, reject) => {
const child = spawn(command, args, { ...options, stdio: 'inherit' });

child.on('close', code => {
if (code) {
reject();
} else {
resolve();
}
});
const child = spawn(command, args, { ...options, stdio: 'inherit', shell: true });

child
.on('close', code => {
if (code) {
reject();
} else {
resolve();
}
})
.on('error', e => {
logger.error(e);
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
});
});

const hasBuildScript = async l => {
Expand Down