How to run test files (NOT tests in file) sequentially? Variables between files are interconnected. Framework is Mocha - testing

How to run test files (NOT tests in file) sequentially? Variables between files are interconnected. Framework is Mocha
for example tree in spec:
test#1.js
test#2.js
First I need run test#2.js -> important variables will be store as global , then I need to use global variables from test#2.js
and run test#1.js
I did try this method https://www.npmjs.com/package/mocha-order-tests

Related

Getting environment variables at runtime in a compiled VueJS app

I'm working on a VueJS app that uses env vars in multiple places. It runs on GCloud with nginx serving the files compiled with vue-cli-service build.
When developing everything works well with the env vars set in .env.development and .env.development.local files and used in JS with process.env.VUE_APP_FOO. I'm not using .env.production as some of these env vars shouldn't be committed to our repository.
For the staging and prod environment of all of our projects, we use GCloud's config maps which let us provide env vars to the pods. The issue in this project is that vue-cli-service build requires the env vars to be available at build time, which is not the case in our setup. Config maps are only available in the pods that run the images.
Out of curiosity, I checked the compiled code and all uses of process.env are quite simply replaced by an object with all vue env vars (basic ones + VUE_APP_* ones). So for example,
console.log(process.env.VUE_APP_FOO);
is compiled to
console.log(Object({NODE_ENV: "production", BASE_URL: "/", VUE_APP_FOO: "bar"}).VUE_APP_FOO);
Except that in our case, VUE_APP_FOO is missing from the object as it's not available in the environment when building the app.
So as is, it doesn't seem possible to provide env vars when the server is started or the JS file is served. Is there a way to tell vue-cli-service to not compile the env that way? Or any other alternative?
The only one I found so far is to replace the uses of env vars with their actual value directly in the compiled JS file when the pod starts using sed, but that's pretty ugly and could break easily.
One approach you can follow is to provide the production values when building locally. Another approach is to setup a continuous integration workflow that fetches your environment variables from wherever it is stored, builds the apps and pushes to production servers. I personally work with approach 2.
It is relatively easy to setup a github workflow that runs whenever your code is pushed to a particlar branch

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

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

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.

Testing using local files

I'm looking for what best practice I should use when it comes to testing with Go using local files.
By using local files, I mean that in order to test functionality, the application needs some local files, as the application reads from these files frequently.
I'm not sure if I should write temporary files myself just before running the tests using the ioutil package tempdir and tempfile functions, or create a test folder like so;
testing/...test_files_here
main.go
main_test.go
and then read from the contents inside
testing/...
A folder named testdata is usually used for this purpose as it is ignored by the go tool (see go help packages).
This is my current test setup:
app/
main.go
main_test.go
main_testdata
package1/
package1.go
package1_test.go
package1_testdata1
package2/
package2.go
package2_test.go
package2_testdata1
All the test data that is specific to a single package, is placed within the directory of that package. Common test data that will be used by multiple packages are either placed in the application root or in $HOME.
This set up works for me. Its easy to change the data and test, without having to do extra typing:
vim package1_test_data1; go test app/package1

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.