Cypress CI vsts not finding binary - cypress

Could you please give me some advise on how to deal with this issue.
Build Pipeline
npm install
package.json
"dependencies": {
"cypress": "^3.4.1"
}
Release
Powershell command
npm ./node_modules/.bin/Cypress run
The cypress npm package is installed, but the Cypress binary is missing.
2019-10-07T18:04:59.5720120Z We expected the binary to be installed here:
There are some examples on how to cache ~/.npm but nothing seems to work so far. Examples on how to include cypress.io in your vsts are at the building stage and not after release.

According to the error log, it has provided a solution about this. You should run the cypress install command first and then the error will be fixed.
As my test, since I don't have a cypress.json file, so I need run the open command to
automatic generated get the json file and project sample.
Then the open command run as expected.
But because I run the open command in interactive mode and I don't have the cypress.json file in my artifacts, the taks finally failed.
So if you have cypress.json in your repo or artifacts, you just need to add
.\cypress install
in your powershell command.
And if not, you can add the related json file and folder to your repo or artifacts and then the run command will work as your expected.

Related

Unknown file extension ".ts" cypress.config.ts on CI

When I run npm run cypress:run in my GitLab CI env I get the error:
Your configFile is invalid: //WebApp/cypress.config.ts
It threw an error when required, check the stack trace below:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for //WebApp/cypress.config.ts
test:cypress:
image:
name: cypress/included:10.3.1-typescript
entrypoint: ['']
stage: test
script:
- yarn install --frozen-lockfile
- cd WebApp
- npm run cypress:run
rules:
- *branch
If I run npm run cypress:run from the WebApp folder (where cypress.config.ts is in the root) locally I have no issue. Also no issues when I do an npx cypress:run
However, if I run npx cypress run --config-file WebApp/cypress.config.ts from the parent folder locally I do get the error:
Unknown file extension ".ts"
Any ideas why locally Cypress is working but on the CI the config file is incorrect?
This still seems to be an issues today for LTS 10.10.0
Changing the fresh install cypress.config.ts -> cypress.config.js
and use require like so proved successful.
module.exports = require('cypress').defineConfig({ component: {
devServer: {
framework: "create-react-app",
bundler: "webpack",
},
},
});
I updated this github issue with some more information.
This will be because you have typescript installed globally on your machine so it will work ok locally but not in CI.
Essentially typescript has to be in the folder from where the cypress command is run for it to detect typescript properly.
I went with:
script:
- npm install --global serve
- serve ./build --listen 3000 &
- rm package*
- npm install #percy/cypress typescript
- npm install --global #percy/cli
- percy exec --verbose -- cypress run
Just installing the bare minimum to run the e2e tests ./build is an artifact from another run and percy is really great if you have not used it before.
I am late here, i had similar issue. The del package to delete passed videos was the culprit for me. In the CI environment, it requested to install the del package separately, but in my cypress.config.ts, i was directly able to import del package which was served from third party.
I wanted to install the exact del package in my case and that solved the problem. Del package has its limitations, rimraf solved my issue.
https://www.npmjs.com/package/rimraf
It looks like it's about the version. This might be hepful GitHub
I have tried all different ways suggested in the GitHub issue that
user18025789 linked, but nothing helped. Then I tried switching the config file from .ts to cypress.config.js and it started to work (syntax needed to be updated to JavaScript as well). I have no idea why.
I came across this issue because Typescript was not installed in my Cypress container. When ts-node doesn't have access to typescript, it's require behaves like the native "require", which is why you're seeing the error.
I don't know enough about your specific setup to recommend a solution, but for me I was able to run npm i and mount the volume in the cypress container before running the tests. Another option could be to create a new Dockerfile to extend the base Cypress image with typescript included in the build.
If working on a monorepo and mounting only the app/package folder to test into the cypress docker image, not all dependencies are available within this directory.
To fix this mounting, the whole workspace does the job:
cypress:
image: cypress/included:10.11.0
# …
working_dir: /workspace/app
volumes:
- ..:/workspace
I started facing this issue, suddenly, My solution wasrm -rf node_modules package-lock.jsonnpm i I already had the cypress.config.ts file, so cypress test runner picked it up, when I rannpx cypress open

Is it possible to disable ESLint when running npm run build for a React app?

I have an app initiated using Create React App, so npm run build runs react-scripts build. I recently installed prettier and so added a .eslintrc.json file to the project root to load the prettier plugin. npm run build works as expected locally, but, when deploying the app to Heroku, npm run build tries to run ESLint and fails because the plugins are devDependencies rather than dependencies.
Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
From prior wrangling with a similar issue, I know that I can set NPM_CONFIG_PRODUCTION=false in Heroku so that it will install devDependencies, which actually does resolve the deployment issue. Nevertheless, I'm curious to learn if there's another solution that doesn't require setting NPM_CONFIG_PRODUCTION=false.
Is it possible to prevent npm run build in this scenario from running ESLint altogether or to prevent it from trying to access the plugins specified in .eslintrc.json? I acknowledge that adding .eslintrc.json to .gitignore is one solution, but I want the ESLint configuration in my repo.
you can run "npm run eject" to generate webpack configuration files, and then modify "webpack.config.js",delete the eslint configuration

Jenkins giving "The cypress npm package is installed, but the Cypress binary is missing." error while Running cypress Test

Hi I am Trying to run cypress test through Jenkins and am getting the test form my local m/c not form github and am Executing windows batch command
"./node_modules/.bin/cypress run --spec "cypress\integration\SignUpTestCases\NewUserSignUp.spec.js" in Bulid configuration.
and i am getting this error
C:\Users\akash\CypressAutomation>./node_modules/.bin/cypress run --spec "cypress\integration\SignUpTestCases\NewUserSignUp.spec.js"
The cypress npm package is installed, but the Cypress binary is missing.
We expected the binary to be installed here: C:\WINDOWS\system32\config\systemprofile\AppData\Local\Cypress\Cache\4.4.1\Cypress\Cypress.exe
Reasons it may be missing:
You're caching 'node_modules' but are not caching this path: C:\WINDOWS\system32\config\systemprofile\AppData\Local\Cypress\Cache
You ran 'npm install' at an earlier build step but did not persist: C:\WINDOWS\system32\config\systemprofile\AppData\Local\Cypress\Cache
Properly caching the binary will fix this error and avoid downloading and unzipping Cypress.
Alternatively, you can run 'cypress install' to download the binary again.
https://on.cypress.io/not-installed-ci-error
WHat is the problem here .....or pls tell me about cypress configuration with Jenkins!!!!
Please set up environment variable CYPRESS_RUN_BINARY and its value should be your cypress runner location. (the runner defauly localtion is ~/AppData\Local\Cypress\Cache)
the variable setting:
Name: CYPRESS_RUN_BINARY
Value:C:\Users\Administrator\AppData\Local\Cypress\Cache\4.8.0\Cypress\Cypress.exe
Or you can add the command in the jenkins job:
set CYPRESS_RUN_BINARY=C:\Users\Administrator\AppData\Local\Cypress\Cache\4.8.0\Cypress\Cypress.exe before run the cypress cases.
Your problem probably exists because you have node_modules added to your git repository.
Remove node_modules folder from your repository
add node_modules to .gitignore file.
commit changes, push them and try again.

Can't run Cypress Open

I recently took over a cypress project; running on windows. The first time I installed, all was working. Now, subsequent to upgrading node/electron/chrome, I can't open cypress with any command. Here's what I tried:
Delete node_modules directory in my project.
npm init Answered with all defaults. node_modules directory is present but empty.
npm install cypress --save-dev (from [the doc][1]). This populated my node_modules, but installed cypress in my account (users) directory.
node_modules\.bin\cypress open That reported:
It looks like this is your first time using Cypress: 3.1.1
Verified Cypress: [in my users dir]
Opening Cypress...
At that point I can see cypress in my process list, but the UI never shows. I can run headless tests normally, so I'm OK from a CI perspective, but I still want to open the UI with my tests locally. I can launch the cypress executable in my user dir and then open my project root directory manually, but can't run an open command normally. The scripts section of package.json doesn't seem to be designed to accept a path to an exe with params.
Is there another way to call open that I'm missing?
Solution: Go to your project directory which you installed cypress, in your package.json update the cypress version to the latest , look at the releases versions link, or just install the latest from cli:
npm install cypress#latest --save-dev
Reopen again and verify:
./node_modules/.bin/cypress open
//OR
npx cypress open
Did you upgrade the Electron version that Cypress uses? Cypress uses Electron 1.8.2 which is significantly behind the latest, and Cypress does not currently support newer versions of electron. See this Github issue for more info.
try starting with debugging enabled:
DEBUG=cypress:* ./node_modules/.bin/cypress open
I can't use command npm to open cypress neither,
but command npx works well.
So you can try this in your visual studio code: npx cypress open
Using this in my code solved the issue
cypress (folder) -->support --> index.ts
add this:
import './commands'
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from failing the test
return false
})
Didn't work for me as well. I got the same error. I've created new folder in the repo.
Run npm init -y
Run npm install --save-dev cypress
Then go to ./node_modules/.bin/cypress open
And boom the error.
I've workaround it by adding:
{
"scripts": {
"test": "cypress open"
}
}
into package.json
and run cypress with npm run test

Cannot get TeamCity Build Step to execute grunt-cli

I'm trying to automate building of my project on a TeamCity server. I'm using grunt to define and configure my tasks. This works fine locally. Yet, I am having problems getting TeamCity (running on Windows Server 2008) to recognize grunt as a executable, the build will fail when grunt is called as it is not available.
I do have grunt-cli installed on the server and can execute it when I login via ssh (The build script also succeeds when I trigger it that way).
I'm running npm install before I call grunt and also tried to force install grunt-cli using a preinstall instruction in my package.json like:
{
"name": "someName",
"version": "0.0.1",
"private": true,
"scripts" : {
"preinstall" : "npm install grunt-cli -g"
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.3",
"grunt-contrib-less": "~0.8.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-strip": "~0.2.1",
"grunt-bump": "0.0.11"
}
}
I can see npm installing grunt-cli, yet grunt is not available in the next step.
I also tried wrapping that into a bat file or using multiple build steps for dependency installing and running the grunt task.
Does anyone have any input on this?
I had the same problem when trying to get our TFS Build agents to run grunt-cli. In the end I just changed my build process to use the full path to the grunt-cli executable.
So I changed from using this:
grunt deploy
to using this:
"C:\Users\tfsservice\AppData\Roaming\npm\grunt.cmd" deploy
I know this is just a workaround and not a true fix, but it should be good enough to get you going. I hope this helps.
-- Update --
I was able to get it to work properly by simply adding "C:\Users\tfsservice\AppData\Roaming\npm" (where the grunt.cmd file is found) to my system path, and then rebooting my build server. The reboot was required since tfsservice is both a user and a running service; simply restarting the service may be enough, but I didn't test that.
After doing this grunt deploy worked in our builds as expected.
You are running Teamcity agent on Widnows Server?
There is plugin for Node.js/Grunt for Teamcity: https://github.com/jonnyzzz/TeamCity.Node
As far as I've used it had no issue running grunt with Teamcity.

Resources