-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(command): ng test command runs karma #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules/ | ||
.idea | ||
npm-debug.log | ||
typings/ | ||
typings/ | ||
tmp/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'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(resolve, reject){ | ||
var karma = requireDependency(projectRoot, 'karma'); | ||
var karmaConfig = path.join(projectRoot, 'karma.conf'); | ||
|
||
// Convert browsers from a string to an array | ||
if (commandOptions.browsers){ | ||
commandOptions.browsers = commandOptions.browsers.split(','); | ||
} | ||
commandOptions.configFile = karmaConfig; | ||
var karmaServer = new karma.Server(commandOptions, resolve); | ||
|
||
karmaServer.start(); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
module.exports.overrideCore = true; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,17 @@ describe('Basic end-to-end Workflow', function () { | |
|
||
after(conf.restore); | ||
|
||
var testArgs = [ | ||
'test', | ||
'--single-run' | ||
]; | ||
|
||
// In travis CI only run tests in Firefox | ||
if (process.env.TRAVIS) { | ||
testArgs.push('--browsers'); | ||
testArgs.push('Firefox'); | ||
} | ||
|
||
it('Installs angular-cli correctly', function() { | ||
this.timeout(300000); | ||
|
||
|
@@ -56,19 +67,17 @@ describe('Basic end-to-end Workflow', function () { | |
}); | ||
}); | ||
|
||
it('Perform `ng test`', function(done) { | ||
this.timeout(30000); | ||
it('Perform `ng test` after initial build', function() { | ||
this.timeout(300000); | ||
|
||
return ng([ | ||
'test' | ||
]).then(function(err) { | ||
// TODO when `ng test` will be implemented | ||
//expect(err).to.be.equal(1); | ||
done(); | ||
return ng(testArgs) | ||
.then(function(result) { | ||
expect(result.exitCode).to.be.equal(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this what we have to check on future tests for the correct execution of a command? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for karma tests yes, based on their API it is how we can discern if our tests passed/failed via our CLI |
||
}); | ||
}); | ||
|
||
it('Can create a test component using `ng generate component test-component`', function() { | ||
this.timeout(10000); | ||
return ng([ | ||
'generate', | ||
'component', | ||
|
@@ -82,15 +91,12 @@ describe('Basic end-to-end Workflow', function () { | |
}); | ||
}); | ||
|
||
it('Perform `ng test`', function(done) { | ||
this.timeout(30000); | ||
it('Perform `ng test` after adding a component', function() { | ||
this.timeout(300000); | ||
|
||
return ng([ | ||
'test' | ||
]).then(function(err) { | ||
// TODO when `ng test` will be implemented | ||
//expect(err).to.be.equal(1); | ||
done(); | ||
return ng(testArgs) | ||
.then(function(result) { | ||
expect(result.exitCode).to.be.equal(0); | ||
}); | ||
}); | ||
|
||
|
@@ -107,15 +113,12 @@ describe('Basic end-to-end Workflow', function () { | |
}); | ||
}); | ||
|
||
it('Perform `ng test`', function(done) { | ||
this.timeout(30000); | ||
it('Perform `ng test` after adding a service', function() { | ||
this.timeout(300000); | ||
|
||
return ng([ | ||
'test' | ||
]).then(function(err) { | ||
// TODO when `ng test` will be implemented | ||
//expect(err).to.be.equal(1); | ||
done(); | ||
return ng(testArgs) | ||
.then(function(result) { | ||
expect(result.exitCode).to.be.equal(0); | ||
}); | ||
}); | ||
|
||
|
@@ -132,15 +135,12 @@ describe('Basic end-to-end Workflow', function () { | |
}); | ||
}); | ||
|
||
it('Perform `ng test`', function(done) { | ||
this.timeout(30000); | ||
it('Perform `ng test` after adding a pipe', function() { | ||
this.timeout(300000); | ||
|
||
return ng([ | ||
'test' | ||
]).then(function(err) { | ||
// TODO when `ng test` will be implemented | ||
//expect(err).to.be.equal(1); | ||
done(); | ||
return ng(testArgs) | ||
.then(function(result) { | ||
expect(result.exitCode).to.be.equal(0); | ||
}); | ||
}); | ||
|
||
|
@@ -166,20 +166,16 @@ describe('Basic end-to-end Workflow', function () { | |
}); | ||
}); | ||
|
||
it('Perform `ng test`', function(done) { | ||
it('Perform `ng test` after adding a route', function() { | ||
this.timeout(300000); | ||
|
||
return ng([ | ||
'test' | ||
]).then(function(err) { | ||
// TODO when `ng test` will be implemented | ||
//expect(err).to.be.equal(1); | ||
// Clean `tmp` folder | ||
return ng(testArgs) | ||
.then(function(result) { | ||
expect(result.exitCode).to.be.equal(0); | ||
|
||
// Clean `tmp` folder | ||
process.chdir(path.resolve(root, '..')); | ||
sh.rm('-rf', './tmp'); // tmp.teardown takes too long | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks