When I prefix test folders with special characters - e.g. /src/tests/+something/a.spec.ts or /src/tests/$something/a.test.ts - the tests are not discovered. I tried to adjust testMatch to wildcard anything but Jest still does not find the tests.
Is there anything particular that needs to be set to support folder with special characters with Jest?
❯ npm run test /Users/david/app/src/tests/\\+public/app.services.spec.ts
dapp#2.0.3 test
TZ=UTC jest /Users/david/app/src/tests/\+public/app.services.spec.ts
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/david/app/
1015 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 260 matches
testPathIgnorePatterns: /node_modules/ - 1015 matches
testRegex: - 0 matches
Pattern: /Users/david/app/src/tests/\+public/app.services.spec.ts - 0 matches
Related
I have following tests
libs/app1/e2e/my-e2e-tests.spec.ts
libs/app1/uat/my-uat-test.spec.ts
libs/app2/e2e/my-e2e-tests.spec.ts
libs/app2/uat/my-uat-test.spec.ts
I want a command to run all uat and e2e tests under libs/app1. Tried the following
jest --testPathPattern=libs/app1/**/*.spec.ts
But above command only run the first match which is 'libs/app1/e2e/my-e2e-tests.spec.ts'.
I also tried to provide a regular expression
jest --testPathPattern=/libs\/app1\/[a-z]*\/[a-z]*.spec.ts/ig
testPathPattern uses a regexp pattern, not a glob pattern. Remove the /**/*.spec.ts part.
Try (macOS):
$ npx jest --testPathPattern=libs/app1
PASS libs/app1/e2e/my-e2e-tests.spec.ts
PASS libs/app1/uat/my-uat-test.spec.ts
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.685 s, estimated 20 s
Ran all test suites matching /libs\/app1/i.
gitlab has introduces rules and changes that allow specifying jobs to run when changes occur.
I wonder how can I configure the job to be skipped or ignore a path?
For example, I want to run the ci for any change unless it is a change in the docs path.
If a change occured both in the src and docs then the job should be executed,
but if the change was only in the docs folder, then the job should not be executed.
Update 2
GitLab uses globs for their rules: changes. There is no direct way of excluding folders in standard globs, but we can work around it and include everything except files in the folder docs:
myjob:
script: build myproject
rules:
- changes:
- "*"
- "?/**/*"
- "??/**/*"
- "???/**/*"
- "[^d]???/**/*"
- "?[^o]??/**/*"
- "??[^c]?/**/*"
- "???[^s]/**/*"
- "?????*/**/*"
when: on_success
The first * matches all files. The second to forth glob lines matches everything in folders that have 1-3 characters. The fifth line matches everything inside of folders that are four characters long, except if it starts with a d. The line after this matches all folders that are four characters long, except if the second char is a o. The two next lines does the same for c and s, and together these four lines matches all folders that have four characters, except docs.
The last line matches everything inside of folders that are five or more characters long.
Update
When I understood the question properly:
myjob:
script: build myproject
rules:
- changes:
- docs/**/*
when: never
- when: on_success
This job is skipped if there are changes to docs, and otherwise it behaves as a normal job and is run if all jobs from the previous stage has succeeded.
Old answer
Something like this should work:
myjob:
script: build myproject
rules:
- changes:
- src/**/*
when: on_success
- changes:
- docs/**/*
when: never
The rules are evaluated from top to bottom. If there are changes to any file in the src directory, the job will get the attribute when: on_success. This is the default for GitLab jobs, and means that this job will be executed if all jobs of the previous stage has been executed.
If the first rule doesn't match, the second job will be evaluated. If there are any changes to the docs folder, the job will get the attribute when: never, and the job will never execute.
The second rule could be changed to:
- when: never
But I imagine that your real task is a bit more complicated that your question, and that you might need this whole rule.
I'm cloning the following repository and making one change to the stack.yaml by adding at the end:
docker:
enable: true
To run all the tests for haskoin-core I'm using
stack test haskoin-core:test-haskoin-core
What I want to do is run just one test. If this were HSpec (which it is not) I'd be running something like:
stack test --test-arguments -m "Network.Haskoin.Network.Units"
Now what I could do is modify the file haskcoin-core/test/Main.hs and comment out all the tests I don't want to run. But ya know - there should be a simpler way to run it with just command line parameters. (Mutating the file system goes agains the whole functional grain of Haskell).
I'd also be open to running it with stack ghci somehow.
My question is: How to run an individual test with Stack and Haskell Test.Framework?
As of mid 2019, I think stack has changed.
See --help for options:
stack test --test-arguments "--help"
Do a --dry-run to see what tests will run:
stack test --test-arguments "--dry-run"
Select tests with --match. Note, this alleges glob patterns will work but they don't seem to for me:
stack test --test-arguments "--match=foobar"
AFAICT, "foobar" is interpreted like a glob of *foobar*, but I can't be explicit about it.
Thanks to #sjakobi for this answer.
The process is - list the available test commands:
stack test --test-arguments "--help" haskoin-core:test-haskoin-core
This gives the following result:
haskoin-core-0.4.2: test (suite: test-haskoin-core, args: --help)
Usage: test-haskoin-core [OPTIONS]
--help show this help message
-j NUMBER --threads=NUMBER number of threads to use to run tests
--test-seed=NUMBER|random default seed for test random number generator
-a NUMBER --maximum-generated-tests=NUMBER how many automated tests something like QuickCheck should try, by default
--maximum-unsuitable-generated-tests=NUMBER how many unsuitable candidate tests something like QuickCheck should endure before giving up, by default
-s NUMBER --maximum-test-size=NUMBER to what size something like QuickCheck should test the properties, by default
-d NUMBER --maximum-test-depth=NUMBER to what depth something like SmallCheck should test the properties, by default
-o NUMBER --timeout=NUMBER how many seconds a test should be run for before giving up, by default
--no-timeout specifies that tests should be run without a timeout, by default
-l --list-tests list available tests but don't run any; useful to guide subsequent --select-tests
-t TEST-PATTERN --select-tests=TEST-PATTERN only tests that match at least one glob pattern given by an instance of this argument will be run
--jxml=FILE write a JUnit XML summary of the output to FILE
--jxml-nested use nested testsuites to represent groups in JUnit XML (not standards compliant)
--plain do not use any ANSI terminal features to display the test run
--color use ANSI terminal features to display the test run
--hide-successes hide sucessful tests, and only show failures
Test suite failure for package haskoin-core-0.4.2
test-haskoin-core: exited with: ExitFailure 1
Logs printed to console
From that we can build a command to list the tests:
stack test --test-arguments "--list-tests" haskoin-core:test-haskoin-core
From there we can use this command to glob for a particular test
stack test --test-arguments=--select-tests=Bloom*Filter haskoin-core:test-haskoin-core
Note the * in place of the space, there seems to be some discussion about how to handle spaces in this scenario.
Now this selects the tests we want to run:
haskoin-core-0.4.2: test (suite: test-haskoin-core, args: --select-tests=Bloom*Filter)
Binary encoding and decoding of bloom types:
BloomFilter: [OK, passed 100 tests]
Bloom Filters:
Bloom Filter Vector 1: [OK]
Bloom Filter Vector 2: [OK]
Bloom Filter Vector 3: [OK]
Properties Test Cases Total
Passed 1 3 4
Failed 0 0 0
Total 1 3 4
How can I tell Mocha where to look for my test files? My test files dont reside in the standard project root ./test folder. My test sit in Modules/.*/Tests/.
I've attempted to use the --grep command line argument but I have a feeling this argument looks for test NAMES not for test FILE NAMES.
mocha --grep Modules\/.*\/Tests
The above command gives the error:
Warning: Could not find any test files matching pattern: test
No test files found
You have to match not only directory but also its files . Besides, do no need grep , use only -- :
mocha -- Modules/**/Tests/*.js
// or `mocha -- Modules/Tests/*.js` (I am not sure because you didn't give the project hierarchy )
ive been setting up Grunt for my web app to auto build it and im seeing paths like
/path/to/file/**/*.js
i understand what one wildcard means, but what does 2 in a row mean?
/path/to/file/**/*.js matches any number of directories between /path/to/file/ and /*.js. As opposed to /path/to/file/*/*.js, which matches a single directory between /path/to/file/ and /*.js.
this matchers called "glob pattern" they are widely used in shell script and in CLI tools like grunt or npm .they '**' means -- "Matches zero or more directories, but will never match the directories . and .. "
you can read more in the docs
glob pattern