forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): ng test command runs karma
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 angular#70
- Loading branch information
Showing
3 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'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({ | ||
|
||
init: function(){ | ||
if (!this.karmaServer) { | ||
var karma = requireDependency(this.project.root, 'karma'); | ||
var karmaConfig = path.join(this.project.root, 'karma.conf'); | ||
this.karmaServer = new karma.Server({configFile: karmaConfig}); | ||
} | ||
}, | ||
|
||
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 self = this; | ||
return win.checkWindowsElevation(this.ui) | ||
.then(function() { | ||
return buildTask.run(buildCommandOptions); | ||
}) | ||
.then(function(){ | ||
return new Promise(function(){ | ||
return self.karmaServer.start(); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
module.exports.overrideCore = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'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; | ||
|
||
describe('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 () { | ||
this.timeout(10000); | ||
|
||
return tmp.teardown('./tmp'); | ||
}); | ||
|
||
it('ng test should excecute a test', function () { | ||
console.log('starting test'); | ||
return ng([ | ||
'test', | ||
'--skip-npm', | ||
'--skip-bower' | ||
]) | ||
.then(function () { | ||
console.log('test completed'); | ||
}); | ||
}); | ||
}); |