Skip to content

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

Merged
merged 1 commit into from
Feb 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
.idea
npm-debug.log
typings/
typings/
tmp/
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ sudo: false
env:
- NODE_VERSION=4
- NODE_VERSION=5

os:
- linux
- osx
script: npm run-script test
addons:
firefox: "latest"
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source ~/.nvm/nvm-exec; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install Caskroom/cask/firefox; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
- nvm install $NODE_VERSION
- npm config set spin false
- npm config set progress false
install:
- node --version
- npm --version
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,11 @@ ng install ng2-cli-test-lib

### Running unit 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)


### Running end-to-end tests
Expand All @@ -161,9 +157,6 @@ $(npm bin)/tsc -p e2e/
Afterwards you only need to run `$(npm bin)/protractor` while serving via
`ng serve`.

This will be easier when the command
[ng test](https://github.com/angular/angular-cli/issues/70) is implemented.


### Deploying the app via GitHub Pages

Expand Down
8 changes: 5 additions & 3 deletions addon/ng2/blueprints/ng2/files/karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ System.config({
}
});

System.import('angular2/platform/browser').then(function(browser_adapter) {
// TODO: once beta is out we should change this code to use a "test platform"
browser_adapter.BrowserDomAdapter.makeCurrent();
System.import('angular2/testing').then(function(testing) {
return System.import('angular2/platform/testing/browser').then(function(providers) {
testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS,
providers.TEST_BROWSER_APPLICATION_PROVIDERS);
});
}).then(function() {
return Promise.all(
Object.keys(window.__karma__.files)
Expand Down
10 changes: 7 additions & 3 deletions addon/ng2/blueprints/ng2/files/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ module.exports = function(config) {
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher')
require('karma-chrome-launcher'),
require('karma-firefox-launcher')
],
files: [
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true},
{pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true},


{pattern: 'karma-test-shim.js', included: true, watched: true},

Expand All @@ -40,7 +44,7 @@ module.exports = function(config) {
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['Chrome', 'Firefox'],
singleRun: false
});
};
3 changes: 2 additions & 1 deletion addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.0",
"systemjs": "0.19.4"
"systemjs": "0.19.20"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

},
"devDependencies": {
"angular-cli": "0.0.*",
Expand All @@ -29,6 +29,7 @@
"jasmine-core": "^2.3.4",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.1",
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.6",
"protractor": "^3.0.0",
"typescript": "^1.7.3",
Expand Down
71 changes: 71 additions & 0 deletions addon/ng2/commands/test.js
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;
3 changes: 2 additions & 1 deletion addon/ng2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
'new' : require('./commands/new'),
'init' : require('./commands/init'),
'install' : require('./commands/install'),
'uninstall' : require('./commands/uninstall')
'uninstall' : require('./commands/uninstall'),
'test' : require('./commands/test')
};
}
};
78 changes: 37 additions & 41 deletions tests/e2e/e2e_workflow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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',
Expand All @@ -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);
});
});

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

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

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

Expand Down