Skip to content

Commit

Permalink
Storybook v8 upgrade (#940)
Browse files Browse the repository at this point in the history
* Initial changes for Storybook v8

* Supporting multiple versions of storybook in tests

* Fixing jackspeak issue

* Lint fixes

* Running all tests

* Formatting fixes

* Making lint job node 18

* Removing dependency of storybook version
  • Loading branch information
rishigupta1599 committed May 7, 2024
1 parent 93e4c56 commit 1e64e21
Show file tree
Hide file tree
Showing 20 changed files with 3,396 additions and 3,546 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
- uses: actions/checkout@8459bc0c7e3759cdf591f513d9f141a95fef0a8f
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}/node-16/${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}/node-16/
key: ${{ runner.os }}/node-18/${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}/node-18/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@8459bc0c7e3759cdf591f513d9f141a95fef0a8f
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: yarn
- run: yarn build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-storybook-v6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [14]
node: [18]
runs-on: ${{ matrix.os }}
steps:
- uses: actions-ecosystem/action-regex-match@9e6c4fb3d5e898f505be7a1fb6e7b0a278f6665b
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: ./prepare-storybook-v6-tests.sh
- run: ./prepare-storybook-tests.sh 6
- uses: actions/cache@v3
with:
path: node_modules
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test-storybook-v7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [16]
node: [18]
runs-on: ${{ matrix.os }}
steps:
- uses: actions-ecosystem/action-regex-match@9e6c4fb3d5e898f505be7a1fb6e7b0a278f6665b
Expand All @@ -29,6 +29,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: ./prepare-storybook-tests.sh 7
- uses: actions/cache@v3
with:
path: node_modules
Expand All @@ -54,4 +55,4 @@ jobs:
yarn link `echo $PERCY_PACKAGES`
npx percy --version
- run: yarn test:coverage
- run: yarn test
57 changes: 57 additions & 0 deletions .github/workflows/test-storybook-v8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Test
on:
push:
workflow_dispatch:
inputs:
branch:
required: false
type: string
default: master
jobs:
test:
name: Test Storybook v8
strategy:
matrix:
os: [ubuntu-latest]
node: [18]
runs-on: ${{ matrix.os }}
steps:
- uses: actions-ecosystem/action-regex-match@9e6c4fb3d5e898f505be7a1fb6e7b0a278f6665b
id: regex-match
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
text: ${{ inputs.branch }}
regex: '^[a-zA-Z0-9_/\-]+$'
- name: Break on invalid branch name
run: exit 1
if: ${{ github.event_name == 'workflow_dispatch' && steps.regex-match.outputs && steps.regex-match.outputs.match == '' }}
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}/node-${{ matrix.node }}/${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}/node-${{ matrix.node }}/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
- run: yarn build
- name: Set up @percy/cli from git
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
cd /tmp
git clone --branch ${{ inputs.branch }} --depth 1 https://github.com/percy/cli
cd cli
PERCY_PACKAGES=`find packages -type d -mindepth 1 -maxdepth 1 | sed -e 's/packages/@percy/g' | tr '\n' ' '`
echo "Packages: $PERCY_PACKAGES"
git log -1
yarn
yarn build
yarn global:link
cd ${{ github.workspace }}
yarn link `echo $PERCY_PACKAGES`
npx percy --version
- run: yarn test:coverage
5 changes: 3 additions & 2 deletions babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module.exports = {
['@babel/env', {
modules: false,
targets: {
node: '14'
node: '18'
}
}]
}],
'@babel/preset-react'
],
env: {
test: {
Expand Down
19 changes: 19 additions & 0 deletions babel.config.old.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
presets: [
['@babel/env', {
modules: false,
targets: {
node: '18'
}
}]
],
env: {
test: {
plugins: [
['istanbul', {
exclude: ['dist', 'test']
}]
]
}
}
};
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
]
},
"dependencies": {
"@percy/cli-command": "^1.24.0",
"@percy/cli-command": "^1.28.5",
"cross-spawn": "^7.0.3",
"qs": "^6.11.0"
},
Expand All @@ -64,8 +64,10 @@
"@babel/eslint-parser": "^7.19.1",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.22.9",
"@storybook/react": "^7.5.0",
"@storybook/react-webpack5": "^7.5.0",
"@babel/preset-react": "^7.24.1",
"@storybook/react": "^8.0.9",
"@storybook/react-webpack5": "^8.0.9",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"babel-eslint": "^10.0.3",
"babel-plugin-istanbul": "^6.1.1",
"cross-env": "^7.0.3",
Expand All @@ -82,6 +84,9 @@
"nyc": "^15.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.5.0"
"storybook": "^8.0.9"
},
"resolutions": {
"jackspeak": "2.1.1"
}
}
2 changes: 1 addition & 1 deletion packageV6.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
]
},
"dependencies": {
"@percy/cli-command": "^1.24.0",
"@percy/cli-command": "^1.28.5",
"cross-spawn": "^7.0.3",
"qs": "^6.11.0"
},
Expand Down
90 changes: 90 additions & 0 deletions packageV7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"name": "@percy/storybook",
"version": "5.0.3",
"description": "Storybook addons for visual testing with Percy",
"keywords": [
"storybook",
"addon",
"visual",
"visual-testing",
"layout-testing",
"percy",
"image-testing",
"test"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/percy/percy-storybook.git"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"engine": {
"node": ">=14"
},
"files": [
"bin",
"dist"
],
"bin": {
"percy-storybook": "./bin/percy-storybook.cjs"
},
"main": "./dist/index.js",
"exports": "./dist/index.js",
"type": "module",
"scripts": {
"build": "babel src --out-dir dist",
"clean": "git clean -Xdf -e !node_modules -e !node_modules/**",
"lint": "eslint --ignore-path .gitignore .",
"readme": "percy-cli-readme",
"pretest": "storybook build --config-dir=./test/.storybook --output-dir=./test/.storybook-build --loglevel error",
"test": "yarn test:env jasmine --config=./test/jasmine.json",
"test:env": "cross-env NODE_ENV=test NODE_OPTIONS='--loader=./test/loader.js'",
"test:coverage": "nyc yarn test"
},
"storybook": {
"displayName": "Percy",
"icon": "https://avatars.githubusercontent.com/u/12260884"
},
"@percy/cli": {
"commands": [
"./dist/storybook.js"
]
},
"dependencies": {
"@percy/cli-command": "^1.28.5",
"cross-spawn": "^7.0.3",
"qs": "^6.11.0"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.19.1",
"@babel/eslint-plugin": "^7.19.1",
"@babel/preset-env": "^7.22.9",
"@storybook/react": "^7.5.0",
"@storybook/react-webpack5": "^7.5.0",
"babel-eslint": "^10.0.3",
"babel-plugin-istanbul": "^6.1.1",
"cross-env": "^7.0.3",
"eslint": "^8.51.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^15.4.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"jasmine": "^4.5.0",
"jasmine-spec-reporter": "^7.0.0",
"mock-require": "^3.0.3",
"nock": "^13.2.9",
"nyc": "^15.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.5.0"
},
"resolutions": {
"jackspeak": "2.1.1"
}
}
24 changes: 24 additions & 0 deletions prepare-storybook-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

storybook_version="$1"

# Check if the version is passed to script
if [ -z "$storybook_version" ]; then
echo "Error: Storybook version is required"
exit 1
fi

# Versions supported
versions=(6 7)

# Performing common steps

if [[ " ${versions[*]} " =~ " $storybook_version " ]]; then
# move package and storybook configs
mv "./packageV$storybook_version.json" "./package.json"
mv "./test/.storybook/mainV$storybook_version.js" "./test/.storybook/main.js"
mv "./babel.config.old.cjs" "./babel.config.cjs"
else
echo "The value $storybook_version is not a supported version."
exit 1
fi
5 changes: 0 additions & 5 deletions prepare-storybook-v6-tests.sh

This file was deleted.

1 change: 0 additions & 1 deletion src/snapshots.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { logger, PercyConfig } from '@percy/cli-command';
import { yieldAll } from '@percy/cli-command/utils';
import qs from 'qs';

import {
fetchStorybookPreviewResource,
evalStorybookEnvironmentInfo,
Expand Down
4 changes: 2 additions & 2 deletions src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export const start = command('start', {
let { host, port } = flags;
let storybookVersion = await checkStorybookVersion();

let args = storybookVersion === 7 ? ['dev'] : [];
let args = storybookVersion >= 7 ? ['dev'] : [];
args = args.concat(['--ci', `--host=${host}`, `--port=${port}`, ...argv]);

let storybookBinary = storybookVersion === 7 ? 'storybook' : 'start-storybook';
let storybookBinary = storybookVersion >= 7 ? 'storybook' : 'start-storybook';

log.info(`Running "${storybookBinary} ${args.join(' ')}"`);

Expand Down
Loading

0 comments on commit 1e64e21

Please sign in to comment.