mocha opts to look for tests in multiple directories - mocha.js

I need to run tests from both src and test directories. I've added the following line to mocha.opts, but it doesn't help:
"./{src,test}/**/*.spec.ts"

You can also specify in the config files. Here is an example that looks recursively in two different directories from app root. It will look for test named <anything>.test.js inside any test directory under mainDir1 or mainDir2
Example mocha --recursive --config ./mocha-config-test.js.
module.exports = {
spec: [
'mainDir1/**/test/**/*.test.js',
'mainDir2/**/test/**/*.test.js',
],
};

This is the answer:
./{,+(test|src)}/**/*.spec.ts without quotes

Related

How can I read static files from a bazel target?

I have a test that I want to run using go_test, however it reads in some files in order to run the test - in this case, an Excel file.
When I try to run the test, I attempt to read the relative path to the file "testdata/good_file.xlsx", but I get a file not found error. If I run the test normally using go test it works fine. How can I read this file from my test in bazel?
Note that this answer will work for all languages, not just Go. It will also work for binaries like go_binary or go_image, not just tests.
Bazel attempts to create a hermetically-sealed environment for your binary, which means that anything that is not explicitly specified in the BUILD.bazel file is ignored and from the perspective of anything that is running, does not exist.
To include it is fairly straightforward. You first create a filegroup target that wraps the data:
filegroup(
name = "testdata",
srcs = [
"testdata/good_file.xlsx",
],
# Alternatively you can use a glob if you want to get all the Excel files, which is usually
# the case when working with tests:
# srcs = glob(["testdata/*.xlsx"]),
)
Then in your test target, you include the data using the data attribute:
go_test(
name = "my_test",
# ... some fields ...
data = [
":testdata",
],
# ... more fields ...
)

Use Ruby, Cucumber and Aruba to check for file in testing home directory

I'm using Cucumber and Aruba to test a Ruby command line app written on top of GLI. To prevent tests from affecting production data, I update ENV['HOME'] to point to a testing directory. I'd like to check for the existence of a file in the testing ENV['HOME'] directory. I'd like to use Aruba for this, but I have been unable to get ENV['HOME'] to expand properly.
For example:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "set_a" of test_arena
Then a file named "#{ENV['HOME']}/config.xml" should exist
Is it possible to pass ENV['HOME'] to Aruba's Then a file named "" should exist step_definition and have it expand to the full path?
I'm still interested in seeing if it's possible to do this natively with Cucumber/Aruba. In the mean time, here's a cut down example of what I'm doing:
In features/app_name.feature file, define the following Scenario:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "test_arenas/set_a"
Then a test_arena file named "config.xml" should exist
Then, in the features/step_definitions/app_name.rb file define the steps:
Given(/^I switch ENV\['HOME'\] to be "(.*?)"$/) do |testing_dir|
ENV['HOME'] = File.join(File.expand_path(File.dirname(__FILE__)),
'..','..', testing_dir)
end
Then(/^a test_arena file named "(.*?)" should exist$/) do |file_name|
file_path = "#{ENV['HOME']}/#{file_name}"
expect(File.exists?(file_path)).to be_truthy
end
This isn't as robust at Aruba's check_file_presence but it gets the basic job done.
For a little more background, the idea behind this approach is to have a test_arenas directory sitting at the root of the app's directory structure. For each test, an individual test_arenas/set_X directory is created that contains the necessary files. Prior to each test, ENV['HOME'] is pointed to the respective test_arenas/set_X directory.

Jasmine-node CLI: Specify file match parameter

I'm trying to execute just a subset of my node jasmine tests.
I have a project structure as follows
root
+ server
+ invite
+specs
inviteSendSpec.js
inviteConfirmSpec.js
.. many more spec files
+ auth
+specs
.. many spec files
I can execute all tests from root by running:
node-jasmine --verbose server/
I'm trying to figure out how to use the -m parameter, so that I can just run the test matching a certain file name pattern.
e.g.
node-jasmine --verbose -m invite server/
should run all tests which contain invite, according to the few examples I've found. But instead it just finds one single test.
If I try to run a similar variation e.g.
node-jasmine --verbose -m send server/
it will find no tests.
What is the correct syntax for selecting a subset of tests?
p.s. I'm running jasmine-node 11.1.0 (so its not the walkdir issue)
-m or --match parameter is indeed used for file name matching.
I banged my had against the keyboard for couple of hours, and ended up looking at source for cli.js.
So here is the ticket (cli.js, line 228):
var regExpSpec = new RegExp(match + (matchall ? "" : "spec\\.") + "(" + extensions + ")$", 'i')
Aha!
First, you MUST specify --matchall key, otherwise it will use default "spec" prefix.
Second, there is no way you can specify extensions, they are either js or js|coffee|litcoffee if you use --coffee command line parameter
My test files have unit.js suffix (do not ask why), so I ended up with
cli.js --verbose --matchall --match unit\. --test-dir C:\MyProject\
and it did the job.
Your file names are right and
from the docs github.com/mhevery/jasmine-node
Note: your specification files must be named as *spec.js, *spec.coffee
or *spec.litcoffee, which matches the regular expression
/spec.(js|coffee|litcoffee)$/i; otherwise jasmine-node won't find
them! For example, sampleSpecs.js is wrong, sampleSpec.js is right.
You just need to run the hole folder:
node-jasmine --verbose server/invite/specs/
node-jasmine --verbose server/auth/specs/

Directory dependencies with rake

I'm using rake to copy a directory as so:
file copied_directory => original_directory do
#copy directory
end
This works fine, except when something inside of original_directory changes. The problem is that the mod date doesn't change on the enclosing directory, so rake doesn't know to copy the directory again. Is there any way to handle this? Unfortunately my current setup does not allow me to set up individual dependencies for each individual file inside of original_directory.
You could use rsync to keep the 2 directories in sync as shown here: http://asciicasts.com/episodes/149-rails-engines
You don't need to know the files to depend on them:
file copied_directory => FileList[original_directory, original_directory + "/**/*"]

When using Webby/Compass Integration what directory do the *.sass files go in?

I just setup Webby/Compass integration.
(https://github.com/Compass/compass/wiki/webby-integration)
Where do I put my Compass/Sass source files, and in what directory do they get
output as stylesheets?
You can put your SASS files wherever you want (under the 'content/' directory). So if the directory containing your CSS files is 'content/css', then put them there.
The only important thing is that you set the metadata part correctly, at the top of the SASS file itself. Like this:
$ cat content/css/site.sass
---
filter: sass
extension: css
layout: nil
---
[..cut..]
It looks like you can set the source-file yourself, from the documentation:
Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = File.join('src', 'stylesheets' )
end
It looks like it defaults to "src/stylesheets". When you build it it will probably get rendered to "output/css/" but I never used webby myself so im not 100% sure.
Okay found it in this repository
Apparently it belongs in the ./content/stylesheets directory of your webby project, and is output to the ./output/stylesheets directory.
What perplexes me is "why" it works this way. Why File.join? It looks like the default "src" is being replaced by "stylesheets" rather than joining a new string. Curious.

Resources