From ef71d932f380ed22d03e7f2c6bbf9dddaeede825 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 26 Nov 2014 23:06:24 -0500 Subject: [PATCH] Add initial client unit test. --- Gruntfile.js | 56 +++++++++++++++++-- bower.json | 5 ++ core/client/loader.js | 4 +- core/test/client/.jshintrc | 46 +++++++++++++++ core/test/client/index.html | 33 +++++++++++ core/test/client/test-helper.js | 18 ++++++ .../components/gh-trim-focus-input_test.js | 18 ++++++ package.json | 1 + testem.json | 9 +++ 9 files changed, 184 insertions(+), 6 deletions(-) create mode 100644 core/test/client/.jshintrc create mode 100644 core/test/client/index.html create mode 100644 core/test/client/test-helper.js create mode 100644 core/test/client/unit/components/gh-trim-focus-input_test.js create mode 100644 testem.json diff --git a/Gruntfile.js b/Gruntfile.js index 57392f0a52..d2a24ee254 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -59,11 +59,19 @@ var _ = require('lodash'), ] } }, + clientTests: { + files: { + src: [ + 'core/test/client/**/*.js' + ] + } + }, // Linting files for test code. test: { files: { src: [ - 'core/test/**/*.js' + 'core/test/**/*.js', + '!core/test/client/**/*.js' ] } } @@ -106,8 +114,8 @@ var _ = require('lodash'), tasks: ['emberTemplates:dev'] }, ember: { - files: ['core/client/**/*.js'], - tasks: ['clean:tmp', 'transpile', 'concat_sourcemap:dev'] + files: ['core/client/**/*.js', 'core/test/client/**/*.js'], + tasks: ['clean:tmp', 'transpile', 'concat_sourcemap:dev', 'concat_sourcemap:tests'] }, sass: { files: [ @@ -169,6 +177,11 @@ var _ = require('lodash'), jshintrc: 'core/client/.jshintrc' } }, + clientTests: { + options: { + jshintrc: 'core/test/client/.jshintrc' + } + }, test: { options: { jshintrc: 'core/test/.jshintrc' @@ -193,6 +206,12 @@ var _ = require('lodash'), esnext: true } }, + clientTests: { + options: { + config: '.jscsrc', + esnext: true + } + }, test: { options: { config: '.jscsrc' @@ -297,6 +316,14 @@ var _ = require('lodash'), } }, + testem: { + command: path.resolve(cwd + '/node_modules/.bin/testem ci'), + options: { + stdout: true, + stdin: false + } + }, + // #### Generate coverage report // See the `grunt test-coverage` task in the section on [Testing](#testing) for more information. coverage: { @@ -389,6 +416,18 @@ var _ = require('lodash'), src: ['**/*.js', '!loader.js', '!config-*.js'], dest: '.tmp/ember-transpiled/' }] + }, + tests: { + type: 'amd', + moduleName: function (path) { + return 'ghost/tests/' + path; + }, + files: [{ + expand: true, + cwd: 'core/test/client/', + src: ['**/*.js'], + dest: '.tmp/ember-tests-transpiled/' + }] } }, @@ -402,6 +441,13 @@ var _ = require('lodash'), sourcesContent: true } }, + tests: { + src: ['.tmp/ember-tests-transpiled/**/*.js'], + dest: 'core/built/scripts/ghost-tests.js', + options: { + sourcesContent: true + } + }, prod: { src: ['.tmp/ember-transpiled/**/*.js', 'core/built/scripts/templates.js', 'core/client/loader.js'], @@ -769,7 +815,7 @@ var _ = require('lodash'), // details of each of the test suites. // grunt.registerTask('test', 'Run tests and lint code', - ['jshint', 'jscs', 'test-routes', 'test-module', 'test-unit', 'test-integration', 'test-functional']); + ['jshint', 'jscs', 'test-routes', 'test-module', 'test-unit', 'test-integration', 'test-functional', 'shell:testem']); // ### Lint // @@ -934,7 +980,7 @@ var _ = require('lodash'), // ### Ember Build *(Utility Task)* // All tasks related to building the Ember client code including transpiling ES6 modules and building templates grunt.registerTask('emberBuildDev', 'Build Ember JS & templates for development', - ['clean:tmp', 'buildAboutPage', 'emberTemplates:dev', 'transpile', 'concat_sourcemap:dev']); + ['clean:tmp', 'buildAboutPage', 'emberTemplates:dev', 'transpile', 'concat_sourcemap:dev', 'concat_sourcemap:tests']); // ### Ember Build *(Utility Task)* // All tasks related to building the Ember client code including transpiling ES6 modules and building templates diff --git a/bower.json b/bower.json index f3d57d23ec..a8a3202dca 100644 --- a/bower.json +++ b/bower.json @@ -25,5 +25,10 @@ "showdown-ghost": "0.3.4", "validator-js": "3.22.1", "google-caja": "5669.0.0" + }, + "devDependencies": { + "ember-mocha": "~0.1.4", + "ember-cli-test-loader": "dgeb/ember-cli-test-loader#test-agnostic", + "ember-cli-shims": "stefanpenner/ember-cli-shims#~0.0.3" } } diff --git a/core/client/loader.js b/core/client/loader.js index 584654dc75..b8581aa964 100644 --- a/core/client/loader.js +++ b/core/client/loader.js @@ -1,4 +1,6 @@ // Loader to create the Ember.js application /*global require */ -window.App = require('ghost/app')['default'].create(); +if (!window.disableBoot) { + window.App = require('ghost/app')['default'].create(); +} diff --git a/core/test/client/.jshintrc b/core/test/client/.jshintrc new file mode 100644 index 0000000000..06a23d0929 --- /dev/null +++ b/core/test/client/.jshintrc @@ -0,0 +1,46 @@ +{ + "node": false, + "browser": true, + "nomen": false, + "bitwise": true, + "curly": true, + "eqeqeq": true, + "forin": true, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "plusplus": true, + "regexp": true, + "undef": true, + "unused": true, + "trailing": true, + "indent": 4, + "esnext": true, + "onevar": true, + "white": true, + "quotmark": "single", + "globals": { + "Ember": true, + "Em": true, + "DS": true, + "$": true, + "SimpleAuth": true, + "validator": true, + "ic": true, + "_": true, + "NProgress": true, + "moment": true, + "mocha": true, + "chai": true, + "expect": true, + "describe": true, + "it": true, + "beforeEach": true, + "before": true, + "afterEach": true, + "after": true + } +} diff --git a/core/test/client/index.html b/core/test/client/index.html new file mode 100644 index 0000000000..1fad858ecc --- /dev/null +++ b/core/test/client/index.html @@ -0,0 +1,33 @@ + + + + + + Ghost Admin Tests + + + + + + + +
+ + + + + + + + + + + + + + + diff --git a/core/test/client/test-helper.js b/core/test/client/test-helper.js new file mode 100644 index 0000000000..a476823faf --- /dev/null +++ b/core/test/client/test-helper.js @@ -0,0 +1,18 @@ +import TestLoader from 'ember-cli/test-loader'; +import Resolver from 'ember/resolver'; +import { setResolver } from 'ember-mocha'; + +var resolver = Resolver.create(); +resolver.namespace = { + modulePrefix: 'ghost' +}; + +setResolver(resolver); + +TestLoader.load(); + +window.expect = chai.expect; + +mocha.checkLeaks(); +mocha.globals(['jQuery', 'EmberInspector']); +mocha.run(); diff --git a/core/test/client/unit/components/gh-trim-focus-input_test.js b/core/test/client/unit/components/gh-trim-focus-input_test.js new file mode 100644 index 0000000000..f707b9d6b5 --- /dev/null +++ b/core/test/client/unit/components/gh-trim-focus-input_test.js @@ -0,0 +1,18 @@ +/* jshint expr:true */ +import { + describeComponent, + it +} from 'ember-mocha'; + +describeComponent('gh-trim-focus-input', function () { + it('trims value on focusOut', function () { + var component = this.subject({ + value: 'some random stuff ' + }); + + this.render(); + + component.$().focusout(); + expect(component.$().val()).to.equal('some random stuff'); + }); +}); diff --git a/package.json b/package.json index f178e098f1..48e22422f8 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,7 @@ "should": "~4.0.4", "sinon": "~1.10.3", "supertest": "~0.13.0", + "testem": "^0.6.23", "top-gh-contribs": "0.0.2" } } diff --git a/testem.json b/testem.json new file mode 100644 index 0000000000..bd4c08cb2d --- /dev/null +++ b/testem.json @@ -0,0 +1,9 @@ +{ + "test_page": "core/test/client/index.html", + "launch_in_ci": [ + "PhantomJS" + ], + "launch_in_dev": [ + "PhantomJS" + ] +}