Open samfearn opened 8 years ago
Ok, I've been playing with this on and off during the day, but I'm very new to using grunt, bower, yo etc, so I may be saying things that are either obvious or stupid.
npm install chai --save-dev
and `npm install mocha --save-dev, to make sure both mocha and chai were installed. This was following https://gist.github.com/maicki/7781943.src: ['test/index.html']
instead of using urls.connect().use('/node_modules', connect.static('./node_modules')),
to my connect middleware return. At this point it could find all the resources.to get it working using the mocha option 'urls' instead of 'src', I changed the urls option to be:
urls: ['http://<%= connect.options.hostname %>:<%= connect.test.options.port %>/test/index.html']
and also added connect().use('/test', connect.static('./test')),
to the connect middleware return for test.
At this point it all seems to be working. The test runs (obviously there are no actual tests being run and the test index.html has nothing to do with the app index.html) and the grunt task completes.
test index.html for reference:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Example Mocha Test</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" type="text/css" charset="utf-8" />
</head>
<body>
<!-- Required for browser reporter -->
<div id="mocha"></div>
<!-- mocha -->
<script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// This will be overridden by mocha-helper if you run with grunt
mocha.setup('bdd');
</script>
<!-- Include your assertion lib of choice -->
<script src="../node_modules/chai/chai.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Setup chai
var expect = chai.expect;
</script>
<!-- run mocha -->
<script type="text/javascript" charset="utf-8">
// If tests run in a real browser
// Can alternatively do a check on window.PHANTOMJS
if (navigator.userAgent.indexOf('PhantomJS') < 0) {
mocha.run();
}
</script>
</body>
</html>
This leaves the problem of getting real tests working. So far I've added the script test1.js to test/spec/test1.js
'use strict';
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
chai.assert.equal(-1, [1,2,3].indexOf(5));
chai.assert.equal(-1, [1,2,3].indexOf(0));
});
});
});
Getting this through jshint required me to add "mocha": true"
and '"predef":["chai"]` to my .jshintrc.
Hey,
I've just tried to scaffold out a project using this generator, but if I try to run `grunt' from within the working directory the grunt task fails with the error:
When I look at the directory structure I can see that I don't actually have a /test folder, just /app/, /bower_components/, /node_modules/, /package.json, /bower.json and Gruntfile.js.
For what its worth, when I ran 'yo' to scaffold out the project I got