Skip to content

Commit

Permalink
add intern test framework, setup initial unit and medium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-vilchik committed Jun 30, 2015
1 parent 501289c commit 3860f8a
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 194 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ env:
- JOB=H2
- JOB=POSTGRES
- JOB=MYSQL
- JOB=WEB
- JOB=PRANALYSIS

script:
Expand Down
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@

<skipBatchTests>false</skipBatchTests>
<skipServerTests>false</skipServerTests>
<skipWebTests>false</skipWebTests>
<jsCoverage>nocoverage</jsCoverage>

<version.maven-license.plugin>1.9.0</version.maven-license.plugin>
<skipSanityChecks>false</skipSanityChecks>
Expand Down Expand Up @@ -1507,7 +1505,6 @@
</property>
</activation>
<properties>
<skipWebTests>true</skipWebTests>
<skipBatchTests>true</skipBatchTests>
<skipServerTests>true</skipServerTests>
</properties>
Expand All @@ -1517,15 +1514,13 @@
<id>batch</id>
<properties>
<skipServerTests>true</skipServerTests>
<skipWebTests>true</skipWebTests>
</properties>
</profile>

<profile>
<id>server</id>
<properties>
<skipBatchTests>true</skipBatchTests>
<skipWebTests>true</skipWebTests>
</properties>
</profile>

Expand All @@ -1548,7 +1543,6 @@
</property>
</activation>
<properties>
<skipWebTests>true</skipWebTests>
<junitGroups>org.sonar.test.DbTests</junitGroups>
</properties>
<dependencies>
Expand Down Expand Up @@ -1609,7 +1603,6 @@
<profile>
<id>analysis</id>
<properties>
<jsCoverage>coverage</jsCoverage>
<coveragePerTest>true</coveragePerTest>
</properties>
</profile>
Expand Down
175 changes: 23 additions & 152 deletions server/sonar-web/Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = (grunt) ->
require('jit-grunt')(grunt, {
express: 'grunt-express-server'
unzip: 'grunt-zip'
replace: 'grunt-text-replace'
});
require('time-grunt')(grunt);

useBrowserStack = !!process.env['BROWSERSTACK_USERNAME'] && !!process.env['BROWSERSTACK_ACCESS_KEY']
expressPort = '<%= grunt.option("port") || 3000 %>'
internPort = '<%= grunt.option("internPort") || 9100 %>'

grunt.initConfig
pkg: grunt.file.readJSON('package.json')
Expand Down Expand Up @@ -143,32 +144,6 @@ module.exports = (grunt) ->
'requirejs:issuesContext'
'requirejs:selectList'
]
casper:
tasks: [
'casper:apiDocumentation'
'casper:application'
'casper:codingRules'
'casper:issueFilterWidget'
'casper:handlebarsHelpers'
'casper:issues'
'casper:markdown'
'casper:nav'
'casper:process'
'casper:qualityGates'
'casper:qualityProfiles'
'casper:sourceViewer'
'casper:treemap'
'casper:ui'
'casper:workspace'
'casper:users'
'casper:groups'
'casper:provisioning'
'casper:computation'
'casper:metrics'
'casper:maintenance'
'casper:updateCenter'
'casper:histogram'
]


handlebars:
Expand Down Expand Up @@ -267,125 +242,37 @@ module.exports = (grunt) ->
src: '<%= BUILD_PATH %>/css/sonar.css', dest: '<%= ASSETS_PATH %>/css/sonar.css'


express:
test:
options:
script: 'src/test/server.js'
port: expressPort
testCoverage:
options:
script: 'src/test/server-coverage.js'
port: expressPort
dev:
options:
background: false
script: 'src/test/server.js'


casper:
options:
test: true
'fail-fast': true
concise: true
'no-colors': true
port: expressPort
testCoverageLight:
options:
concise: false
verbose: true
'no-colors': false
src: ['src/test/js/**/*<%= grunt.option("spec") %>*.js']
single:
options:
concise: false
verbose: true
'no-colors': false
src: ['src/test/js/<%= grunt.option("spec") %>-spec.js']
testfile:
options:
concise: false
verbose: true
'no-colors': false
src: ['<%= grunt.option("file") %>']

apiDocumentation:
src: ['src/test/js/api-documentation*.js']
application:
src: ['src/test/js/application*.js']
codingRules:
src: ['src/test/js/coding-rules*.js']
issueFilterWidget:
src: ['src/test/js/*issue-filter-widget*.js']
handlebarsHelpers:
src: ['src/test/js/handlebars-helpers*.js']
issues:
src: ['src/test/js/issues*.js']
markdown:
src: ['src/test/js/markdown*.js']
nav:
src: ['src/test/js/nav*.js']
process:
src: ['src/test/js/process*.js']
qualityGates:
src: ['src/test/js/quality-gates*.js']
qualityProfiles:
src: ['src/test/js/quality-profiles*.js']
sourceViewer:
src: ['src/test/js/source-viewer*.js']
treemap:
src: ['src/test/js/treemap*.js']
ui:
src: ['src/test/js/ui*.js']
workspace:
src: ['src/test/js/workspace*.js']
users:
src: ['src/test/js/users*.js']
provisioning:
src: ['src/test/js/provisioning*.js']
computation:
src: ['src/test/js/computation*.js']
groups:
src: ['src/test/js/groups-spec.js']
metrics:
src: ['src/test/js/metrics-spec.js']
maintenance:
src: ['src/test/js/maintenance-spec.js']
updateCenter:
src: ['src/test/js/update-center-spec.js']
histogram:
src: ['src/test/js/histogram-spec.js']

uglify:
build:
src: '<%= ASSETS_PATH %>/js/sonar.js'
dest: '<%= ASSETS_PATH %>/js/sonar.js'


curl:
resetCoverage:
src:
url: 'http://localhost:' + expressPort + '/coverage/reset'
method: 'POST'
dest: 'target/reset_coverage.dump'

downloadCoverage:
src: 'http://localhost:' + expressPort + '/coverage/download'
dest: 'target/coverage.zip'


unzip:
'target/js-coverage': 'target/coverage.zip'


replace:
lcov:
src: 'target/js-coverage/lcov.info'
dest: 'target/js-coverage/lcov.info'
src: 'target/web-tests/lcov.info'
dest: 'target/web-tests/lcov.info'
replacements: [
{ from: '/build/', to: '/src/main/' }
]


rename:
lcov:
src: 'lcov.info'
dest: 'target/web-tests/lcov.info'


intern:
test:
options:
runType: 'runner'
config: 'test/intern'
proxyPort: expressPort
proxyUrl: 'http://localhost:' + expressPort + '/'
useBrowserStack: useBrowserStack


jshint:
dev:
src: [
Expand Down Expand Up @@ -427,11 +314,10 @@ module.exports = (grunt) ->
['copy:assets-css', 'copy:assets-js', 'concurrent:build']

grunt.registerTask 'test-suffix',
['express:test', 'concurrent:casper']
['intern:test', 'rename:lcov', 'replace:lcov']

grunt.registerTask 'coverage-suffix',
['express:testCoverage', 'curl:resetCoverage', 'concurrent:casper', 'curl:downloadCoverage', 'unzip',
'replace:lcov']
['test-suffix']

grunt.registerTask 'build-app', (app) ->
grunt.option 'app', app
Expand Down Expand Up @@ -467,24 +353,9 @@ module.exports = (grunt) ->
grunt.registerTask 'dw',
['build-fast', 'watch']

grunt.registerTask 'testCoverageLight',
['prepare', 'express:testCoverage', 'curl:resetCoverage', 'casper:testCoverageLight', 'curl:downloadCoverage', 'unzip', 'replace:lcov']

grunt.registerTask 'single',
['prepare', 'express:test', 'casper:single']

grunt.registerTask 'testfile',
['prepare', 'express:test', 'casper:testfile']

# tasks used by Maven build (see pom.xml)
grunt.registerTask 'maven-quick-build',
['build-fast']

grunt.registerTask 'maven-build-skip-tests-true-nocoverage',
grunt.registerTask 'maven-build',
['build']

grunt.registerTask 'maven-build-skip-tests-false-nocoverage',
['build-test']

grunt.registerTask 'maven-build-skip-tests-false-coverage',
['build-coverage']
14 changes: 2 additions & 12 deletions server/sonar-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
"name": "SonarQube",
"version": "0.0.1",
"devDependencies": {
"body-parser": "1.13.0",
"casperjs": "1.1.0-beta3",
"errorhandler": "1.1.1",
"express": "4.8.0",
"grunt": "0.4.5",
"grunt-casper": "0.3.9",
"grunt-cli": "0.1.13",
"grunt-concurrent": "1.0.0",
"grunt-contrib-clean": "0.6.0",
Expand All @@ -18,15 +13,10 @@
"grunt-contrib-requirejs": "0.4.4",
"grunt-contrib-uglify": "0.9.1",
"grunt-contrib-watch": "0.6.1",
"grunt-curl": "2.1.0",
"grunt-express-server": "0.4.17",
"grunt-rename": "^0.1.4",
"grunt-text-replace": "0.4.0",
"grunt-zip": "0.16.2",
"istanbul": "0.3.5",
"istanbul-middleware": "0.2.0",
"jade": "1.4.2",
"intern": "^3.0.0-rc.1",
"jit-grunt": "0.9.1",
"serve-static": "1.5.0",
"time-grunt": "1.2.1"
},
"scripts": {
Expand Down
21 changes: 1 addition & 20 deletions server/sonar-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<!-- self-analysis -->
<sonar.sources>src/main/js,src/main/less</sonar.sources>
<sonar.exclusions>src/main/js/libs/third-party/**/*,src/main/js/libs/require.js</sonar.exclusions>
<sonar.javascript.lcov.reportPath>target/js-coverage/lcov.info</sonar.javascript.lcov.reportPath>
<grunt.arguments>maven-build-skip-tests-${skipWebTests}-${jsCoverage} --port=${jsTestPort} --no-color</grunt.arguments>
<grunt.arguments>maven-build --no-color</grunt.arguments>
</properties>

<build>
Expand Down Expand Up @@ -83,24 +82,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>initialize</phase>
<configuration>
<portNames>
<portName>jsTestPort</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
Expand Down
30 changes: 30 additions & 0 deletions server/sonar-web/test/intern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* jshint node:true */
define(['intern'], function (intern) {
var useBrowserStack = intern.args.useBrowserStack,
tunnel = useBrowserStack ? 'BrowserStackTunnel' : 'NullTunnel';

return {
excludeInstrumentation: /(test|third-party|node_modules)\//,

defaultTimeout: 60 * 1000,

reporters: [
{ id: 'Runner' },
{ id: 'Lcov' },
{ id: 'LcovHtml', directory: 'target/web-tests' }
],

suites: [
'test/unit/application.spec'
],

functionalSuites: [
'test/medium/users.spec'
],

tunnel: tunnel,
environments: [
{ browserName: 'firefox' }
]
};
});
Loading

0 comments on commit 3860f8a

Please sign in to comment.