我一直在努力根据percyPERCY_TOKEN
的官方指南设置本地测试运行并通过.yarn
该指南说:
$ PERCY_TOKEN=aaabbbcccdddeeefff PERCY_BRANCH=local npm test
我现在的尝试是这样的:
包.json
...
"scripts": {
"start": "react-scripts -r @cypress/instrument-cra start",
"start:silent": "BROWSER=none yarn start",
"start:server": "start-server-and-test start:silent http://localhost:3000",
"build": "react-scripts build",
"eject": "react-scripts eject",
"envGenerateExample": "cat .env | sed 's/=.*/=/g' > .env.example",
"jest:test": "react-scripts test --env=jest-environment-jsdom-sixteen",
"cy:run": " 'yarn start:server './node_modules/.bin/cypress run'",
"cy:open": "yarn start:server './node_modules/.bin/cypress open'",
"cy:ci": "yarn start:server cy:chrome",
"cy:chrome": "cypress run --browser chrome --record",
"percy:exec": "yarn percy exec -- cypress run",
"cy:percy": "yarn start:server percy:exec",
"percy:local": "PERCY_TOKEN=$(grep 'PERCY_TOKEN.*' .env | sed 's/.*=//'); PERCY_BRANCH=local;",
"cy:percy:local": "yarn percy:local && yarn start:server percy:exec"
},
...
$ yarn cy:percy:local
Compiled successfully!
You can now view playground in the browser.
Local: http://localhost:3000
On Your Network: http://192.168.1.163:3000
Note that the development build is not optimized.
To create a production build, use yarn build.
...
> playground@0.2.0 percy:exec /Users/norfeldt/Repos/playground
> yarn percy exec -- cypress run
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ /Users/norfeldt/Repos/playground/node_modules/.bin/percy exec cypress run
› Warning: Skipping visual tests. PERCY_TOKEN was not provided.
...
TL;DR 解决方案
包.json
...
"scripts": {
"start": "react-scripts -r @cypress/instrument-cra start",
"start:silent": "BROWSER=none yarn start",
"start:server": "start-server-and-test start:silent http://localhost:3000",
...
"percy:local": "PERCY_TOKEN=$(grep 'PERCY_TOKEN.*' .env | sed 's/.*=//') PERCY_BRANCH=local yarn start:server 'percy exec cypress run'"
},
...