diff --git a/.gitignore b/.gitignore index 2676228edb0a..a180e51682de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ .idea npm-debug.log -typings/ \ No newline at end of file +typings/ +tmp/ \ No newline at end of file diff --git a/README.md b/README.md index 9d35418d1521..df15163f92d7 100644 --- a/README.md +++ b/README.md @@ -71,18 +71,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..bdd691fdb3d1 --- /dev/null +++ b/addon/ng2/commands/test.js @@ -0,0 +1,66 @@ +'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'); + commandOptions.configFile = karmaConfig; + var karmaServer = new karma.Server(commandOptions, resolve); + + 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 9cd064680ba8..d05efd8e9458 100644 --- a/addon/ng2/index.js +++ b/addon/ng2/index.js @@ -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') }; } }; diff --git a/tests/acceptance/install.spec.js b/tests/acceptance/install.spec.js index d35d3881ed42..e32c6de5535e 100644 --- a/tests/acceptance/install.spec.js +++ b/tests/acceptance/install.spec.js @@ -44,14 +44,12 @@ describe('Acceptance: ng install', function() { function parsePackage(packageName) { var packagePath = path.resolve(process.cwd(), 'node_modules', packageName, packageName + '.ts'); - if (!existsSync(packagePath)) { return false; } var contents = fs.readFileSync(packagePath, 'utf8'); var data = {}; - data.Directive = []; data.Pipe = []; data.Provider = []; diff --git a/tests/acceptance/test.spec.js b/tests/acceptance/test.spec.js new file mode 100644 index 000000000000..a06224152826 --- /dev/null +++ b/tests/acceptance/test.spec.js @@ -0,0 +1,68 @@ +'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'); +var sh = require('shelljs'); + +describe('Acceptance: ng test', function () { + before(conf.setup); + + after(conf.restore); + + var testProjectName = 'ng-test-test-proj'; + + it('Installs angular-cli correctly', function() { + this.timeout(300000); + + return tmp.setup('./tmp') + .then(function () { + process.chdir('./tmp'); + + sh.exec('npm i angular-cli -g -C ' + process.cwd(), { silent: true }); + expect(fs.existsSync(path.join(process.cwd(), 'bin', 'ng'))); + }); + }); + + it('Can create new project using `ng new [project name]`', function() { + this.timeout(300000); + + return ng([ + 'new', + testProjectName, + '--silent' + ]).then(function() { + expect(fs.existsSync(path.join(root, testProjectName))); + }); + }); + + it('Can change current working directory', function() { + process.chdir(path.join(root, testProjectName)); + expect(path.basename(process.cwd())).to.equal(testProjectName); + }); + + it('Can execute a test run', function() { + this.timeout(300000); + return ng([ + 'test', + '--single-run' + ]).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 + }); + }); +}); \ No newline at end of file diff --git a/tests/e2e/e2e_workflow.spec.js b/tests/e2e/e2e_workflow.spec.js index 6c8e4341bad0..258c7d7fe6e1 100644 --- a/tests/e2e/e2e_workflow.spec.js +++ b/tests/e2e/e2e_workflow.spec.js @@ -55,19 +55,18 @@ 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(); + 'test', + '--single-run' + ]).then(function(result) { + expect(result.exitCode).to.be.equal(0); }); }); it('Can create a test component using `ng generate component test-component`', function() { + this.timeout(10000); return ng([ 'generate', 'component', @@ -81,15 +80,14 @@ 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(); + 'test', + '--single-run' + ]).then(function(result) { + expect(result.exitCode).to.be.equal(0); }); }); @@ -106,15 +104,14 @@ 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(); + 'test', + '--single-run' + ]).then(function(result) { + expect(result.exitCode).to.be.equal(0); }); }); @@ -131,20 +128,18 @@ describe('Basic end-to-end Workflow', function () { }); }); - it('Perform `ng test`', function(done) { + it('Perform `ng test` 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); + 'test', + '--single-run' + ]).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(); }); });