From 6924888053c13cf12897b248bea890ced2dd94a2 Mon Sep 17 00:00:00 2001 From: alexisjanvier Date: Tue, 1 Mar 2016 16:06:52 +0100 Subject: [PATCH 1/3] Prepare e2e tests without grunt --- Makefile | 9 +++++++++ webpack.config.js | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8c4aef91..ef86d36f 100644 --- a/Makefile +++ b/Makefile @@ -24,3 +24,12 @@ test-e2e: @./node_modules/.bin/grunt test:e2e test: test-unit test-e2e + +prepare-test-e2e: + @echo "Preparing files for e2e tests" + @NODE_ENV=test ./node_modules/webpack/bin/webpack.js -p --optimize-minimize --optimize-occurence-order --optimize-dedupe + @cp ./examples/blog/*.js ./src/javascripts/test/fixtures/examples/blog + @cp ./examples/blog/*.html ./src/javascripts/test/fixtures/examples/blog + @sed -i.bak 's|http://localhost:8000/|/|g' src/javascripts/test/fixtures/examples/blog/index.html + @cp ./examples/blog/build/fakerest.js ./src/javascripts/test/fixtures/examples/blog/build/ + @cp ./examples/blog/build/sinon-server.js ./src/javascripts/test/fixtures/examples/blog/build/ diff --git a/webpack.config.js b/webpack.config.js index 5bfa0a6b..da199ff1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -32,7 +32,11 @@ module.exports = { 'ng-admin': getEntrySources(ngAdminAndVendorSources), 'ng-admin-only': getEntrySources(ngAdminSources) }, - output: { + output: process.env.NODE_ENV === 'test' ? { + path: './src/javascripts/test/fixtures/examples/blog/', + publicPath: "/", + filename: "build/[name].min.js" + } : { publicPath: "http://localhost:8000/", filename: "build/[name].min.js" }, @@ -52,3 +56,5 @@ module.exports = { }) ] }; + +//NODE_ENV=test ./node_modules/webpack/bin/webpack.js -p --optimize-minimize --optimize-occurence-order --optimize-dedupe --progress From da2372744edac31746bc58811f8a7f1dec0e7261 Mon Sep 17 00:00:00 2001 From: alexisjanvier Date: Tue, 1 Mar 2016 17:33:32 +0100 Subject: [PATCH 2/3] Remove grunt and lauch protractor from makefile --- Gruntfile.js | 69 ----------------------------------------------- Makefile | 25 +++++++++++------ package.json | 7 +---- webpack.config.js | 1 - 4 files changed, 18 insertions(+), 84 deletions(-) delete mode 100644 Gruntfile.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index d0759082..00000000 --- a/Gruntfile.js +++ /dev/null @@ -1,69 +0,0 @@ -/*global module*/ - -module.exports = function (grunt) { - 'use strict'; - - // Define the configuration for all the tasks - grunt.initConfig({ - copy: { - test_build: { - src: 'build/*', - dest: 'src/javascripts/test/fixtures/examples/blog/' - }, - test_sample_app: { - src: 'examples/blog/*', - dest: 'src/javascripts/test/fixtures/', - options: { - process: function(content) { - return content.replace(/http\:\/\/localhost\:8000\//g, '/'); - } - } - }, - test_fakerest: { - src: 'node_modules/fakerest/dist/FakeRest.min.js', - dest: 'src/javascripts/test/fixtures/examples/blog/build/fakerest.js' - }, - test_sinon_server: { - src: 'node_modules/sinon/pkg/sinon-server-1.14.1.js', - dest: 'src/javascripts/test/fixtures/examples/blog/build/sinon-server.js' - } - }, - connect: { - dev: { - options: { - port: 8000, - base: 'examples/blog/', - keepalive: false, - livereload: false - } - }, - test: { - options: { - port: 8001, - base: 'src/javascripts/test/fixtures/examples/blog/', - keepalive: false, - livereload: false - } - } - }, - protractor: { - e2e: { - configFile: 'src/javascripts/test/protractor.conf.js', - keepAlive: true, - debug: true - } - }, - exec: { - webpack: './node_modules/webpack/bin/webpack.js' - } - }); - - grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-exec'); - grunt.loadNpmTasks('grunt-protractor-runner'); - - grunt.registerTask('test:e2e', ['test:e2e:prepare', 'connect:test', 'protractor']); - grunt.registerTask('test:e2e:prepare', ['exec:webpack', 'copy:test_sample_app', 'copy:test_build', 'copy:test_fakerest', 'copy:test_sinon_server']); - -}; diff --git a/Makefile b/Makefile index ef86d36f..baea6001 100644 --- a/Makefile +++ b/Makefile @@ -17,19 +17,28 @@ build: @cp -Rf build examples/blog/ @echo "Files build/ng-admin.min.css and build/ng-admin.min.js updated (with minification)" +test: test-unit test-e2e + test-unit: @./node_modules/.bin/karma start src/javascripts/test/karma.conf.js --single-run -test-e2e: - @./node_modules/.bin/grunt test:e2e - -test: test-unit test-e2e +test-e2e: prepare-test-e2e + @make start-static-server + @./node_modules/.bin/protractor src/javascripts/test/protractor.conf.js + @make stop-static-server prepare-test-e2e: @echo "Preparing files for e2e tests" @NODE_ENV=test ./node_modules/webpack/bin/webpack.js -p --optimize-minimize --optimize-occurence-order --optimize-dedupe - @cp ./examples/blog/*.js ./src/javascripts/test/fixtures/examples/blog - @cp ./examples/blog/*.html ./src/javascripts/test/fixtures/examples/blog + @cp examples/blog/*.js src/javascripts/test/fixtures/examples/blog + @cp examples/blog/*.html src/javascripts/test/fixtures/examples/blog @sed -i.bak 's|http://localhost:8000/|/|g' src/javascripts/test/fixtures/examples/blog/index.html - @cp ./examples/blog/build/fakerest.js ./src/javascripts/test/fixtures/examples/blog/build/ - @cp ./examples/blog/build/sinon-server.js ./src/javascripts/test/fixtures/examples/blog/build/ + @cp node_modules/fakerest/dist/FakeRest.min.js src/javascripts/test/fixtures/examples/blog/build/fakerest.js + @cp node_modules/sinon/pkg/sinon-server-1.14.1.js src/javascripts/test/fixtures/examples/blog/build/sinon-server.js + +start-static-server: static-server.PID +static-server.PID: + @echo "Starting static server" + @./node_modules/.bin/http-server src/javascripts/test/fixtures/examples/blog -p 8001 --silent & echo $$! > ./$@; +stop-static-server: static-server.PID + @kill `cat $<` && rm $< diff --git a/package.json b/package.json index 9fd8753f..4eeb6243 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,8 @@ "fakerest": "^1.1.4", "file-loader": "^0.8.1", "font-awesome": "^4.3.0", - "grunt": "~0.4.4", - "grunt-cli": "^0.1.13", - "grunt-contrib-connect": "^0.8.0", - "grunt-contrib-copy": "^0.6.0", - "grunt-exec": "^0.4.6", - "grunt-protractor-runner": "~3.0.0", "html-loader": "^0.3.0", + "http-server": "~0.9.0", "humane-js": "^3.2.2", "jasmine": "~2.4.1", "jasmine-core": "~2.4.1", diff --git a/webpack.config.js b/webpack.config.js index da199ff1..3acd667b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,7 +34,6 @@ module.exports = { }, output: process.env.NODE_ENV === 'test' ? { path: './src/javascripts/test/fixtures/examples/blog/', - publicPath: "/", filename: "build/[name].min.js" } : { publicPath: "http://localhost:8000/", From 8e6d701ab6fb63ae1c6c72a6eadbc4e420d7e870 Mon Sep 17 00:00:00 2001 From: alexisjanvier Date: Wed, 2 Mar 2016 06:53:08 +0100 Subject: [PATCH 3/3] Launch a static server from protractor configuration --- Makefile | 9 ------ package.json | 2 +- src/javascripts/test/protractor.conf.js | 38 +++++++++++++++++++++++-- webpack.config.js | 2 -- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index baea6001..1cc484c4 100644 --- a/Makefile +++ b/Makefile @@ -23,9 +23,7 @@ test-unit: @./node_modules/.bin/karma start src/javascripts/test/karma.conf.js --single-run test-e2e: prepare-test-e2e - @make start-static-server @./node_modules/.bin/protractor src/javascripts/test/protractor.conf.js - @make stop-static-server prepare-test-e2e: @echo "Preparing files for e2e tests" @@ -35,10 +33,3 @@ prepare-test-e2e: @sed -i.bak 's|http://localhost:8000/|/|g' src/javascripts/test/fixtures/examples/blog/index.html @cp node_modules/fakerest/dist/FakeRest.min.js src/javascripts/test/fixtures/examples/blog/build/fakerest.js @cp node_modules/sinon/pkg/sinon-server-1.14.1.js src/javascripts/test/fixtures/examples/blog/build/sinon-server.js - -start-static-server: static-server.PID -static-server.PID: - @echo "Starting static server" - @./node_modules/.bin/http-server src/javascripts/test/fixtures/examples/blog -p 8001 --silent & echo $$! > ./$@; -stop-static-server: static-server.PID - @kill `cat $<` && rm $< diff --git a/package.json b/package.json index 4eeb6243..b0445cec 100644 --- a/package.json +++ b/package.json @@ -33,11 +33,11 @@ "file-loader": "^0.8.1", "font-awesome": "^4.3.0", "html-loader": "^0.3.0", - "http-server": "~0.9.0", "humane-js": "^3.2.2", "jasmine": "~2.4.1", "jasmine-core": "~2.4.1", "jshint-stylish": "~0.1.3", + "json-server": "~0.8.8", "jsonlint": "^1.6.2", "karma": "~0.12.14", "karma-chrome-launcher": "^0.2.0", diff --git a/src/javascripts/test/protractor.conf.js b/src/javascripts/test/protractor.conf.js index b5884d1c..3c349206 100644 --- a/src/javascripts/test/protractor.conf.js +++ b/src/javascripts/test/protractor.conf.js @@ -1,4 +1,36 @@ /*global browser*/ +var jsonServer = require('json-server'); +var path = require('path'); + +var server = function() { + const server = jsonServer.create(); + + server.use(jsonServer.defaults({ + static: path.join(__dirname, '/fixtures/examples/blog'), + logger: false + })); + + server.listen(8001); + + return server; +} + +var beforeLaunch = function () { + global.server = server(); +}; + +var onPrepare = function () { + browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO"'); +} + +var afterLaunch = function () { + if (!global.server || !global.server.close) { + return; + } + + global.server.close(); +}; + exports.config = { sauceUser: process.env.SAUCE_USERNAME, sauceKey: process.env.SAUCE_ACCESS_KEY, @@ -23,7 +55,7 @@ exports.config = { defaultTimeoutInterval: 360000 }, - onPrepare: function () { - browser.executeScript('window.name = "NG_ENABLE_DEBUG_INFO"'); - } + beforeLaunch: beforeLaunch, + onPrepare: onPrepare, + afterLaunch: afterLaunch, }; diff --git a/webpack.config.js b/webpack.config.js index 3acd667b..611a64d3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -55,5 +55,3 @@ module.exports = { }) ] }; - -//NODE_ENV=test ./node_modules/webpack/bin/webpack.js -p --optimize-minimize --optimize-occurence-order --optimize-dedupe --progress