Could not find Cypress test run results - vue.js

I created a new Vue project via npm init vue#latest and selected Cypress.
Currently there are no tests yet, I have a placeholder test /cypress/e2e/example.cy.ts with
describe("My First Test", () => {
it("visits the app root url", () => {
cy.visit("/");
});
});
I'm using Cypress v11.0.1 and have a script to run the cypress tests inside my Github Actions
"test:e2e:ci": "start-server-and-test preview :4173 'cypress run --e2e'",
This is my Cypress action
- name: Check if e2e tests are passing
uses: cypress-io/github-action#v4
with:
build: npm run build
start: npm run test:e2e:ci
Sometimes ( it occurs very rarely ) the Github workflow fails with
As you can see the test itself passes. I can fix the pipeline by running it again...
Does someone know why this happens and how to avoid this error?
Please let me know if you need more information ( e.g. configuration files )

Related

Not Found Error on localhost:3400 on Github Actions

So I want to build and run my svelte application on Github Actions (and the fastapi backend) and then do cypress tests on them. Running fastapi backend works so far.
The Problem is even when npm logs
Your application is ready~! 🚀
- Local: http://localhost:3400
cypress get's a not found error on cy.visit(). I also tried just waiting on localhost:3400 (for 120 seconds) but this doesn't work either.
In my main.yml looks like this:
- name: Build and run Svelte app
run: |
npm install cypress
cd frontend/app
npm install
npm run build
npm run start &
sleep 120
cd ..
cd ..
npx cypress run
Does anyone has a clue why this happens? Has been very frustrating.
Later I want to auto dockerize and deploy. Should I already go on with this, so maybe it gets easier once it's dockerized?

How to pass Bitbucket pipeline repository variables to npm run script?

How do I pass a Bitbucket repository variable into the Cypress.io test script that I am running with npm run in a pipeline?
The pipeline and tests work, but I am unable to get a Bitbucket variable into the test file iteself. I can access the respository variable from bitbucket-pipeline.yml following the instructions provided by Bitbucket on the repository variable page, but I cannot access the variable inside of cypress/integration/example.js. I want to store credentials the test scripts use as Bitbucket repository variables.
Here's my code...
bitbucket-pipeline.yml
image: cypress/included:3.2.0
pipelines:
custom:
robot:
- step:
script:
- printenv
- npm ci
- npm run e2e
uses an image provided by Cypress
I can see my repository variables via printenv
package.json
{
...
"scripts": {
"e2e": "cypress run"
},
...
"dependencies": {
"cypress": "^9.4.1"
}
}
cypress/integration/example.js
describe('A', () => {
it('should B', () => {
cy.visit('https://google.com');
});
});
I want to use the Bitbucket repository variable inside of the it('should B' ...) method.
Thanks in advance for your help.
I found the Cypress.io documentation on environment variables:
https://docs.cypress.io/guides/guides/environment-variables
bitbucket-pipeline.yml
image: cypress/included:3.2.0
pipelines:
custom:
robot:
- step:
script:
- npm ci
- export CYPRESS_example=$example
- export CYPRESS_whatever=$whatever
- npm run e2e
Where example is the name of the Bitbucket repo variable. Might be case sensitive.
Add $ to reference the Bitbucket repository variable in the bitbucket-pipeline.yml file.
Use CYPRESS_ to identify it as a Cypress environment variable.
https://docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_
Then you can use it in the test spec via Cypress.env("example")
I actually had to typecast because Bitbucket was providing unexpected data types...
cy.get('[name="password"]').clear().type(Cypress.env("example").toString());
You can use the plugin to have a profiles for each deployment and when run the script you can set which env to run the script for example below would work if plugin setup properly inside the pipeline.
npx cypress run --env version="qa"
npx cypress run --env version="prod"

Nuxt: Command 'nuxt' not found - Output directory `dist/` does not exists

I have successfully created a Nuxt.js project with this configuration using the CLI:
Project name: test
Programming language: JavaScript
Package manager: Npm
UI framework: None
Nuxt.js modules: None
Linting tools: None
Testing framework: None
Rendering mode: Single Page App
Deployment target: Static (Static/JAMStack hosting)
Development tools: jsconfig.json
Version control system: Git
The developement server runs properly with npm run dev.
npm run build also runs without errors and tells me that:
Ready to run nuxt generate
But the execution of nuxt generate leads to the error Command 'nuxt' not found. This is strange because nuxt seems to be installed when I execute npm nuxt list.
I first reinstalled just nuxt and then all dependencies after deleting the node_modules/ folder, but the error remains the same. If I just run npm run start it tells me
Nuxt Fatal Error
Error: Output directory `dist/` does not exists, please use
`nuxt generate` before `nuxt start` for static target.
This is strange again because the .nuxt/dist/ folder exists.
Does anyone have an idea what is going wrong?
I have solved the problem. For me it works if I run npm run generate instead of nuxt generate.

When I run cypress as npm run cypress run build fails

I have installed cypress using npm as npm install cypress --save-dev .
I used the same command in .gitlab-ci.yml file
When i run the command npm run cypress run locally , IDE opens and when i double click the spec.js file , then the tests run.
But I i use the same command on the gitlab pipeline , it says
cypress open "run"
It looks like this is your first time using Cypress: 4.1.0
[07:45:16] Verifying Cypress can run /osmc/ux/framework-acceptance-tests/cache/Cypress/4.1.0/Cypress [started]
[07:45:18] Verifying Cypress can run /osmc/ux/framework-acceptance-tests/cache/Cypress/4.1.0/Cypress [completed]
Opening Cypress...
and build fails .
Am i missing anything here ?
It's because it's opening the test runner, which is used locally via npx cypress open.
From that output it looks like you're running npx cypress open run, which isn't a real command and will open the runner
In CI you need to use npx cypress run, which will run tests without user interaction. https://docs.cypress.io/guides/guides/command-line.html#How-to-run-commands
Your gitlab.yml file should accomodate for the npm installations.
One example is as below. Meanwhile also please check the test/run command for your specs under package.json file. use the same command to trigger the test in pipeline.
stages:
- test
test:
image: cypress/browsers:node12.14.1-chrome85
stage: test
script:
npm i
npm run start:ci &
npx cypress run
You should have your .gitlab-ci.yml with:
stages:
- test
cypress-test:
image: cypress/browsers:node16.14.0-slim-chrome99-ff97
stage: test
script:
- npm ci
- npx cypress run

SailsJS how to setup Mocha Test Framework?

I want to add tests to my SailsJS project, Mocha is pretty common so I decided to use it.
I configured and registered the grunt-mocha-test to run my tests when the "default" task trigger (tasks/register/default.js) runs, but it is not running anything!
How to properly configure and setup Mocha into SailsJS to run automatically with grunt?
Is it possible to run the tests manually?
Here is what I did:
1) install test packages
npm install mocha --save-dev
npm install grunt-mocha-test --save-dev
npm install sinon --save-dev
npm install assert --save-dev
3) added file tasks/config/mocha-test.js
module.exports = function(grunt) {
grunt.config.set('mochaTest', {
test: {
options: {
reporter: 'spec'
},
src: ['tests/**/*.spec.js']
}
}),
grunt.loadNpmTasks('grunt-mocha-test');
};
**3) registered tasks in tasks/register/default.js **
module.exports = function (grunt) {
grunt.registerTask('default', ['compileAssets', 'linkAssets', 'watch', 'mochaTest']);
};
2) created tests folder in the app root
tests/controller/session.spec.js
var SessionController = require('../../api/controllers/SessionController'),
sinon = require('sinon'),
assert = require('assert');
console.log('SessionController: ', SessionController);
describe('The SessionController', function () {
describe('When we load the signIn page', function () {
it ('should render the view', function () {
var view = sinon.spy();
SessionController.index(null, {
view: view
});
assert.ok(view.called);
});
});
});
I don't know that setting up a Grunt task to run your Mocha tests is the best solution. The Grunt tasks in the Sails "pipeline" are run every time you do sails lift; running your tests every time you lift the server could become very annoying as you add more tests to your suite, because you tend to do sails lift a lot during development!
You certainly can run the tests manually; you just need to install Mocha globally:
sudo npm install -g mocha
Then in your app's root directory, simply type mocha to run all the tests under /test. You can specify a subset of tests to run by giving the command a subdirectory, e.g. mocha test/controller.
As far as the tests themselves are concerned, it's possible to unit test a controller by requiring it the way you're doing, but it means you'll have to mock up request and response objects. A better way is to lift a Sails instance in your before function, and then make HTTP requests to your controllers. See answers to this question for a couple of examples of lifting Sails from within tests, either before every test or before each test. You can then use the Node http module to make requests to your controllers, or make life easier on yourself and use the request module.