From 6d04ead9f2eeb329dc2e4aa7041c468b509da7ad Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Sat, 18 Apr 2015 13:20:03 +0100 Subject: [PATCH] Switch test coverage to use Istanbul closes #4644 - Switch from using blanket to istanbul - Rename some test files for consistency (and so that they will run) --- .gitignore | 3 +- Gruntfile.js | 43 ++++++++++++------- core/test/blanket_coverage.js | 11 ----- .../module/{module_test.js => module_spec.js} | 0 .../routes/{admin_test.js => admin_spec.js} | 6 +-- ...ication_test.js => authentication_spec.js} | 0 .../routes/api/{db_test.js => db_spec.js} | 0 .../api/{error_test.js => error_spec.js} | 0 ...ications_test.js => notifications_spec.js} | 0 .../api/{posts_test.js => posts_spec.js} | 0 .../{settings_test.js => settings_spec.js} | 0 .../api/{slugs_test.js => slugs_spec.js} | 0 .../routes/api/{tags_test.js => tags_spec.js} | 0 .../api/{users_test.js => users_spec.js} | 0 .../{frontend_test.js => frontend_spec.js} | 0 package.json | 2 +- 16 files changed, 34 insertions(+), 31 deletions(-) delete mode 100644 core/test/blanket_coverage.js rename core/test/functional/module/{module_test.js => module_spec.js} (100%) rename core/test/functional/routes/{admin_test.js => admin_spec.js} (99%) rename core/test/functional/routes/api/{authentication_test.js => authentication_spec.js} (100%) rename core/test/functional/routes/api/{db_test.js => db_spec.js} (100%) rename core/test/functional/routes/api/{error_test.js => error_spec.js} (100%) rename core/test/functional/routes/api/{notifications_test.js => notifications_spec.js} (100%) rename core/test/functional/routes/api/{posts_test.js => posts_spec.js} (100%) rename core/test/functional/routes/api/{settings_test.js => settings_spec.js} (100%) rename core/test/functional/routes/api/{slugs_test.js => slugs_spec.js} (100%) rename core/test/functional/routes/api/{tags_test.js => tags_spec.js} (100%) rename core/test/functional/routes/api/{users_test.js => users_spec.js} (100%) rename core/test/functional/routes/{frontend_test.js => frontend_spec.js} (100%) diff --git a/.gitignore b/.gitignore index 184194c2d3..e07bc7a8ff 100644 --- a/.gitignore +++ b/.gitignore @@ -54,8 +54,9 @@ Session.vim # Changelog, which is autogenerated, not committed CHANGELOG.md -# Casper generated files +# Test generated files /core/test/functional/*.png +/core/test/coverage config.js /core/client/config.js diff --git a/Gruntfile.js b/Gruntfile.js index 53ca3ad92b..bffee1a9ea 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -130,6 +130,7 @@ var _ = require('lodash'), 'core/server/**/*.js', 'core/shared/**/*.js', 'core/test/**/*.js', + '!core/test/coverage/**', '!core/shared/vendor/**/*.js' ] }, @@ -166,6 +167,7 @@ var _ = require('lodash'), 'core/server/**/*.js', 'core/shared/**/*.js', 'core/test/**/*.js', + '!core/test/coverage/**', '!core/shared/vendor/**/*.js' ] } @@ -240,18 +242,35 @@ var _ = require('lodash'), // #### All Route tests routes: { src: [ - 'core/test/functional/routes/**/*_test.js' + 'core/test/functional/routes/**/*_spec.js' ] }, // #### All Module tests module: { src: [ - 'core/test/functional/module/**/*_test.js' + 'core/test/functional/module/**/*_spec.js' ] } }, + // ### grunt-mocha-istanbul + // Configuration for the mocha test coverage generator + // `grunt coverage`. + mocha_istanbul: { + coverage: { + // TODO fix the timing/async & cleanup issues with the route and integration tests so that + // they can also have coverage generated for them & the order doesn't matter + src: ['core/test/integration', 'core/test/unit'], + options: { + mask: '**/*_spec.js', + coverageFolder: 'core/test/coverage', + mochaOptions: ['--timeout=15000'], + excludes: ['core/client/**'] + } + } + }, + // ### grunt-bg-shell // Used to run ember-cli watch in the background bgShell: { @@ -312,13 +331,6 @@ var _ = require('lodash'), } }, - // #### Generate coverage report - // See the `grunt test-coverage` task in the section on [Testing](#testing) for more information. - coverage: { - command: 'node ' + mochaPath + ' --timeout 15000 --reporter html-cov > coverage.html ' + - path.resolve(cwd + '/core/test/blanket_coverage.js') - }, - shrinkwrap: { command: 'npm shrinkwrap' } @@ -333,7 +345,7 @@ var _ = require('lodash'), options: { onlyUpdated: true, exclude: 'node_modules,.git,.tmp,bower_components,content,*built,*test,*doc*,*vendor,' + - 'config.js,coverage.html,.travis.yml,*.min.css,screen.css', + 'config.js,.travis.yml,*.min.css,screen.css', extras: ['fileSearch'] } } @@ -492,7 +504,7 @@ var _ = require('lodash'), // * [Building assets](#building%20assets): // `grunt init`, `grunt` & `grunt prod` or live reload with `grunt dev` // * [Testing](#testing): - // `grunt validate`, the `grunt test-*` sub-tasks or generate a coverage report with `grunt test-coverage`. + // `grunt validate`, the `grunt test-*` sub-tasks or generate a coverage report with `grunt coverage`. // ### Help // Run `grunt help` on the commandline to get a print out of the available tasks and details of @@ -660,7 +672,7 @@ var _ = require('lodash'), // If you need to run an individual route test file, you can do so, providing you have a `config.js` file and // mocha installed globally by using a command in the form: // - // `NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/functional/routes/admin_test.js` + // `NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/functional/routes/admin_spec.js` // // Route tests are run with [mocha](http://mochajs.org/) using // [should](https://github.com/visionmedia/should.js) and [supertest](https://github.com/visionmedia/supertest) @@ -723,7 +735,7 @@ var _ = require('lodash'), ); // ### Coverage - // `grunt test-coverage` will generate a report for the Unit and Integration Tests. + // `grunt coverage` will generate a report for the Unit Tests. // // This is not currently done as part of CI or any build, but is a tool we have available to keep an eye on how // well the unit and integration tests are covering the code base. @@ -731,8 +743,9 @@ var _ = require('lodash'), // of the codebase are covered, than that the whole codebase is covered to a particular level. // // Key areas for coverage are: helpers and theme elements, apps / GDK, the api and model layers. - grunt.registerTask('test-coverage', 'Generate unit and integration (mocha) tests coverage report', - ['test-setup', 'shell:coverage'] + + grunt.registerTask('coverage', 'Generate unit and integration (mocha) tests coverage report', + ['test-setup', 'mocha_istanbul:coverage'] ); // #### Master Warning *(Utility Task)* diff --git a/core/test/blanket_coverage.js b/core/test/blanket_coverage.js deleted file mode 100644 index 1972c7637e..0000000000 --- a/core/test/blanket_coverage.js +++ /dev/null @@ -1,11 +0,0 @@ -// Posts -/*jshint unused:false */ -var blanket = require('blanket')({ - pattern: ['/core/server/', '/core/client/', '/core/shared/'], - 'data-cover-only': ['/core/server/', '/core/client/', '/core/shared/'] - }), - requireDir = require('require-dir'); - -requireDir('./unit'); -requireDir('./integration'); -requireDir('./functional/routes'); diff --git a/core/test/functional/module/module_test.js b/core/test/functional/module/module_spec.js similarity index 100% rename from core/test/functional/module/module_test.js rename to core/test/functional/module/module_spec.js diff --git a/core/test/functional/routes/admin_test.js b/core/test/functional/routes/admin_spec.js similarity index 99% rename from core/test/functional/routes/admin_test.js rename to core/test/functional/routes/admin_spec.js index 7e364b4b03..5ce2dca524 100644 --- a/core/test/functional/routes/admin_test.js +++ b/core/test/functional/routes/admin_spec.js @@ -134,7 +134,7 @@ describe('Admin Routing', function () { it('should block admin access over non-HTTPS', function (done) { request.get('/ghost/') .expect(403) - .end(done); + .end(doEnd(done)); }); it('should allow admin access over HTTPS', function (done) { @@ -173,14 +173,14 @@ describe('Admin Routing', function () { request.get('/ghost/') .expect('Location', /^https:\/\/localhost\/ghost\//) .expect(301) - .end(done); + .end(doEnd(done)); }); it('should allow admin access over HTTPS', function (done) { request.get('/ghost/setup/') .set('X-Forwarded-Proto', 'https') .expect(200) - .end(done); + .end(doEnd(done)); }); }); diff --git a/core/test/functional/routes/api/authentication_test.js b/core/test/functional/routes/api/authentication_spec.js similarity index 100% rename from core/test/functional/routes/api/authentication_test.js rename to core/test/functional/routes/api/authentication_spec.js diff --git a/core/test/functional/routes/api/db_test.js b/core/test/functional/routes/api/db_spec.js similarity index 100% rename from core/test/functional/routes/api/db_test.js rename to core/test/functional/routes/api/db_spec.js diff --git a/core/test/functional/routes/api/error_test.js b/core/test/functional/routes/api/error_spec.js similarity index 100% rename from core/test/functional/routes/api/error_test.js rename to core/test/functional/routes/api/error_spec.js diff --git a/core/test/functional/routes/api/notifications_test.js b/core/test/functional/routes/api/notifications_spec.js similarity index 100% rename from core/test/functional/routes/api/notifications_test.js rename to core/test/functional/routes/api/notifications_spec.js diff --git a/core/test/functional/routes/api/posts_test.js b/core/test/functional/routes/api/posts_spec.js similarity index 100% rename from core/test/functional/routes/api/posts_test.js rename to core/test/functional/routes/api/posts_spec.js diff --git a/core/test/functional/routes/api/settings_test.js b/core/test/functional/routes/api/settings_spec.js similarity index 100% rename from core/test/functional/routes/api/settings_test.js rename to core/test/functional/routes/api/settings_spec.js diff --git a/core/test/functional/routes/api/slugs_test.js b/core/test/functional/routes/api/slugs_spec.js similarity index 100% rename from core/test/functional/routes/api/slugs_test.js rename to core/test/functional/routes/api/slugs_spec.js diff --git a/core/test/functional/routes/api/tags_test.js b/core/test/functional/routes/api/tags_spec.js similarity index 100% rename from core/test/functional/routes/api/tags_test.js rename to core/test/functional/routes/api/tags_spec.js diff --git a/core/test/functional/routes/api/users_test.js b/core/test/functional/routes/api/users_spec.js similarity index 100% rename from core/test/functional/routes/api/users_test.js rename to core/test/functional/routes/api/users_spec.js diff --git a/core/test/functional/routes/frontend_test.js b/core/test/functional/routes/frontend_spec.js similarity index 100% rename from core/test/functional/routes/frontend_test.js rename to core/test/functional/routes/frontend_spec.js diff --git a/package.json b/package.json index 46c93c5241..cc21ec7cd7 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "pg": "4.1.1" }, "devDependencies": { - "blanket": "~1.1.6", "bower": "~1.3.10", "grunt": "~0.4.5", "grunt-bg-shell": "^2.3.1", @@ -87,6 +86,7 @@ "grunt-express-server": "~0.4.19", "grunt-jscs": "~1.2.0", "grunt-mocha-cli": "~1.11.0", + "grunt-mocha-istanbul": "2.4.0", "grunt-shell": "~1.1.1", "grunt-update-submodules": "~0.4.1", "matchdep": "~0.3.0",