diff --git a/README.md b/README.md index 8416b5036950..2b98472a8a00 100644 --- a/README.md +++ b/README.md @@ -69,18 +69,13 @@ The build artifacts will be stored in the `dist/` directory. ### Running tests -Before running the tests make sure that the project is built. To build the -project once you can use: - ```bash -ng build +ng test ``` -With the project built in the `dist/` folder you can just run: `karma start`. -Karma will run the tests and keep the browser open waiting to run again. +Tests will execute after a build is executed via [Karma](http://karma-runner.github.io/0.13/index.html) -This will be easier when the command -[ng test](https://github.com/angular/angular-cli/issues/70) is implemented. +End to end tests will be available via `ng test` once implemented ([reference](https://github.com/angular/angular-cli/issues/103)) ### Deploying the app via GitHub Pages diff --git a/addon/ng2/commands/test.js b/addon/ng2/commands/test.js new file mode 100644 index 000000000000..fed52b5016e6 --- /dev/null +++ b/addon/ng2/commands/test.js @@ -0,0 +1,65 @@ +'use strict'; + +var chalk = require('chalk'); +var Command = require('ember-cli/lib/models/command'); +var Promise = require('ember-cli/lib/ext/promise'); +var Project = require('ember-cli/lib/models/project'); +var SilentError = require('silent-error'); +var validProjectName = require('ember-cli/lib/utilities/valid-project-name'); +var normalizeBlueprint = require('ember-cli/lib/utilities/normalize-blueprint-option'); + +var TestCommand = require('ember-cli/lib/commands/test'); +var win = require('ember-cli/lib/utilities/windows-admin'); +var path = require('path'); + +// require dependencies within the target project +function requireDependency (root, moduleName) { + var packageJson = require(path.join(root, 'node_modules', moduleName, 'package.json')); + var main = path.normalize(packageJson.main); + return require(path.join(root, 'node_modules', moduleName, main)); +} + +module.exports = TestCommand.extend({ + availableOptions: [ + { name: 'single-run', type: Boolean, default: true }, + { name: 'auto-watch', type: Boolean }, + { name: 'browsers', type: String }, + { name: 'colors', type: Boolean }, + { name: 'log-level', type: String }, + { name: 'port', type: Number }, + { name: 'reporters', type: String }, + ], + + run: function(commandOptions, rawArgs) { + var BuildTask = this.tasks.Build; + var buildTask = new BuildTask({ + ui: this.ui, + analytics: this.analytics, + project: this.project + }); + + var buildCommandOptions = { + environment: 'development', + outputPath: 'dist/', + watch: false + }; + + var projectRoot = this.project.root; + + return win.checkWindowsElevation(this.ui) + .then(function() { + return buildTask.run(buildCommandOptions); + }) + .then(function(){ + return new Promise(function(){ + var karma = requireDependency(projectRoot, 'karma'); + var karmaConfig = path.join(projectRoot, 'karma.conf'); + commandOptions.configFile = karmaConfig; + var karmaServer = new karma.Server(commandOptions); + karmaServer.start(); + }); + }); + } +}); + +module.exports.overrideCore = true; \ No newline at end of file diff --git a/addon/ng2/index.js b/addon/ng2/index.js index a262826d4b0a..273b9d5c867f 100644 --- a/addon/ng2/index.js +++ b/addon/ng2/index.js @@ -6,7 +6,8 @@ module.exports = { includedCommands: function() { return { 'new': require('./commands/new'), - 'init': require('./commands/init') + 'init': require('./commands/init'), + 'test': require('./commands/test') }; } }; diff --git a/tests/acceptance/test.spec.js b/tests/acceptance/test.spec.js new file mode 100644 index 000000000000..8a4157b1d66a --- /dev/null +++ b/tests/acceptance/test.spec.js @@ -0,0 +1,51 @@ +'use strict'; + +var fs = require('fs-extra'); +var ng = require('../helpers/ng'); +var existsSync = require('exists-sync'); +var expect = require('chai').expect; +var forEach = require('lodash/collection/forEach'); +var walkSync = require('walk-sync'); +var Blueprint = require('ember-cli/lib/models/blueprint'); +var path = require('path'); +var tmp = require('../helpers/tmp'); +var root = process.cwd(); +var util = require('util'); +var conf = require('ember-cli/tests/helpers/conf'); +var EOL = require('os').EOL; +var rewire = require('rewire'); + +xdescribe('Acceptance: ng test', function () { + before(conf.setup); + + after(conf.restore); + + beforeEach(function () { + return tmp.setup('./tmp') + .then(function () { + process.chdir('./tmp'); + }) + .then(function () { + return ng([ + 'init', + '--skip-npm', + '--skip-bower' + ]); + }); + }); + + afterEach(function () { + return tmp.teardown('./tmp'); + }); + + it('ng test should excecute a test', function () { + console.log('starting test'); + return ng([ + 'test', + '--single-run' + ]) + .then(function () { + console.log('test completed'); + }); + }); +}); \ No newline at end of file