Merge pull request #4527 from rwjblue/unit-tests

Add initial client unit test.
This commit is contained in:
Hannah Wolfe 2014-11-27 11:48:16 +00:00
commit 1db30f896f
9 changed files with 184 additions and 6 deletions

View File

@ -59,11 +59,19 @@ var _ = require('lodash'),
] ]
} }
}, },
clientTests: {
files: {
src: [
'core/test/client/**/*.js'
]
}
},
// Linting files for test code. // Linting files for test code.
test: { test: {
files: { files: {
src: [ src: [
'core/test/**/*.js' 'core/test/**/*.js',
'!core/test/client/**/*.js'
] ]
} }
} }
@ -106,8 +114,8 @@ var _ = require('lodash'),
tasks: ['emberTemplates:dev'] tasks: ['emberTemplates:dev']
}, },
ember: { ember: {
files: ['core/client/**/*.js'], files: ['core/client/**/*.js', 'core/test/client/**/*.js'],
tasks: ['clean:tmp', 'transpile', 'concat_sourcemap:dev'] tasks: ['clean:tmp', 'transpile', 'concat_sourcemap:dev', 'concat_sourcemap:tests']
}, },
sass: { sass: {
files: [ files: [
@ -169,6 +177,11 @@ var _ = require('lodash'),
jshintrc: 'core/client/.jshintrc' jshintrc: 'core/client/.jshintrc'
} }
}, },
clientTests: {
options: {
jshintrc: 'core/test/client/.jshintrc'
}
},
test: { test: {
options: { options: {
jshintrc: 'core/test/.jshintrc' jshintrc: 'core/test/.jshintrc'
@ -193,6 +206,12 @@ var _ = require('lodash'),
esnext: true esnext: true
} }
}, },
clientTests: {
options: {
config: '.jscsrc',
esnext: true
}
},
test: { test: {
options: { options: {
config: '.jscsrc' 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 // #### Generate coverage report
// See the `grunt test-coverage` task in the section on [Testing](#testing) for more information. // See the `grunt test-coverage` task in the section on [Testing](#testing) for more information.
coverage: { coverage: {
@ -389,6 +416,18 @@ var _ = require('lodash'),
src: ['**/*.js', '!loader.js', '!config-*.js'], src: ['**/*.js', '!loader.js', '!config-*.js'],
dest: '.tmp/ember-transpiled/' 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 sourcesContent: true
} }
}, },
tests: {
src: ['.tmp/ember-tests-transpiled/**/*.js'],
dest: 'core/built/scripts/ghost-tests.js',
options: {
sourcesContent: true
}
},
prod: { prod: {
src: ['.tmp/ember-transpiled/**/*.js', 'core/built/scripts/templates.js', src: ['.tmp/ember-transpiled/**/*.js', 'core/built/scripts/templates.js',
'core/client/loader.js'], 'core/client/loader.js'],
@ -769,7 +815,7 @@ var _ = require('lodash'),
// details of each of the test suites. // details of each of the test suites.
// //
grunt.registerTask('test', 'Run tests and lint code', 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 // ### Lint
// //
@ -934,7 +980,7 @@ var _ = require('lodash'),
// ### Ember Build *(Utility Task)* // ### Ember Build *(Utility Task)*
// All tasks related to building the Ember client code including transpiling ES6 modules and building templates // 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', 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)* // ### Ember Build *(Utility Task)*
// All tasks related to building the Ember client code including transpiling ES6 modules and building templates // All tasks related to building the Ember client code including transpiling ES6 modules and building templates

View File

@ -25,5 +25,10 @@
"showdown-ghost": "0.3.4", "showdown-ghost": "0.3.4",
"validator-js": "3.22.1", "validator-js": "3.22.1",
"google-caja": "5669.0.0" "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"
} }
} }

View File

@ -1,4 +1,6 @@
// Loader to create the Ember.js application // Loader to create the Ember.js application
/*global require */ /*global require */
if (!window.disableBoot) {
window.App = require('ghost/app')['default'].create(); window.App = require('ghost/app')['default'].create();
}

View File

@ -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
}
}

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Ghost Admin Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/bower_components/mocha/mocha.css">
<link rel="stylesheet" href="/core/client/assets/css/ghost.min.css">
<script>
window.disableBoot = true;
</script>
</head>
<body>
<div id="mocha"></div>
<script src="/core/built/scripts/vendor-dev.js"></script>
<script src="/core/built/scripts/ghost-dev.js"></script>
<script src="/bower_components/mocha/mocha.js"></script>
<script src="/testem.js"></script>
<script src="/bower_components/chai/chai.js"></script>
<script src="/bower_components/ember-cli-shims/app-shims.js"></script>
<script src="/bower_components/ember-mocha-adapter/adapter.js"></script>
<script src="/bower_components/ember-mocha/ember-mocha.amd.js"></script>
<script src="/core/built/scripts/ghost-tests.js"></script>
<script src="/bower_components/ember-cli-test-loader/test-loader.js"></script>
<script>
require('ghost/tests/test-helper');
</script>
</body>
</html>

View File

@ -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();

View File

@ -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');
});
});

View File

@ -98,6 +98,7 @@
"should": "~4.0.4", "should": "~4.0.4",
"sinon": "~1.10.3", "sinon": "~1.10.3",
"supertest": "~0.13.0", "supertest": "~0.13.0",
"testem": "^0.6.23",
"top-gh-contribs": "0.0.2" "top-gh-contribs": "0.0.2"
} }
} }

9
testem.json Normal file
View File

@ -0,0 +1,9 @@
{
"test_page": "core/test/client/index.html",
"launch_in_ci": [
"PhantomJS"
],
"launch_in_dev": [
"PhantomJS"
]
}