mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 16:54:04 +02:00
Remove obsolete JavaScript tests
This commit is contained in:
parent
afc905f090
commit
8ca9437a9c
@ -1 +0,0 @@
|
|||||||
../../library/vendor/**
|
|
@ -1,6 +0,0 @@
|
|||||||
/* See http://www.jshint.com/docs/#usage on how to use this file */
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
from pipes import quote
|
|
||||||
from fnmatch import fnmatch
|
|
||||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
|
||||||
|
|
||||||
|
|
||||||
APPLICATION = 'jshint'
|
|
||||||
DEFAULT_ARGS = []
|
|
||||||
|
|
||||||
VAGRANT_SCRIPT = '/vagrant/test/js/checkswag'
|
|
||||||
REPORT_DIRECTORY = '../../build/log'
|
|
||||||
|
|
||||||
|
|
||||||
class PassThroughOptionParser(OptionParser):
|
|
||||||
"""
|
|
||||||
An unknown option pass-through implementation of OptionParser.
|
|
||||||
|
|
||||||
When unknown arguments are encountered, bundle with largs and try again,
|
|
||||||
until rargs is depleted.
|
|
||||||
|
|
||||||
sys.exit(status) will still be called if a known argument is passed
|
|
||||||
incorrectly (e.g. missing arguments or bad argument types, etc.)
|
|
||||||
|
|
||||||
Borrowed from: http://stackoverflow.com/a/9307174
|
|
||||||
"""
|
|
||||||
def _process_args(self, largs, rargs, values):
|
|
||||||
while rargs:
|
|
||||||
try:
|
|
||||||
OptionParser._process_args(self, largs, rargs, values)
|
|
||||||
except (BadOptionError, AmbiguousOptionError), error:
|
|
||||||
largs.append(error.opt_str)
|
|
||||||
|
|
||||||
|
|
||||||
def execute_command(command, return_output=False, shell=False):
|
|
||||||
prog = subprocess.Popen(command, shell=shell,
|
|
||||||
stdout=subprocess.PIPE
|
|
||||||
if return_output
|
|
||||||
else None)
|
|
||||||
return prog.wait() if not return_output else \
|
|
||||||
prog.communicate()[0]
|
|
||||||
|
|
||||||
|
|
||||||
def get_report_directory():
|
|
||||||
path = os.path.abspath(REPORT_DIRECTORY)
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.makedirs(REPORT_DIRECTORY)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def get_script_directory():
|
|
||||||
return os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
||||||
|
|
||||||
|
|
||||||
def parse_commandline():
|
|
||||||
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
|
|
||||||
' for {0}]'.format(APPLICATION))
|
|
||||||
parser.add_option('-b', '--build', action='store_true',
|
|
||||||
help='Enable reporting.')
|
|
||||||
parser.add_option('-v', '--verbose', action='store_true',
|
|
||||||
help='Be more verbose.')
|
|
||||||
parser.add_option('-i', '--include', metavar='PATTERN', action='append',
|
|
||||||
help='Include only specific files/test cases.'
|
|
||||||
' (Can be supplied multiple times.)')
|
|
||||||
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
|
|
||||||
help='Exclude specific files/test cases. '
|
|
||||||
'(Can be supplied multiple times.)')
|
|
||||||
parser.add_option('-V', '--vagrant', action='store_true',
|
|
||||||
help='Run in vagrant VM')
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
options, arguments = parse_commandline()
|
|
||||||
|
|
||||||
if options.vagrant and os.environ['USER'] != 'vagrant':
|
|
||||||
# Check if vagrant is installed
|
|
||||||
vagrant_path = execute_command('which vagrant', True, True).strip()
|
|
||||||
if not vagrant_path:
|
|
||||||
print 'ERROR: vagrant not found!'
|
|
||||||
return 2
|
|
||||||
|
|
||||||
# Call the script in the Vagrant VM with the same parameters
|
|
||||||
commandline = ' '.join(quote(p) for p in sys.argv[1:])
|
|
||||||
return execute_command('vagrant ssh -c "{0} {1}"'
|
|
||||||
''.format(VAGRANT_SCRIPT, commandline),
|
|
||||||
shell=True)
|
|
||||||
else:
|
|
||||||
# Environment preparation and verification
|
|
||||||
os.chdir(get_script_directory())
|
|
||||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
|
||||||
True, True).strip()
|
|
||||||
if not application_path:
|
|
||||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
|
||||||
return 2
|
|
||||||
|
|
||||||
# Commandline preparation
|
|
||||||
command_options = []
|
|
||||||
if options.build:
|
|
||||||
command_options.extend(['--reporter', 'jslint'])
|
|
||||||
else:
|
|
||||||
command_options.append('--verbose')
|
|
||||||
if options.verbose:
|
|
||||||
command_options.append('--show-non-errors')
|
|
||||||
path_args = [arguments.remove(a) or a
|
|
||||||
for a in arguments[:len(arguments)]
|
|
||||||
if os.path.isfile(a) or os.path.isdir(a)]
|
|
||||||
if not path_args:
|
|
||||||
path_args = ['../../public/js/icinga', '../../bin',
|
|
||||||
'../../modules/']
|
|
||||||
if options.include:
|
|
||||||
path_args = [os.path.join(r, f)
|
|
||||||
for a in path_args
|
|
||||||
for r, _, fs in os.walk(a)
|
|
||||||
for f in fs
|
|
||||||
if any(fnmatch(os.path.join(r, f), p)
|
|
||||||
for p in options.include)]
|
|
||||||
if options.exclude:
|
|
||||||
walk = lambda p: os.walk(p) if os.path.isdir(p) else \
|
|
||||||
[(os.path.dirname(p), None,
|
|
||||||
[os.path.basename(p)])]
|
|
||||||
path_args = [os.path.join(r, f)
|
|
||||||
for a in path_args
|
|
||||||
for r, _, fs in walk(a)
|
|
||||||
for f in fs
|
|
||||||
if not any(fnmatch(os.path.join(r, f), p)
|
|
||||||
for p in options.exclude)]
|
|
||||||
|
|
||||||
# Application invocation..
|
|
||||||
if options.build:
|
|
||||||
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
|
||||||
command_options + arguments +
|
|
||||||
path_args, True)
|
|
||||||
result_path = os.path.join(get_report_directory(),
|
|
||||||
'jshint_results.xml')
|
|
||||||
with open(result_path, 'w') as result_file:
|
|
||||||
result_file.write(result_data)
|
|
||||||
else:
|
|
||||||
print (application_path )
|
|
||||||
execute_command([application_path] + DEFAULT_ARGS +
|
|
||||||
command_options + arguments + path_args)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
@ -1,39 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
describe('regression test for bug #4102', function(){
|
|
||||||
it('Object.create', function(){
|
|
||||||
Object.create.should.be.a('function');
|
|
||||||
|
|
||||||
var t = {
|
|
||||||
name: 'test123'
|
|
||||||
};
|
|
||||||
|
|
||||||
t.should.have.property('name').and.equal('test123');
|
|
||||||
});
|
|
||||||
});
|
|
149
test/js/runtests
149
test/js/runtests
@ -1,149 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
from pipes import quote
|
|
||||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
|
||||||
|
|
||||||
|
|
||||||
APPLICATION = 'mocha'
|
|
||||||
DEFAULT_ARGS = ['--recursive', '--require', 'should']
|
|
||||||
|
|
||||||
VAGRANT_SCRIPT = '/vagrant/test/js/runtests'
|
|
||||||
REPORT_DIRECTORY = '../../build/log'
|
|
||||||
|
|
||||||
|
|
||||||
class PassThroughOptionParser(OptionParser):
|
|
||||||
"""
|
|
||||||
An unknown option pass-through implementation of OptionParser.
|
|
||||||
|
|
||||||
When unknown arguments are encountered, bundle with largs and try again,
|
|
||||||
until rargs is depleted.
|
|
||||||
|
|
||||||
sys.exit(status) will still be called if a known argument is passed
|
|
||||||
incorrectly (e.g. missing arguments or bad argument types, etc.)
|
|
||||||
|
|
||||||
Borrowed from: http://stackoverflow.com/a/9307174
|
|
||||||
"""
|
|
||||||
def _process_args(self, largs, rargs, values):
|
|
||||||
while rargs:
|
|
||||||
try:
|
|
||||||
OptionParser._process_args(self, largs, rargs, values)
|
|
||||||
except (BadOptionError, AmbiguousOptionError), error:
|
|
||||||
largs.append(error.opt_str)
|
|
||||||
|
|
||||||
|
|
||||||
def execute_command(command, return_output=False, shell=False):
|
|
||||||
prog = subprocess.Popen(command, shell=shell,
|
|
||||||
stdout=subprocess.PIPE
|
|
||||||
if return_output
|
|
||||||
else None)
|
|
||||||
return prog.wait() if not return_output else \
|
|
||||||
prog.communicate()[0]
|
|
||||||
|
|
||||||
|
|
||||||
def get_report_directory():
|
|
||||||
path = os.path.abspath(REPORT_DIRECTORY)
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.makedirs(REPORT_DIRECTORY)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def get_script_directory():
|
|
||||||
return os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
||||||
|
|
||||||
|
|
||||||
def parse_commandline():
|
|
||||||
parser = PassThroughOptionParser(usage='%prog [options] [additional arguments'
|
|
||||||
' for {0}]'.format(APPLICATION))
|
|
||||||
parser.add_option('-b', '--build', action='store_true',
|
|
||||||
help='Enable reporting.')
|
|
||||||
parser.add_option('-v', '--verbose', action='store_true',
|
|
||||||
help='Be more verbose.')
|
|
||||||
parser.add_option('-i', '--include', metavar='PATTERN', action='append',
|
|
||||||
help='Include only specific files/test cases.'
|
|
||||||
' (Can be supplied multiple times.)')
|
|
||||||
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
|
|
||||||
help='Exclude specific files/test cases. '
|
|
||||||
'(Can be supplied multiple times.)')
|
|
||||||
parser.add_option('-V', '--vagrant', action='store_true',
|
|
||||||
help='Run in vagrant VM')
|
|
||||||
return parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
options, arguments = parse_commandline()
|
|
||||||
|
|
||||||
if options.vagrant and os.environ['USER'] != 'vagrant':
|
|
||||||
# Check if vagrant is installed
|
|
||||||
vagrant_path = execute_command('which vagrant', True, True).strip()
|
|
||||||
if not vagrant_path:
|
|
||||||
print 'ERROR: vagrant not found!'
|
|
||||||
return 2
|
|
||||||
|
|
||||||
# Call the script in the Vagrant VM with the same parameters
|
|
||||||
commandline = ' '.join(quote(p) for p in sys.argv[1:])
|
|
||||||
return execute_command('vagrant ssh -c "{0} {1}"'
|
|
||||||
''.format(VAGRANT_SCRIPT, commandline),
|
|
||||||
shell=True)
|
|
||||||
else:
|
|
||||||
# Environment preparation and verification
|
|
||||||
os.chdir(get_script_directory())
|
|
||||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
|
||||||
True, True).strip()
|
|
||||||
if not application_path:
|
|
||||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
|
||||||
return 2
|
|
||||||
os.environ['NODE_PATH'] = os.environ.get('NODE_PATH', '') + \
|
|
||||||
':/usr/local/lib/node_modules' \
|
|
||||||
':/usr/local/share/npm/lib/node_modules' \
|
|
||||||
':/usr/lib/node_modules:./testlib'
|
|
||||||
|
|
||||||
# Commandline preparation
|
|
||||||
command_options, more_command_options = [], None
|
|
||||||
if options.include or options.exclude:
|
|
||||||
for pattern in (options.include or options.exclude):
|
|
||||||
command_options.append('--grep')
|
|
||||||
command_options.append(pattern)
|
|
||||||
if options.exclude:
|
|
||||||
command_options.append('--invert')
|
|
||||||
if options.build:
|
|
||||||
more_command_options = command_options[:len(command_options)] + \
|
|
||||||
['--reporter', 'mocha-cobertura-reporter']
|
|
||||||
command_options.extend(['--reporter', 'xunit'])
|
|
||||||
elif options.verbose:
|
|
||||||
command_options.extend(['--reporter', 'spec'])
|
|
||||||
else:
|
|
||||||
command_options.extend(['--reporter', 'nyan'])
|
|
||||||
if not any(os.path.isfile(a) or os.path.isdir(a) for a in arguments):
|
|
||||||
arguments.append('.')
|
|
||||||
|
|
||||||
# Application invocation..
|
|
||||||
if more_command_options is None:
|
|
||||||
execute_command([application_path] + DEFAULT_ARGS +
|
|
||||||
command_options + arguments)
|
|
||||||
else:
|
|
||||||
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
|
||||||
command_options + arguments, True)
|
|
||||||
coverage_data = execute_command([application_path] + DEFAULT_ARGS +
|
|
||||||
more_command_options + arguments,
|
|
||||||
return_output=True)
|
|
||||||
# Result storage
|
|
||||||
report_directory = get_report_directory()
|
|
||||||
result_path = os.path.join(report_directory, 'mocha_results.xml')
|
|
||||||
coverage_path = os.path.join(report_directory, 'mocha_coverage.xml')
|
|
||||||
with open(result_path, 'w') as result_file:
|
|
||||||
result_file.write(result_data)
|
|
||||||
with open(coverage_path, 'w') as coverage_file:
|
|
||||||
coverage_file.write(coverage_data)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
@ -1,168 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
require('should');
|
|
||||||
var rjsmock = require('requiremock.js');
|
|
||||||
|
|
||||||
GLOBAL.document = $('body');
|
|
||||||
var component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the test fixture
|
|
||||||
*
|
|
||||||
* @param registry The optional registry mock that should be used.
|
|
||||||
*/
|
|
||||||
var setUp = function(registry)
|
|
||||||
{
|
|
||||||
rjsmock.purgeDependencies();
|
|
||||||
|
|
||||||
requireNew('icinga/componentRegistry.js');
|
|
||||||
registry = registry || rjsmock.getDefine();
|
|
||||||
|
|
||||||
rjsmock.registerDependencies({
|
|
||||||
'icinga/componentRegistry': registry,
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Available components
|
|
||||||
*/
|
|
||||||
'components/app/component1': function(cmp) {
|
|
||||||
cmp.test = 'changed-by-component-1';
|
|
||||||
this.type = function() {
|
|
||||||
return "app/component1";
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
'components/app/component2': function(cmp) {
|
|
||||||
cmp.test = 'changed-by-component-2';
|
|
||||||
this.type = function() {
|
|
||||||
return "app/component2";
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
'components/module/component3': function(cmp) {
|
|
||||||
cmp.test = 'changed-by-component-3-from-module';
|
|
||||||
this.type = function() {
|
|
||||||
return "module/component3";
|
|
||||||
};
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('body').empty();
|
|
||||||
requireNew('icinga/componentLoader.js');
|
|
||||||
component = rjsmock.getDefine();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new component to the current test-DOM
|
|
||||||
*
|
|
||||||
* @param type {String} The type of the component in the form: "<module>/<type>"
|
|
||||||
* @param id {String} The optional id of the component
|
|
||||||
*/
|
|
||||||
var addComponent = function(type, id) {
|
|
||||||
var txt = '<div ' + ( id ? ( ' id= "' + id + '" ' ) : '' ) +
|
|
||||||
' data-icinga-component="' + type + '" >test</div>';
|
|
||||||
|
|
||||||
$('body').append(txt);
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Component loader', function() {
|
|
||||||
|
|
||||||
it('Component loaded with automatic id', function() {
|
|
||||||
setUp();
|
|
||||||
addComponent('app/component1');
|
|
||||||
component.load(function() {
|
|
||||||
var cmpNode = $('#icinga-component-0');
|
|
||||||
cmpNode.length.should.equal(1);
|
|
||||||
cmpNode[0].test.should.equal('changed-by-component-1');
|
|
||||||
component.getById('icinga-component-0').type().should.equal('app/component1');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('Component load with user-defined id', function() {
|
|
||||||
setUp();
|
|
||||||
addComponent('app/component2','some-id');
|
|
||||||
|
|
||||||
component.load(function() {
|
|
||||||
var cmpNode = $('#some-id');
|
|
||||||
cmpNode.length.should.equal(1);
|
|
||||||
cmpNode[0].test.should.equal('changed-by-component-2');
|
|
||||||
component.getById('some-id').type().should.equal('app/component2');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Garbage collection removes deleted components', function() {
|
|
||||||
setUp();
|
|
||||||
addComponent('app/component1');
|
|
||||||
addComponent('app/component2');
|
|
||||||
addComponent('app/component2');
|
|
||||||
addComponent('module/component3');
|
|
||||||
|
|
||||||
component.load(function() {
|
|
||||||
var components = component.getComponents();
|
|
||||||
components.length.should.equal(4);
|
|
||||||
$('body').empty();
|
|
||||||
component.load(function() {
|
|
||||||
var components = component.getComponents();
|
|
||||||
components.length.should.equal(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Component queries are delegated to the registry correctly', function() {
|
|
||||||
var getByIdCalled = false;
|
|
||||||
var getByTypeCalled = false;
|
|
||||||
var getComponentsCalled = false;
|
|
||||||
|
|
||||||
var registryMock = {
|
|
||||||
getById: function(id) {
|
|
||||||
getByIdCalled = true;
|
|
||||||
id.should.equal('some-id');
|
|
||||||
},
|
|
||||||
getByType: function(type) {
|
|
||||||
getByTypeCalled = true;
|
|
||||||
type.should.equal('some-type');
|
|
||||||
},
|
|
||||||
getComponents: function() {
|
|
||||||
getComponentsCalled = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
setUp(registryMock);
|
|
||||||
|
|
||||||
component.getById('some-id');
|
|
||||||
getByIdCalled.should.be.true;
|
|
||||||
|
|
||||||
component.getByType('some-type');
|
|
||||||
getByTypeCalled.should.be.true;
|
|
||||||
|
|
||||||
component.getComponents();
|
|
||||||
getComponentsCalled.should.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/*global requireNew:false, describe: false, it:false */
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The assertion framework
|
|
||||||
*
|
|
||||||
* @type {should}
|
|
||||||
*/
|
|
||||||
var should = require('should');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RequireJS mocks for dynamically loading modules
|
|
||||||
*
|
|
||||||
* @type {requiremock}
|
|
||||||
*/
|
|
||||||
var rjsmock = require('requiremock.js');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* URIjs object for easier URL manipulation
|
|
||||||
*
|
|
||||||
* @type {URIjs}
|
|
||||||
*/
|
|
||||||
var URI = require('URIjs');
|
|
||||||
|
|
||||||
// Setup required globals for this test
|
|
||||||
GLOBAL.document = $('body');
|
|
||||||
GLOBAL.History = require('historymock.js');
|
|
||||||
GLOBAL.Modernizr = {
|
|
||||||
history: true
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Workaround as jQuery.contains doesn't work with the nodejs jQuery library on some test systems
|
|
||||||
*
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
jQuery.contains = function() {
|
|
||||||
'use strict';
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a basic dom only containing a main and detail container
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
var createDOM = function() {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
document.empty();
|
|
||||||
document.append(
|
|
||||||
$('<div>').attr('id', 'icingamain')
|
|
||||||
).append(
|
|
||||||
$('<div>').attr('id', 'icingadetail')
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax = function(obj) {
|
|
||||||
obj.success("<div></div>");
|
|
||||||
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Test case
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
describe('The container component', function() {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test dom selectors and instance creation
|
|
||||||
*/
|
|
||||||
it('should provide access to the main and detail component', function() {
|
|
||||||
createDOM();
|
|
||||||
|
|
||||||
rjsmock.registerDependencies({
|
|
||||||
'URIjs/URI' : URI,
|
|
||||||
'icinga/util/url' : 'icinga/util/url.js'
|
|
||||||
});
|
|
||||||
requireNew('icinga/components/container.js');
|
|
||||||
var Container = rjsmock.getDefine();
|
|
||||||
should.exist(Container.getMainContainer().containerDom, 'Assert that the main container has an DOM attached');
|
|
||||||
should.exist(Container.getDetailContainer().containerDom, 'Assert that the detail container has an DOM attached');
|
|
||||||
Container.getMainContainer().containerDom[0].should.equal(
|
|
||||||
$('#icingamain')[0], 'Assert the DOM of the main container being #icingamain');
|
|
||||||
Container.getDetailContainer().containerDom[0].should.equal(
|
|
||||||
$('#icingadetail')[0], 'Assert the DOM of the detail container being #icingadetail');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
@ -1,139 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
var should = require('should');
|
|
||||||
var rjsmock = require('requiremock.js');
|
|
||||||
|
|
||||||
GLOBAL.document = $('body');
|
|
||||||
|
|
||||||
var registry;
|
|
||||||
var setUp = function() {
|
|
||||||
requireNew('icinga/componentRegistry.js');
|
|
||||||
registry = rjsmock.getDefine();
|
|
||||||
};
|
|
||||||
|
|
||||||
var cleanTestDom = function() {
|
|
||||||
$('body').empty();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
describe('Component registry',function() {
|
|
||||||
it('Ids are created automatically in the form "icinga-component-<id>"', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
registry.add({}, null, null).should.equal('icinga-component-0');
|
|
||||||
registry.add({}, null, null).should.equal('icinga-component-1');
|
|
||||||
registry.add({}, null, null).should.equal('icinga-component-2');
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('Existing ids are preserved', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
registry.add({}, 'user-defined-id', null).should.equal('user-defined-id');
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Components are correctly added to the library', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
|
||||||
registry.add(cmp2, null, null);
|
|
||||||
registry.getById('icinga-component-0').should.equal(cmp2);
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not supported anymore
|
|
||||||
*/
|
|
||||||
xit('getId(component) should return the components assigned id.', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
var cmp1 = { component: "cmp1" };
|
|
||||||
registry.add(cmp1, 'user-defined-id', null);
|
|
||||||
registry.getId(cmp1).should.equal('user-defined-id');
|
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
|
||||||
registry.add(cmp2, 'user-defined-id-2',null);
|
|
||||||
registry.getId(cmp2).should.equal('user-defined-id-2');
|
|
||||||
|
|
||||||
should.not.exist(registry.getId({}));
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getByType() should return all components of a certain type', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
var cmp1 = { component: "some/type" };
|
|
||||||
registry.add(cmp1,'some/type');
|
|
||||||
|
|
||||||
var cmp2 = { component: "some/type" };
|
|
||||||
registry.add(cmp2, "some/type");
|
|
||||||
|
|
||||||
var cmp3 = { component: "other/type" };
|
|
||||||
registry.add(cmp3, "other/type");
|
|
||||||
|
|
||||||
var cmps = registry.getByType('some/type');
|
|
||||||
cmps.length.should.equal(2);
|
|
||||||
cmps[0].component.should.equal('some/type');
|
|
||||||
cmps[1].component.should.equal('some/type');
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getComponents() should return all components', function() {
|
|
||||||
setUp();
|
|
||||||
|
|
||||||
var cmp1 = { component: "cmp1" };
|
|
||||||
registry.add(cmp1, null, null);
|
|
||||||
|
|
||||||
var cmp2 = { component: "cmp2" };
|
|
||||||
registry.add(cmp2, null, null);
|
|
||||||
|
|
||||||
var cmp3 = { component: "cmp3" };
|
|
||||||
registry.add(cmp3, null, null);
|
|
||||||
|
|
||||||
var cmps = registry.getComponents();
|
|
||||||
cmps.length.should.equal(3);
|
|
||||||
cmps[0].should.equal(cmp1);
|
|
||||||
cmps[1].should.equal(cmp2);
|
|
||||||
cmps[2].should.equal(cmp3);
|
|
||||||
|
|
||||||
cleanTestDom();
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
* NOTE: The functionality of the garbage collection of this class is
|
|
||||||
* tested in the componentTest.js
|
|
||||||
*/
|
|
||||||
});
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper for mocking $.async's XHR requests
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
var getCallback = function(empty, response, succeed, headers) {
|
|
||||||
if (empty)
|
|
||||||
return function() {};
|
|
||||||
return function(callback) {
|
|
||||||
callback(response, succeed, {
|
|
||||||
getAllResponseHeaders: function() {
|
|
||||||
return headers;
|
|
||||||
},
|
|
||||||
getResponseHeader: function(header) {
|
|
||||||
return headers[header] || null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
setNextAsyncResult: function(async, response, fails, headers) {
|
|
||||||
headers = headers || {};
|
|
||||||
var succeed = fails ? "fail" : "success";
|
|
||||||
async.__internalXHRImplementation = function(config) {
|
|
||||||
return {
|
|
||||||
done: getCallback(fails, response, succeed, headers),
|
|
||||||
fail: getCallback(!fails, response, succeed, headers)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,92 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {{LICENSE_HEADER}}
|
|
||||||
* {{LICENSE_HEADER}}
|
|
||||||
*/
|
|
||||||
|
|
||||||
var URI = require('URIjs');
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
GLOBAL.window = {
|
|
||||||
location: {
|
|
||||||
href: 'http://localhost/icinga2-web/testcase',
|
|
||||||
pathname: '/icinga2-web/testcase',
|
|
||||||
query: '',
|
|
||||||
hash: '',
|
|
||||||
host: 'localhost',
|
|
||||||
protocol: 'http'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var states = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Api for setting the window URL
|
|
||||||
*
|
|
||||||
* @param {string} url The new url to use for window.location
|
|
||||||
*/
|
|
||||||
window.setWindowUrl = function(url) {
|
|
||||||
var url = URI(url);
|
|
||||||
window.location.protocol = url.protocol();
|
|
||||||
window.location.pathname = url.pathname();
|
|
||||||
window.location.query = url.query();
|
|
||||||
window.location.search = url.search();
|
|
||||||
window.location.hash = url.hash();
|
|
||||||
window.location.href = url.href();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for the History API
|
|
||||||
*
|
|
||||||
* @type {{pushState: Function, popState: Function, replaceState: Function, clear: Function}}
|
|
||||||
*/
|
|
||||||
module.exports = {
|
|
||||||
pushState: function(state, title, url) {
|
|
||||||
window.setWindowUrl(url);
|
|
||||||
states.push(arguments);
|
|
||||||
},
|
|
||||||
popState: function() {
|
|
||||||
return states.pop();
|
|
||||||
},
|
|
||||||
replaceState: function(state, title, url) {
|
|
||||||
states.pop();
|
|
||||||
window.setWindowUrl(url);
|
|
||||||
states.push(arguments);
|
|
||||||
},
|
|
||||||
clearState: function() {
|
|
||||||
states = [];
|
|
||||||
},
|
|
||||||
getState: function() {
|
|
||||||
return states;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
@ -1,172 +0,0 @@
|
|||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {{LICENSE_HEADER}}
|
|
||||||
* {{LICENSE_HEADER}}
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This node module acts as a mock for requirejs and allows you to
|
|
||||||
* define your own dependencies in your tests. It also removes the
|
|
||||||
* asynchronous character of dependency loading, so you don't need
|
|
||||||
* to handle everthing in the callbacks.
|
|
||||||
*
|
|
||||||
* Per default it resolves the 'logging' dependency by routing it
|
|
||||||
* to console.
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var path = require('path');
|
|
||||||
var registeredDependencies = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for the requirejs(dependencyList, callback) function, loads
|
|
||||||
* all dependencies that have been registered under the given names
|
|
||||||
* in dependencies and calls fn with them as the parameter
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var debug = false;
|
|
||||||
var requireJsMock = function(dependencies, fn) {
|
|
||||||
var fnArgs = [];
|
|
||||||
for (var i=0;i<dependencies.length;i++) {
|
|
||||||
if (typeof registeredDependencies[dependencies[i]] === "undefined") {
|
|
||||||
if (debug === true)
|
|
||||||
console.warn("Unknown dependency "+dependencies[i]+" in define()");
|
|
||||||
}
|
|
||||||
fnArgs.push(registeredDependencies[dependencies[i]]);
|
|
||||||
}
|
|
||||||
fn.apply(this,fnArgs);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock the Logger
|
|
||||||
*/
|
|
||||||
var logger = {
|
|
||||||
debug: function() {},
|
|
||||||
warn: function() {},
|
|
||||||
error: function() {},
|
|
||||||
emergency: function() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock for the 'define' function of requireJS, behaves exactly the same
|
|
||||||
* except that it looks up the dependencies in the list provided by registerDependencies()
|
|
||||||
* A module that hasn't been defined with a name can be fetched with getDefined() (without parameter)
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
var defineMock = function() {
|
|
||||||
var fn = function() {},
|
|
||||||
fnargs = [],
|
|
||||||
currentArg = 0,
|
|
||||||
scopeName = '__define__';
|
|
||||||
do {
|
|
||||||
var argType = typeof arguments[currentArg];
|
|
||||||
if( argType === "string") {
|
|
||||||
scopeName = arguments[currentArg];
|
|
||||||
currentArg++;
|
|
||||||
continue;
|
|
||||||
} else if (argType === "function") {
|
|
||||||
fn = arguments[currentArg];
|
|
||||||
} else if (Array.isArray(arguments[currentArg])) {
|
|
||||||
var argList = arguments[currentArg];
|
|
||||||
fn = arguments[currentArg+1];
|
|
||||||
for (var i=0;i<argList.length;i++) {
|
|
||||||
if (typeof registerDependencies[argList[i]] === "undefined" && debug) {
|
|
||||||
// console.warn("Unknown dependency "+argList[i]+" in define()");
|
|
||||||
}
|
|
||||||
|
|
||||||
fnargs.push(registeredDependencies[argList[i]]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} while(true);
|
|
||||||
registeredDependencies[scopeName] = fn.apply(this,fnargs);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called on module initialisation, will register the
|
|
||||||
* requirejs, define and jquery '$' methods globally
|
|
||||||
* and also purge any module-global dependencies
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
function initRequireMethods() {
|
|
||||||
GLOBAL.$ = require('jquery');
|
|
||||||
GLOBAL.jQuery = GLOBAL.$;
|
|
||||||
GLOBAL.requirejs = requireJsMock;
|
|
||||||
GLOBAL.define = defineMock;
|
|
||||||
registeredDependencies = {
|
|
||||||
'jquery' : GLOBAL.$,
|
|
||||||
'logging' : logger
|
|
||||||
};
|
|
||||||
}
|
|
||||||
initRequireMethods();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets all additional dependencies, i.e. all dependencies
|
|
||||||
* without a name
|
|
||||||
**/
|
|
||||||
function purgeDependencies() {
|
|
||||||
registeredDependencies = {
|
|
||||||
'jquery' : GLOBAL.$,
|
|
||||||
'logging' : logger
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// helper to log debug messages with console
|
|
||||||
console.debug = function() {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a name=>object map of dependencies
|
|
||||||
* for lookup with requirejs()/define()
|
|
||||||
**/
|
|
||||||
function registerDependencies(obj) {
|
|
||||||
for(var name in obj) {
|
|
||||||
registeredDependencies[name] = obj[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var base = path.normalize(__dirname+"../../../../public/js");
|
|
||||||
GLOBAL.requireNew = function(key) {
|
|
||||||
key = path.normalize(base+"/"+key);
|
|
||||||
delete require.cache[key];
|
|
||||||
return require(key);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The API for this module
|
|
||||||
**/
|
|
||||||
module.exports = {
|
|
||||||
purgeDependencies: purgeDependencies,
|
|
||||||
registerDependencies: registerDependencies,
|
|
||||||
getDefine: function(name) {
|
|
||||||
if (typeof name === "undefined") {
|
|
||||||
return registeredDependencies.__define__;
|
|
||||||
} else {
|
|
||||||
return registeredDependencies[name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user