How to group together certain tests or files when doing a run in Cypress? - automation

I am currently running Cypress and I have folders inside of it, where I have tests located for different applications.
I have a folder entitled "smhw-qa" which contains sub-folders and tests files for this specific application.
This directory apps will also include other applications too in future.
What I wish to do
In order to avoid having to run every test for a run, I wish to only run this specific folder. The location of the folder is as such:
'cypress/integration/apps/smhw-qa'
Over time, there will be more folders and tests added to the apps directory.
I am familiar with how to run a specific file, so doing the following works:
npx cypress run --spec 'cypress/integration/apps/smhw-qa/banners_promos_global/global_search.js'
How can I specify to Cypress which folder to run specifically when I use the npx cypress -run command?
What I have tried already
To run a specific test file I tried:
npx cypress run --project 'cypress/integration/apps/smhw-qa'
But this provides an error instead:
Can't run because no spec files were found.
We searched for any files inside of this folder:
/Users/jaswindersingh/Documents/cypress-automation/automation/cypress/integration/apps/smhw-qa/cypress/integration
Running specific sets of tests by their folders will be much easier for me, and will save time when running a specific suite of tests on our CI platform for example. I will also not need to specify the individual files since this is time-consuming.
It would also mean I can split out my tests and run them on different machines
Do I need to put anything into my test files, or inside of cypress.json or modify anything else, or can this be achieved through the terminal?
What options must I use instead?
Thanks

I think the clue is in the error message, you call
cypress/integration/apps/smhw-qa
and the error message shows
cypress/integration/apps/smhw-qa/cypress/integration
so to use the --project flag you need to replicate the /cypress folder per project, as per this example cypress-test-nested-projects
Folder structure:
package.json
node_modules
src/
clients/
foo/
cypress.json
cypress/
bar/
cypress.json
cypress/
However, I think you might want to use the --spec flag instead. If I understand it correctly, the glob pattern will allow you to keep the current folder structure. Docs
cypress run --spec 'cypress/integration/apps/smhw-qa/**/*'

Through --project you can manage different cypress.json files, the docs says
This enables you to install Cypress in a top level node_modules folder but run Cypress in a nested folder. This is also helpful when you have multiple Cypress projects in your repo.
so you're on the right way, just prepare some project-related cypress.json files

Related

Should i delete webpack and other libraries after bundling?

NPM donwloads a lot of files needed for the webpack/libraries. From what i understand, webpack generates a one single bundle file, that contains all code for script working. After that, when i finish building my app, do i need to keep all those jquery/react files and webpack itself? Or should i just delete them?
It's common practice to make a project portable/shareable by following these steps;
Create a package.json and ensure to capture all dependencies,devDependencies and/or peerDependencies.
Add/commit this package.json and package-lock.json files to your version control
Create a .gitignore file and add node_modules to it (in essence, this cuts out that baggage)
For production purpose (e.g. to be shared with client finished product), build the project (which often results into a small files, often within /build or dist). And then you can always push that build file to AWS or Heroku or the clients' servers.
What does the above help you achieve?
You can easily start the project using any machine, as long as you run npm install which reads from your package.json.

How can I run all test files that are in different folders using mocha?

I want to run my mocha test using npm test the problem is that the tests may vary their location.
The locations may be lib/modules/somefolder/test/*-test.js or lib/modules/somefolder/anotherfolder/test/*-test.js
Currently my test script is like this node_modules/.bin/mocha lib/modules/*/test/*-test.js --reporter spec but this won't find the test files located in the second location.
Is there any way to find the tests in both locations?
You should be able to accomplish this by doing ./**/*-test.js. This should find any files with -test.js in the name in any directory relative to the one you are in.

Gogland Test Configuration always executed with ./

No matter how I set my build configuration for running my tests the go test tool is always run with ./...
E.G.
runs:
go test -v -cover ./... -run ./svs
Depending on what you need to run you can select different configuration types.
For the one in your picture, Run Kind Directory is selected and that means the IDE will run the tests in the directory you point it at and since the working directory is in the same directory, it will run ./... as that's what it means.
For the Run Kind Package, it will run only the specified package and no other packages, so no /... appended to it.
For the Run Kind File it will run the tests in a single file.
The pattern that you've added, ./svc tells the go tool how to match test names. There you should put valid patterns for test names. If you want to control for which directory / package the tests are run you can use a different run configuration per directory / package since multiple configurations are possible.
Based on your reply you want to run the tests in your whole projects, recursive, without the vendor folder. To do so, create a Run Kind Directory, as you have one already, and make sure sure you are using Go 1.9 as it will automatically ignore the vendor directory when using ./... matching.
Please let me know if you need further details.

How do you run `go test` when test files are within a module?

When you have pulled in a module, into your project, how do you run test cases within that module?
i.e. I have done:
go get my.repo.com/repo/mymodule
And then try to test something in it:
server> go test src/my.repo.com/repo/mymodule/my_test.go
# command-line-arguments
src/my.repo.com/repo/mymodule/article_test.go:4:2: cannot find package "mymodule" in any of:
Are we supposed to check out our modules separately and test that way? I can't quite work out what to do. It seems that when I go run it knows how to find the module I have fetched, but when I go test, it "can't find it" in the path.
go test expects packages, not folders relative to $GOPATH.
So leave out the leading src/ and the trailing file name, and it'll work:
go test my.repo.com/repo/mymodule
If the current directory is the package folder you want to test, you can even omit it, e.g.
cd $GOPATH/src/my.repo.com/repo/mymodule
go test
For reference see Command go / Test packages, also run
go help test

dart pub test... can you exclude files / directories?

dart/pub v1.10
I have a test/e2e folder that has webdriver.dart tests. 'pub run test' is trying to run the dart files in e2e.
pubspec.yaml
dev_dependencies:
test: '>=0.12.1 <0.13.0'
I've been running the webdriver.dart test as
dart test/e2e/some_test.dart
Was hoping pub/test implemented a transformer... so I just just exclude it in pubspec.yaml. No joy. Can I build a transformer for test?
Ideas? (besides moving the directory out from under test :-))
update
looks like my options are:
pub run test test/unit (specify the directory)
move the e2e folder out of 'test'
You can filter tests using the --name=xxx (where xxx can be a regular expression) or the --plain-name=xxx (just substring comparsion) parameters to filter tests. There is an open issue to add tags as well but I don't know if this is actually planned.
I don't know what you expect a transformer to do. If you use includes/excludes to the transformer configuration this specifies only which files are processed by the transformer but not which files are executed.