When setting up Mocha how can I say 'Grab all test files in the /tests/specs/ folder and run those`?
This is much more useful than having to explicitly define each test Mocha should include and run.
mocha.setup({
ui: 'bdd',
grep: 'tests/specs/*.Spec.js' // Look for all js files in specs folder
});
There is no option you can pass to mocha.setup to find files.
On the command line you just pass a glob pattern to Mocha (e.g. mocha 'some/subdir/**/*.spec.js', the quotes are to prevent some shells from mangling the glob). You can put it in mocha.opts if you don't want to have to repeat it all the time. The startup script (mocha) will find the files and feed them to the test runner.
If you bypass Mocha's startup script but instead decide to write your own code to setup and drive Mocha, you are responsible for finding the test files and feeding them to Mocha with the .addFile method. An except from this example:
// Add each .js file to the mocha instance
fs.readdirSync(testDir).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function(file){
mocha.addFile(
path.join(testDir, file)
);
});
You could use node-glob to replicate globbing functionality if you want.
In the browser, Mocha has no notion of "files" so it cannot be told what files to use. You need to use a module loader like RequireJS or SystemJS and load the modules that contain the tests or bundle all the test files with bundlers like Webpack or Browserify and load the bundle after you load Mocha. Mocha will learn of the available tests when your test files call the functions that Mocha leaks into the global space.
Related
For unit testing a Go code base, is there any reasonable alternative to the foo.go and foo_test.go pattern? The only "concern" is having all those extra files in the same place on the filesystem. It might be nice to put the test files in a central place, but that might not work due to the way Go packages work.
When you tell the go command to test a package, e.g.
go test some/path/mypackage
Then the go tool will look for test files in the package's directory. If you put the test files elsewhere, then the go tool will not find them (it will not even look for them) in other folders, so they will not be run / executed.
This argument alone is enough to not put them elsewhere.
Package doc of testing:
To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions as described here. Put the file in the same package as the one being tested.
Command go: Testing functions:
The 'go test' command expects to find test, benchmark, and example functions in the "*_test.go" files corresponding to the package under test.
Some notes:
The go tool only expects test files to be in the same folder, but you can name them however you like, you just have to use the _test.go suffix. E.g. you may have a foo.go, and you may use my_test.go for the tests. There is also no requirement to have a separate test file for each .go source files, you may put all tests into a single test file, and you may have more test files than source files.
In the test files, you may use the same package name, and then the test files are compiled together with the package so tests have access to everything–including unexported identifiers–in the package (white-box testing). You may use the package name suffixed with _test, in which case the tests in those files will only have access to the package's exported identifiers (black-box testing). Read more about this here: How can I allow one package access to another package's unexported data only when testing?
You shouldn't worry about the number of .go files. To go tool will handle even if you have a thousand .go files in a package. Although in most cases if you have many .go files in a package, that's an indication that the package is doing too much, and it should be broken into multiple, smaller packages.
Can a Ruby test get the location of the folder where Rake executed it from? I want to run Test::Unit unit tests using Rake but my defined "test suites" in Rake need to be able to find locations of libraries relative to the root of my project.
With Maven, I can set a system property like so :
<properties>
<main.basedir>${project.basedir}</main.basedir>
</properties>
And then Java can reference it like so:
String baseDir = System.getProperty("main.basedir");
Can Ruby do something similar? If so, how? Do I need to use a Rake namespace-require + include ? Not brewing my own framework: just trying to do the most basic test setup. I do have some lib files I created that my tests want to use.
This doesn't work because it hard codes the base dir into the class file:
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
You can probably do this by injecting it in a test helper and getting the base location relative to the location of the file the test helper is is, but I would like to ask you what are you actually trying to achive?
normally the tests have access to the lib path and you should be able to just require what you want to use in the tests directly. are you using something like rspec or test::unit? are you brewing your own test framework?
so overall the answer is yes you can do it, but you should not have to do it. can show you how once you clarify what test framework you're using.
Edit
For test unit, this describes almost what you want to do:
https://github.com/test-unit/test-unit/blob/master/doc/text/how-to.md
The run_test.rb helper is placed in test. You see how the base dir is built by using the path of file (as mentioned above) and how the lib dir is placed on the load path.
I want to use Laravel Elixir to minify my css/files files. But I don't want to use the mix-methode and merge them. All I want is to generate a "custom.min.js" file from my original "custom.js". Is there a way to do this with Elexir?
EDIT:
To make it a bit clearer: My biggest issue is that I have two folders in "resources/assets": js and css. So I basically want to minify all files in there and have them minified in "public/js" and "public/css".
Quote from the Laravel documentation:
Note: All tasks will assume a development environment, and will exclude minification. For production, use gulp --production.
This means if you want the files to be minified run gulp --production instead of just gulp. It's a better practise than enabling compression directly in the gulp file and makes sure you can debug your compiled files while developing the application.
If you want them to be placed in public/assets/css use the path as a second parameter:
mix.less('app.less', 'public/assets/css');
gulp --production.
Jeffrey way replied on the issue here: https://laracasts.com/discuss/channels/elixir/elixir-doesnt-minify
Or you can find it on the documentation. Enjoy coding!
If you just want to copy .css files, without using LESS or SASS, and don't want to combine files (i.e. you want something like a copy() method with minification ability) you can use method for combining, styles(), by calling it for every .css file and passing filename string without array, for example:
mix.styles('some.css');
mix.styles('node_modules/bootstrap/dist/css/bootstrap.css', null, './');
Same can be done for .js files using scripts() method:
mix.scripts('some.js');
mix.scripts('node_modules/bootstrap/dist/js/bootstrap.js', null, './');
And then you can use gulp (doesn't minify, creates .map files) or gulp --production (creates minified files) as mentioned in above posts.
Straight from the Laravel/Elixir docs:
Elixir is built on top of Gulp, so to run your Elixir tasks you only need to run the gulp command in your terminal. Adding the --production flag to the command will instruct Elixir to minify your CSS and JavaScript files:
Run all tasks... gulp
Run all tasks and minify all CSS and JavaScript... gulp --production
docs: https://laravel.com/docs/5.3/elixir#running-elixir
I want to debug just a single test in webstorm. The mocha options specify a test directory, but I can't seem to point it to just a single test.js file.
How can I debug/run configure a single mocha test using the webstorm debug configuration options?
As a hack, you could configure the mocha command directly with the CLI option:
mocha --grep login-failure.js
Also, you can use the only function to skip all other tests:
describe(function () {
// these tests will be skipped
});
describe.only(function () {
// these tests will run
});
Source: http://jaketrent.com/post/run-single-mocha-test/
As far as I'm aware it's not currently supported.
https://youtrack.jetbrains.com/issue/WEB-10067 -- watch this ticket (star/vote/comment) to get notified on progress.
I solved this by pointing to a random non-test directory as the test directory and passing my single test filename in as an "extra mocha option"
Why not just create a test folder and create your .js test file inside?
I cannot quite figure out how can I use gulp with jasmine. I installed and configured it, so it runs my tests, but I am not sure how to introduce my javascript files to jasmine without the jasmin runner html.
Have you tried gulp-jasmine?
gulp.task('default', function () {
gulp.src('spec/test.js').pipe(jasmine());
});
The src() method can take a glob like 'spec/**/*.js' and automatically run jasmine on all javascript files in the spec directory.