Skip to content

Commit

Permalink
feat(command): ng test command runs karma
Browse files Browse the repository at this point in the history
Overrode the ember-cli test command to initialize the karma server
Then start the karma server based upon the karma.conf.js config file

closes #70
  • Loading branch information
Brocco committed Jan 24, 2016
1 parent a8ee48b commit 614ad71
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 9 deletions.
11 changes: 3 additions & 8 deletions README.md
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions 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;
3 changes: 2 additions & 1 deletion addon/ng2/index.js
Expand Up @@ -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')
};
}
};
51 changes: 51 additions & 0 deletions 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');
});
});
});

0 comments on commit 614ad71

Please sign in to comment.