aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2014-07-23 15:49:44 +0200
committerStas Vilchik <vilchiks@gmail.com>2014-07-23 15:49:51 +0200
commitedb94988b829c50910981711da2554d2df401825 (patch)
treefa2e5d9491cdc4211d9abe229383be1af7d8d87a
parentd0f9dca7b2d3dd27ab0b43ecdd9c0ea93d4ae734 (diff)
downloadsonarqube-edb94988b829c50910981711da2554d2df401825.tar.gz
sonarqube-edb94988b829c50910981711da2554d2df401825.zip
Make the frontend medium tests better (integrate templates)
-rw-r--r--server/sonar-web/Gruntfile.coffee4
-rw-r--r--server/sonar-web/package.json7
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/pages/component-viewer.html31
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/pages/quality-gates.html40
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/pages/treemap.html16
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/server.js15
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec.js17
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/tests/treemap-spec.js37
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/views/component-viewer.jade7
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/views/layouts/main.jade17
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/views/quality-gates.jade8
-rw-r--r--server/sonar-web/src/main/js/tests/e2e/views/treemap.jade4
12 files changed, 62 insertions, 141 deletions
diff --git a/server/sonar-web/Gruntfile.coffee b/server/sonar-web/Gruntfile.coffee
index 6eb67c1691c..d1975327285 100644
--- a/server/sonar-web/Gruntfile.coffee
+++ b/server/sonar-web/Gruntfile.coffee
@@ -261,11 +261,11 @@ module.exports = (grunt) ->
express:
test:
options:
- script: '<%= pkg.assets %>js/tests/e2e/server.js'
+ script: '<%= pkg.sources %>js/tests/e2e/server.js'
dev:
options:
background: false
- script: '<%= pkg.assets %>js/tests/e2e/server.js'
+ script: '<%= pkg.sources %>js/tests/e2e/server.js'
casper:
diff --git a/server/sonar-web/package.json b/server/sonar-web/package.json
index dded422d38f..aafaac01a66 100644
--- a/server/sonar-web/package.json
+++ b/server/sonar-web/package.json
@@ -2,12 +2,8 @@
"name": "SonarQube",
"version": "0.0.1",
"devDependencies": {
- "karma": "0.10.10",
- "karma-jasmine": "0.1.5",
- "karma-phantomjs-launcher": "0.1.4",
- "karma-coverage": "0.2.1",
- "karma-junit-reporter": "0.2.1",
"express": "3.4.4",
+ "jade": "1.4.2",
"phantomjs": "1.9.7-12",
"casperjs": "1.1.0-beta3",
"grunt": "0.4.4",
@@ -18,7 +14,6 @@
"grunt-contrib-requirejs": "0.4.3",
"grunt-contrib-watch": "0.5.3",
"grunt-contrib-uglify": "0.4.0",
- "grunt-karma": "0.6.2",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-concat": "0.4.0",
diff --git a/server/sonar-web/src/main/js/tests/e2e/pages/component-viewer.html b/server/sonar-web/src/main/js/tests/e2e/pages/component-viewer.html
deleted file mode 100644
index 4cae4890868..00000000000
--- a/server/sonar-web/src/main/js/tests/e2e/pages/component-viewer.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <link href="../css/sonar.css" rel="stylesheet" media="all">
-
- <script src="../js/sonar.js"></script>
- <script src="../js/third-party/jquery.mockjax.js"></script>
- <script>
- var baseUrl = '..';
- var $j = jQuery.noConflict();
- window.suppressTranslationWarnings = true;
- jQuery.mockjaxSettings.contentType = 'text/json';
- jQuery.mockjaxSettings.responseTime = 250;
- $j(document).ready(function () {
- $j('.open-modal').modal();
- $j('<scr' + 'ipt data-main="../js/component-viewer/app" src="../js/require.js"></scr' + 'ipt>').appendTo('body');
- });
- </script>
-</head>
-<body>
-
-<div id="body">
- <div class="error" id="error" style="display:none"><span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#error').hide();return false;">hide</a>]</div>
- <div class="warning" id="warning" style="display:none"><span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#warning').hide();return false;">hide</a>]</div>
- <div class="notice" id="info" style="display:none"><span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#info').hide();return false;">hide</a>]</div>
-
- <div id="component-viewer"></div>
-</div>
-
-</body>
-</html>
diff --git a/server/sonar-web/src/main/js/tests/e2e/pages/quality-gates.html b/server/sonar-web/src/main/js/tests/e2e/pages/quality-gates.html
deleted file mode 100644
index c2eaba8d13e..00000000000
--- a/server/sonar-web/src/main/js/tests/e2e/pages/quality-gates.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Quality Gates</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <link href="../css/sonar.css" rel="stylesheet" media="all"/>
-
- <script src="../js/sonar.js"></script>
- <script type="text/javascript">
- var baseUrl = '..';
- var $j = jQuery.noConflict();
- window.suppressTranslationWarnings = true;
- $j(document).ready(function () {
- $j('.open-modal').modal();
- $j('<scr' + 'ipt data-main="../js/quality-gate/app" src="../js/require.js"></scr' + 'ipt>').appendTo('body');
- });
- </script>
- </head>
- <body>
- <div id="container">
- <div id="body">
- <div id="content">
- <div class="error" id="error" style="display:none">
- <span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#error').hide();return false;"><%= message('hide').downcase -%></a>]
- </div>
- <div class="notice" id="info" style="display:none">
- <span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#info').hide();return false;"><%= message('hide').downcase -%></a>]
- </div>
- <div class="warning" id="warning" style="display:none">
- <span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$j('#warning').hide();return false;"><%= message('hide').downcase -%></a>]
- </div>
-
- <div id="quality-gate-page-loader" class="navigator-page-loader">
- <i class="spinner"></i>
- </div>
- </div>
- </div>
- </div>
- </body>
-</html>
diff --git a/server/sonar-web/src/main/js/tests/e2e/pages/treemap.html b/server/sonar-web/src/main/js/tests/e2e/pages/treemap.html
deleted file mode 100644
index 8f1779061e7..00000000000
--- a/server/sonar-web/src/main/js/tests/e2e/pages/treemap.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <link href="../css/sonar.css" rel="stylesheet" media="all"/>
- <script src="../js/sonar.js"></script>
- <script src="../js/third-party/jquery.mockjax.js"></script>
- <script type="text/javascript">
- var baseUrl = '';
- window.suppressTranslationWarnings = true;
- </script>
-</head>
-<body>
-<div id="container"></div>
-</body>
-</html>
diff --git a/server/sonar-web/src/main/js/tests/e2e/server.js b/server/sonar-web/src/main/js/tests/e2e/server.js
index 8173ed21f40..c925d50a526 100644
--- a/server/sonar-web/src/main/js/tests/e2e/server.js
+++ b/server/sonar-web/src/main/js/tests/e2e/server.js
@@ -1,13 +1,18 @@
-var express = require('express');
-var path = require('path');
+var express = require('express'),
+ path = require('path'),
+ app = express();
-var app = express();
+app.set('views', __dirname + '/views');
+app.set('view engine', 'jade');
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
// Serve static files
-app.use("/", express.static(path.join(__dirname, '../../..')));
-app.use("/pages", express.static(path.join(__dirname, 'pages')));
+app.use('/', express.static(path.join(__dirname, '../../../webapp')));
+
+app.get('/pages/:page', function (req, res) {
+ res.render(req.param('page'));
+});
// Get the port from environment variables
var port = process.env.PORT || 8000;
diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec.js b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec.js
index 6cedb49c60e..c807e35569f 100644
--- a/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec.js
+++ b/server/sonar-web/src/main/js/tests/e2e/tests/component-viewer-spec.js
@@ -1,23 +1,16 @@
var lib = require('../lib');
-
lib.initMessages();
lib.changeWorkingDirectory('component-viewer-spec');
casper.test.begin('Component Viewer Base Tests', function (test) {
-
- casper.options.onResourceRequested = function (instance, requestData) {
- if (requestData.url.indexOf('require') >= 0) {
- lib.mockRequest('../api/l10n/index', '{}');
- lib.mockRequestFromFile('../api/components/app', 'app.json');
- lib.mockRequestFromFile('../api/sources/show', 'source.json');
- }
- };
-
-
- casper.start(lib.buildUrl('component-viewer.html#component=component'), function () {
+ casper.start(lib.buildUrl('component-viewer#component=component'), function () {
lib.setDefaultViewport();
+
+ lib.mockRequest('/api/l10n/index', '{}');
+ lib.mockRequestFromFile('/api/components/app', 'app.json');
+ lib.mockRequestFromFile('/api/sources/show', 'source.json');
});
casper.wait(1000, function () {
diff --git a/server/sonar-web/src/main/js/tests/e2e/tests/treemap-spec.js b/server/sonar-web/src/main/js/tests/e2e/tests/treemap-spec.js
index ea868ae93db..36b41eb7003 100644
--- a/server/sonar-web/src/main/js/tests/e2e/tests/treemap-spec.js
+++ b/server/sonar-web/src/main/js/tests/e2e/tests/treemap-spec.js
@@ -1,37 +1,16 @@
-// Dump log messages
-casper.on('remote.message', function(message) {
- this.echo('Log: '+ message, 'LOG');
-});
-
-// Dump uncaught errors
-casper.on('page.error', function(msg, trace) {
- this.echo('Error: ' + msg, 'ERROR');
-});
-
-var fs = require('fs');
-var utils = require('utils');
-
-// Since Casper has control, the invoked script is deep in the argument stack
-var currentFile = require('system').args[4];
-var curFilePath = fs.absolute(currentFile).split(fs.separator);
-if (curFilePath.length > 1) {
- curFilePath.pop(); // PhantomJS does not have an equivalent path.baseName()-like method
- curFilePath.push('treemap-spec');
- fs.changeWorkingDirectory(curFilePath.join(fs.separator));
-}
+var lib = require('../lib');
+lib.initMessages();
+lib.changeWorkingDirectory('treemap-spec');
-casper.test.begin('Treemap', function suite(test) {
- // Load MockJax responses from FS
+casper.test.begin('Treemap', function (test) {
var treemapData = JSON.parse(fs.read('treemap.json'));
- var resourceResponse = fs.read('treemap-resources.json');
+ casper.start(lib.buildUrl('treemap'), function () {
+ lib.mockRequestFromFile('/api/resources/index', 'treemap-resources.json');
- casper.start('http://localhost:3000/pages/treemap.html', function () {
- casper.evaluate(function (treemapData, resourceResponse) {
- jQuery.mockjaxSettings.contentType = 'text/json';
- jQuery.mockjax({ url: '/api/resources/index', responseText: resourceResponse });
+ casper.evaluate(function (treemapData) {
var widget = new SonarWidgets.Treemap();
widget
.metrics(treemapData.metrics)
@@ -46,7 +25,7 @@ casper.test.begin('Treemap', function suite(test) {
resource: ''
})
.render('#container');
- }, treemapData, resourceResponse)
+ }, treemapData)
});
casper
diff --git a/server/sonar-web/src/main/js/tests/e2e/views/component-viewer.jade b/server/sonar-web/src/main/js/tests/e2e/views/component-viewer.jade
new file mode 100644
index 00000000000..3fd960c729a
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/views/component-viewer.jade
@@ -0,0 +1,7 @@
+extends ./layouts/main
+
+block header
+ script(data-main='/js/component-viewer/app', src='../js/require.js')
+
+block body
+ #component-viewer
diff --git a/server/sonar-web/src/main/js/tests/e2e/views/layouts/main.jade b/server/sonar-web/src/main/js/tests/e2e/views/layouts/main.jade
new file mode 100644
index 00000000000..f00db74124a
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/views/layouts/main.jade
@@ -0,0 +1,17 @@
+html
+ head
+ meta(http-equiv='Content-Type', content='text/html; charset=UTF-8')
+ link(href='/css/sonar.css', rel='stylesheet', media='all')
+ script(src='/js/sonar.js')
+ script(src='/js/third-party/jquery.mockjax.js')
+ script.
+ var baseUrl = '';
+ var $j = jQuery.noConflict();
+ window.suppressTranslationWarnings = true;
+ jQuery.mockjaxSettings.contentType = 'text/json';
+ jQuery.mockjaxSettings.responseTime = 250;
+ $j(document).ready(function () { $j('.open-modal').modal(); });
+ block header
+ body
+ #body
+ block body
diff --git a/server/sonar-web/src/main/js/tests/e2e/views/quality-gates.jade b/server/sonar-web/src/main/js/tests/e2e/views/quality-gates.jade
new file mode 100644
index 00000000000..58b27d60f0e
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/views/quality-gates.jade
@@ -0,0 +1,8 @@
+extends .layouts/main
+
+block header
+ script(data-main='/js/quality-gate/app', src='../js/require.js')
+
+block body
+ #quality-gate-page-loader.navigator-page-loader
+ i.spinner
diff --git a/server/sonar-web/src/main/js/tests/e2e/views/treemap.jade b/server/sonar-web/src/main/js/tests/e2e/views/treemap.jade
new file mode 100644
index 00000000000..3f6fbac8ae9
--- /dev/null
+++ b/server/sonar-web/src/main/js/tests/e2e/views/treemap.jade
@@ -0,0 +1,4 @@
+extends ./layouts/main
+
+block body
+ #container