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 all 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
162 changes: 52 additions & 110 deletions .circleci/config.yml
@@ -1,14 +1,11 @@
version: 2
version: 2.1

aliases:
- &defaults
working_directory: /tmp/storybook
docker:
- image: circleci/node:10

dependencies:
pre:
- yarn global add npm
jobs:
build:
<<: *defaults
Expand All @@ -17,7 +14,7 @@ jobs:
- restore_cache:
name: Restore core dependencies cache
keys:
- core-dependencies-v3-{{ checksum "yarn.lock" }}
- core-dependencies-v4-{{ checksum "yarn.lock" }}
- run:
name: Install dependencies
command: yarn install
Expand All @@ -29,9 +26,11 @@ jobs:
command: yarn bootstrap --core
- save_cache:
name: Cache core dependencies
key: core-dependencies-v3-{{ checksum "yarn.lock" }}
key: core-dependencies-v4-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- ~/.cache
- node_modules
- /root/.cache
- persist_to_workspace:
root: .
paths:
Expand All @@ -47,9 +46,6 @@ jobs:
- checkout
- attach_workspace:
at: .
- run:
name: Generate static examples
command: yarn build-storybooks
- run:
name: Run chromatic on the pre-built storybook
command: yarn chromatic
Expand All @@ -66,97 +62,50 @@ jobs:
yarn packtracker
examples:
<<: *defaults
parallelism: 4
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Workaround for https://github.com/GoogleChrome/puppeteer/issues/290
command: sh ./scripts/workaround-puppeteer-issue-290.sh
- run:
name: Build react kitchen-sink
command: |
cd examples/cra-kitchen-sink
yarn build-storybook
- run:
name: Build react typescript kitchen-sink
command: |
cd examples/cra-ts-kitchen-sink
yarn build-storybook
- run:
name: Build vue kitchen-sink
command: |
cd examples/vue-kitchen-sink
yarn build-storybook
- run:
name: Build svelte kitchen-sink
command: |
cd examples/svelte-kitchen-sink
yarn build-storybook
- run:
name: Build angular-cli
name: examples
command: |
cd examples/angular-cli
yarn build-storybook
- run:
name: Build ember-cli
command: |
cd examples/ember-cli
yarn build-storybook
- run:
name: Build polymer-cli
command: |
cd examples/polymer-cli
yarn build-storybook
- run:
name: Build marko-cli
command: |
cd examples/marko-cli
yarn build-storybook
- run:
name: Build mithril kitchen-sink
command: |
cd examples/mithril-kitchen-sink
yarn build-storybook
- run:
name: Build html kitchen-sink
command: |
cd examples/html-kitchen-sink
yarn build-storybook
- run:
name: Build riot kitchen-sink
command: |
cd examples/riot-kitchen-sink
yarn build-storybook
- run:
name: Build preact kitchen-sink
command: |
cd examples/preact-kitchen-sink
yarn build-storybook
- run:
name: Build cra react15
command: |
cd examples/cra-react15
yarn build-storybook
- run:
name: Build official-storybook
command: |
cd examples/official-storybook
yarn build-storybook
# - run:
# name: Run image snapshots
# command: yarn test --image
- store_artifacts:
path: examples/official-storybook/image-snapshots/__image_snapshots__
destination: official_storybook_image_snapshots
yarn build-storybooks
- persist_to_workspace:
root: .
paths:
- built-storybooks
e2e:
working_directory: /tmp/storybook
docker:
- image: cypress/base:8
environment:
TERM: xterm
steps:
- checkout
- attach_workspace:
at: .
- run:
name: install cypress
command: yarn cypress install
- save_cache:
name: Cache core dependencies
key: core-dependencies-v4-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- node_modules
- examples
- addons
- app
- lib
- /root/.cache
- run:
name: running example
command: yarn serve-storybooks
background: true
- run:
name: await running examples
command: yarn await-serve-storybooks
- run:
name: cypress run
command: yarn cypress run

smoke-tests:
<<: *defaults
steps:
Expand Down Expand Up @@ -253,18 +202,13 @@ jobs:
- restore_cache:
name: Restore core dependencies cache
keys:
- core-dependencies-v3-{{ checksum "yarn.lock" }}
- core-dependencies-v4-{{ checksum "yarn.lock" }}
- run:
name: Install dependencies
command: yarn install
command: yarn bootstrap --install
- run:
name: Trigger build
command: ./scripts/build-frontpage.js
- save_cache:
name: Cache core dependencies
key: core-dependencies-v3-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
docs:
<<: *defaults
steps:
Expand All @@ -287,12 +231,7 @@ jobs:
name: Cache docs dependencies
key: docs-dependencies-v2-{{ checksum "docs/yarn.lock" }}
paths:
- ~/.cache/yarn
- persist_to_workspace:
root: .
paths:
- docs/public
- docs/node_modules
- ~/.cache
lint:
<<: *defaults
steps:
Expand Down Expand Up @@ -325,19 +264,18 @@ jobs:
name: Upload coverage
command: yarn coverage
workflows:
version: 2
build_test_deploy:
test:
jobs:
- build
- docs
- frontpage
- lint:
requires:
- docs
- build
- examples:
requires:
- build
- e2e:
requires:
- examples
- smoke-tests:
requires:
- build
Expand All @@ -355,4 +293,8 @@ workflows:
- test
- chromatic:
requires:
- build
- examples
deploy:
jobs:
- docs
- frontpage
10 changes: 2 additions & 8 deletions .github/workflows/tests-unit.yml
Expand Up @@ -7,17 +7,11 @@ jobs:

name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [10]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
- uses: actions/setup-node@v1
with:
version: ${{ matrix.node_version }}
node-version: '10.x'
- name: install, bootstrap
run: |
yarn bootstrap --core
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -32,3 +32,5 @@ htpasswd
storybook-out
/addons/docs/common/config-*
built-storybooks
cypress/videos
cypress/screenshots
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"
]
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
55 changes: 55 additions & 0 deletions cypress/helper.ts
@@ -0,0 +1,55 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable jest/valid-expect */
const baseUrl = 'http://localhost:8001';

type StorybookApps = 'official-storybook';

type Addons = 'Knobs';

export const visitExample = (app: StorybookApps, route = '') => {
return cy
.clearLocalStorage()
.visit(`${baseUrl}/${app}/${route}`)
.get(`#storybook-preview-iframe`)
.then({ timeout: 10000 }, iframe => {
return cy.wrap(iframe).should(() => {
const content: Document | null = (iframe[0] as HTMLIFrameElement).contentDocument;
const element: HTMLElement | null = content !== null ? content.documentElement : null;

expect(element).not.null;

if (element !== null) {
expect(element.querySelector('#root > *')).not.null;
}
});
});
};

export const clickAddon = (addonName: Addons) => {
return cy
.get(`[role=tablist] button[role=tab]`)
.contains(addonName)
.click();
};

export const getStorybookPreview = () => {
return cy.get(`#storybook-preview-iframe`).then({ timeout: 10000 }, iframe => {
const content: Document | null = (iframe[0] as HTMLIFrameElement).contentDocument;
const element: HTMLElement | null = content !== null ? content.documentElement : null;

console.log({ element, content, iframe });

return cy
.wrap(iframe)
.should(() => {
expect(element).not.null;

if (element !== null) {
expect(element.querySelector('#root > *')).not.null;
}
})
.then(() => {
return cy.wrap(element).get('#root');
});
});
};
21 changes: 21 additions & 0 deletions cypress/integration/knobs.spec.ts
@@ -0,0 +1,21 @@
import { clickAddon, 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')
.clear()
.type('John Doe');

cy.preview()
.console('info')
.find('p')
.eq(0)
.should('contain.text', 'My name is John Doe');
});
});