How to run jest files that have no .test. in their filename? - jestjs

I have some tests that are ment to be run aside from all other .test files so I called them .integration.js
how to test all files that have .integration.js?
example file;
endpoint.integration.js

You can configure custom test file names with the config key testRegex.
https://jestjs.io/docs/en/configuration#testregex-string--arraystring
The default is: (/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$
So to only run tests in files like endpoint.integration.js tests, you can use this regex instead: \\.integration\\.js$
You can put this in your configuration either in package.json or jest.config.js.
Or you can use the regex as the first argument to the jest cli command.
jest '\\.integration\\.js$'

Related

How can I get rid of the "Warning: Invalid configuration encountered" in serverless.yml?

Currently I'm trying to breakdown my serverless service into multiple services to get over the cloudFormation resource limit.
My current project structure is as follows:
aws-backend
functions
workers
serverless.yml // workers service
.env.local
.env.dev
serverless.yml // Rest of the functions in here
In my workers service, I'm trying to reference the .env.* files in the root folder using variables.
My issue is when i use the following syntax
${env:SLS_AWS_REGION}
I get a
Error:Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.region": Value not found at "env" source
but when I use the following syntax:
${../../env:SLS_AWS_REGION}
It works but I get a warning:
Warning: Invalid configuration encountered
at 'package.individually': must be boolean
at 'provider.region': must be equal to one of the allowed values [use-east-1, etc...]
How can I get rid of this error? Am I even using the correct syntax?
Thanks
as for this error
Error:Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.region": Value not found at "env" source
You get this error because the Framework cannot find SLS_AWS_REGION environment variable. The env variable source doesn't read from .env files, but from environment variables from the process.
As for this syntax:
${../../env:SLS_AWS_REGION}
This does not work because env is a correct variable source, not ../../env.
You have two options here:
Ensure that content of the .env file(s) is exported so the variables defined in these files are actually exported as environment variables before running serverless commands.
Set useDotenv: true in your serverless.yml file so the .env files will be loaded automatically with dotenv. Please see the docs for reference on how it works: https://www.serverless.com/framework/docs/environment-variables
According to the plugin documentation, you should run sls deploy with --stage or --env (deprecated in Serverless >=3.0.0) or NODE_ENV corresponding to the .env file name. If you run it without any of those flags, it will default to development, and the plugin will look for the plugin will look for files named .env, .env.development, .env.development.local
Note that Serverless Framework .env files resolution works differently to the plugin.
The framework looks for .env and .env.{stage} files in service directory and then tries to load them using dotenv. If .env.{stage} is found, .env will not be loaded. If stage is not explicitly defined, it defaults to dev.
I believe the plugin takes precedence here.

pytest test with --ignore and --junitxml generate xml with ignored tests

I am using pytest with --ignore and --junitxml options to generate a report of the test cases those are not ignore but when my report is generated, It also takes into account the ignored tests.
I am using the following command
pytest --ignore=tests/test_a.py --junitxml=pytest_not_a.xml
I am able to resolve this using pytest.mark.httpapi, so rather than using it over each test suite. I added pytest_collection_modifyingitems which puts the marker on the test on run time.
def pytest_collection_modifyitems(config, items):
for item in items:
if 'test_a.py' in str(item.fspath):
mark = getattr(pytest.mark, "httpapi")
item.add_marker(mark)
item.add_marker(pytest.mark.common)
Now the above command would be slightly changed like
py.test -v -m "not httpapi" --junitxml=pytest_not_a.xml. Now the Junit gitlab artifacts only takes the processed tests and do not include skipped tests in success rate calculation.

How to run specific test suite in jest-puppeteer

I wanted to run specific test suite in jest-puppeteer for UI automation.
I am able to run the specific test using below.
jest -t test_name
where test_name is from the "it" not from "describe" without quote.
Is there any other cmd to run all the test under describe too.
Run tests that match this spec name (match against the name in describe or test, basically).
jest -t name-of-it
jest -t "name-of-describe"

Can we run multiple yml files using serverless offline plugins

I have multiple yml files in different folder then how I run locally all those files using serverless offline plugins?
If I'm understanding your question correctly, you have a structure something like this:
./
serverless.yml
/more-yml
/functions
lambda-x.yml
lambda-y.yml
lambda-z.yml
/resources
resource-a.yml
resource-b.yml
You can write a script which parses all these files, runs any validations you may want on the items within, and returns a file for serverless.yml to use, so that your serverless.yml might look like this:
service: your-service
provider:
...
resources: ${file(./scripts/serverless/join-resources.js)}
functions: ${file(./scripts/serverless/join-lambda-functions.js)}
All this scripts (or scripts) need to do is loop over a given directory, load the yml, concat each file's yml to a temp file, then resolve with that temp file!

How to run unit test subset in Mocha framework?

I use mocha --recursive --timeout 15000 CLI command to run all test placed in /test local folder. How can I target specific folder ?
There are quite a few options here depending on exactly what you need, imho straight execution based on path gets a bit cumbersome.
Directory based segregation of tests
Everything in a directory - mocha test/<folderPath>/*.js
Everything including sub-directories - mocha test/<folderPath>/**/*.js
Pattern matching for suites ( or tests )
Suite - mocha --grep <suiteName>
Pattern Match - mocha --grep <pattern>
Negative Pattern matching for suites ( or tests )
Suite - mocha --grep <suiteName> --invert
Pattern Match - mocha --grep <pattern> --invert
Tagging
You can also execute test based on tags within the it() portion of the test.
Tagging uses the --grep feature which also allows for negative tag matching.
More can be found here - https://github.com/mochajs/mocha/wiki/Tagging
You can just run:
mocha path-to-dir/**/*.js --timeout 15000
The two ** are the same as --recursive

Resources