mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[grunt test] always start a new server for the tests, added test:dev task
This commit is contained in:
parent
e39a47e9bf
commit
38ff67b019
5 changed files with 48 additions and 77 deletions
|
@ -16,15 +16,15 @@ module.exports = function (config) {
|
|||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'http://localhost:5601/bundles/commons.bundle.js',
|
||||
'http://localhost:5601/bundles/tests.bundle.js',
|
||||
'http://localhost:5601/bundles/commons.style.css',
|
||||
'http://localhost:5601/bundles/tests.style.css'
|
||||
'http://localhost:5610/bundles/commons.bundle.js',
|
||||
'http://localhost:5610/bundles/tests.bundle.js',
|
||||
'http://localhost:5610/bundles/commons.style.css',
|
||||
'http://localhost:5610/bundles/tests.style.css'
|
||||
],
|
||||
|
||||
proxies: {
|
||||
'/tests/': 'http://localhost:5601/tests/',
|
||||
'/bundles/': 'http://localhost:5601/bundles/'
|
||||
'/tests/': 'http://localhost:5610/tests/',
|
||||
'/bundles/': 'http://localhost:5610/bundles/'
|
||||
},
|
||||
|
||||
// test results reporter to use
|
||||
|
|
|
@ -1,12 +1,19 @@
|
|||
module.exports = function (grunt) {
|
||||
return {
|
||||
unit: {
|
||||
dev: {
|
||||
configFile: 'karma.conf.js',
|
||||
singleRun: true,
|
||||
reporters: 'dots',
|
||||
browsers: [
|
||||
'<%= karmaBrowser %>'
|
||||
]
|
||||
}
|
||||
},
|
||||
ci: {
|
||||
singleRun: true,
|
||||
configFile: 'karma.conf.js',
|
||||
reporters: 'dots',
|
||||
browsers: [
|
||||
'<%= karmaBrowser %>'
|
||||
]
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = function (grunt) {
|
|||
},
|
||||
cmd: './bin/kibana',
|
||||
args: [
|
||||
'--server.port=5610',
|
||||
'--env.name=development',
|
||||
'--logging.json=false',
|
||||
'--optimize.bundleFilter=tests',
|
||||
|
@ -19,6 +20,24 @@ module.exports = function (grunt) {
|
|||
]
|
||||
},
|
||||
|
||||
devTestServer: {
|
||||
options: {
|
||||
wait: false,
|
||||
quiet: false,
|
||||
failOnError: false
|
||||
},
|
||||
cmd: './bin/kibana',
|
||||
args: [
|
||||
'--dev',
|
||||
'--no-watch',
|
||||
'--server.port=5610',
|
||||
'--optimize.lazyPort=5611',
|
||||
'--logging.json=false',
|
||||
'--optimize.bundleFilter=tests',
|
||||
'--plugins.initialize=false'
|
||||
]
|
||||
},
|
||||
|
||||
optimizeBuild: {
|
||||
options: {
|
||||
wait: false,
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
module.exports = function (grunt) {
|
||||
var maybeStartServer = function (options) {
|
||||
return function () {
|
||||
var http = require('http');
|
||||
var opts = {
|
||||
method: 'HEAD',
|
||||
path: '/api/status',
|
||||
host: 'localhost',
|
||||
port: options.port
|
||||
};
|
||||
|
||||
grunt.log.debug('checking for server', JSON.stringify(opts));
|
||||
|
||||
var req = http.request(opts);
|
||||
|
||||
var done = (function (cb) {
|
||||
return function (res) {
|
||||
req.removeListener('error', onError);
|
||||
req.removeListener('response', onResponse);
|
||||
if (res) res.socket.destroy();
|
||||
cb();
|
||||
};
|
||||
}(this.async()));
|
||||
|
||||
function onResponse(res) {
|
||||
grunt.log.debug('Server responded with', res.statusCode);
|
||||
if (res.statusCode === 200 && res.headers['x-app-name'] === 'kibana') {
|
||||
grunt.log.ok('Kibana server already started on port', options.port);
|
||||
} else {
|
||||
grunt.log.error('Another server is already running on port', options.port);
|
||||
process.exit(1); // eslint-disable-line no-process-exit
|
||||
}
|
||||
|
||||
done(res);
|
||||
}
|
||||
|
||||
function onError(err) {
|
||||
if (err.code !== 'ECONNREFUSED') {
|
||||
grunt.log.error('Kibana server check failed', err);
|
||||
}
|
||||
|
||||
grunt.config.set(options.name, true);
|
||||
grunt.task.run(options.tasks);
|
||||
done();
|
||||
}
|
||||
|
||||
req.on('error', onError);
|
||||
req.on('response', onResponse);
|
||||
req.end();
|
||||
};
|
||||
};
|
||||
|
||||
grunt.registerTask('maybeStartTestServer', maybeStartServer({
|
||||
name: 'kibana-server',
|
||||
port: grunt.option('port') || 5601,
|
||||
tasks: ['run:testServer']
|
||||
}));
|
||||
};
|
|
@ -9,21 +9,24 @@ module.exports = function (grunt) {
|
|||
grunt.task.run(_.compact([
|
||||
'eslint:source',
|
||||
'simplemocha:all',
|
||||
'maybeStartTestServer',
|
||||
'karma:unit'
|
||||
'run:testServer',
|
||||
'karma:ci'
|
||||
]));
|
||||
});
|
||||
|
||||
grunt.registerTask('quick-test', function () {
|
||||
grunt.task.run([
|
||||
'simplemocha:all',
|
||||
'maybeStartTestServer',
|
||||
'karma:unit'
|
||||
]);
|
||||
});
|
||||
grunt.registerTask('quick-test', [
|
||||
'simplemocha:all',
|
||||
'run:testServer',
|
||||
'karma:ci'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:dev', [
|
||||
'run:devTestServer',
|
||||
'karma:dev'
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:watch', [
|
||||
'maybeStartTestServer',
|
||||
'run:testServer',
|
||||
'watch:test'
|
||||
]);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue