diff --git a/log4js/Gruntfile.js b/log4js/Gruntfile.js index cb99e1c..f349df2 100644 --- a/log4js/Gruntfile.js +++ b/log4js/Gruntfile.js @@ -120,7 +120,14 @@ grunt.initConfig({ livereload: true } } - } + }, + karma: { + unit: { + configFile: 'src/test/karma.conf.js', + // browsers: ['Chrome'], + singleRun: true + } + } }); grunt.loadNpmTasks('grunt-contrib-watch'); @@ -130,12 +137,14 @@ grunt.initConfig({ grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadTasks('tasks'); + /** * Build task * Run `grunt build` on the command line * This will generate ZIP-Archive with all required artifacts. */ - grunt.registerTask('build', ['copy:build', 'uglify', 'compress'] + grunt.registerTask('build', ['copy:build', 'uglify', 'compress', 'karma'] ); /** * Default task diff --git a/log4js/build.properties b/log4js/build.properties index f576b6a..e8ff90b 100644 --- a/log4js/build.properties +++ b/log4js/build.properties @@ -7,4 +7,5 @@ tools.junit.version=4.3 tools.log4j.version=1.2.13 tools.rhino.version=1.6R5 tools.servlet-api.version=2.4 +tools.dir=../tools/ version=1.0 diff --git a/log4js/package.json b/log4js/package.json index 95d30f0..5aba814 100644 --- a/log4js/package.json +++ b/log4js/package.json @@ -1,39 +1,45 @@ { - "name": "log4js", - "title": "Log4js - The Logging API for JavaScript", - "description": "Log4js - The Logging Framework for JavaScript", - "version": "1.0.0", - "main": "log4js/src/main/js/log4js.js", - "authors": [ - "stritti (https://github.com/stritti)" - ], - "repository": { - "type": "git", - "url": "https://github.com/stritti/log4js.git" - }, - "keywords": [ - "log", - "logging", - "log4js", - "log4j" - ], - "license": "Apache License, Version 2.0", - "homepage": "http://stritti.github.io/log4js/", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "devDependencies": { - "grunt": "~0.4.1", - "grunt-contrib-watch": "~0.5.3", - "grunt-contrib-compress": "^0.7.0", - "grunt-contrib-jshint": "^0.10.0", - "grunt-contrib-uglify": "^0.4.0", - "grunt-contrib-copy": "^0.5.0", - "grunt-contrib-clean": "^0.5.0", - "grunt-contrib-cssmin": "^0.9.0" - } -} \ No newline at end of file + "name": "log4js", + "title": "Log4js - The Logging API for JavaScript", + "description": "Log4js - The Logging Framework for JavaScript", + "version": "1.0.0", + "main": "log4js/src/main/js/log4js.js", + "authors": [ + "stritti (https://github.com/stritti)" + ], + "repository": { + "type": "git", + "url": "https://github.com/stritti/log4js.git" + }, + "keywords": [ + "log", + "logging", + "log4js", + "log4j" + ], + "license": "Apache License, Version 2.0", + "homepage": "http://stritti.github.io/log4js/", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "devDependencies": { + "chai": "^2.2.0", + "grunt": "~0.4.1", + "grunt-contrib-clean": "^0.5.0", + "grunt-contrib-compress": "^0.7.0", + "grunt-contrib-copy": "^0.5.0", + "grunt-contrib-cssmin": "^0.9.0", + "grunt-contrib-jshint": "^0.10.0", + "grunt-contrib-uglify": "^0.4.0", + "grunt-contrib-watch": "~0.5.3", + "karma": "^0.12.31", + "karma-firefox-launcher": "^0.1.4", + "karma-mocha": "^0.1.10", + "karma-spec-reporter": "0.0.18", + "mocha": "^2.2.1" + } +} diff --git a/log4js/src/test/java/de/berlios/log4js/js/AbstractLog4jsTestCase.java b/log4js/src/test/java/de/berlios/log4js/js/AbstractLog4jsTestCase.java deleted file mode 100644 index 3fba8f6..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/AbstractLog4jsTestCase.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.After; -import org.junit.Before; - -import net.sf.jstester.JsTestCase; - -public abstract class AbstractLog4jsTestCase extends JsTestCase { - public AbstractLog4jsTestCase(String name) { - super(name); - } - - @Before - protected void setUp() throws Exception { - // don't forget to call super.setUp() - // or the JsTester won't be initialized - super.setUp(); - eval(loadScript("log4js.js")); - } - - @After - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/AjaxAppenderTest.java b/log4js/src/test/java/de/berlios/log4js/js/AjaxAppenderTest.java deleted file mode 100644 index 9af8125..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/AjaxAppenderTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - - -public class AjaxAppenderTest extends AbstractLog4jsTestCase { - - public AjaxAppenderTest(String name) { - super(name); - - } - - public void testInterface() { - eval("var ajaxLogger = Log4js.getLogger('ajax');"); - eval("var appender = new Log4js.AjaxAppender(ajaxLogger, '/log4js');"); - assertExpressionEquals("appender instanceof Log4js.Appender", "true"); - // eval("appender.doAppend(" + -// "new Log4js.LoggingEvent('categoryName', " + -// "Log4js.Level.DEBUG, 'message', ajaxLogger));"); -// eval("appender.doClear();"); - eval("appender.setLayout(new Log4js.SimpleLayout());"); - eval("appender.setLogger(ajaxLogger);"); - } - - public void testSetThreshold() { - eval("var ajaxLogger = Log4js.getLogger('ajax');"); - - eval("var ajaxAppender = new Log4js.AjaxAppender(ajaxLogger, '/log4js');"); - - } -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/AllTests.java b/log4js/src/test/java/de/berlios/log4js/js/AllTests.java deleted file mode 100644 index 4d8dfa3..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/AllTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class AllTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Test for de.berlios.log4js.js"); - //$JUnit-BEGIN$ - suite.addTestSuite(PatternLayoutTest.class); - suite.addTestSuite(BasicLayoutTest.class); - suite.addTestSuite(DateFormatterTest.class); - suite.addTestSuite(ConsoleAppenderTest.class); - suite.addTestSuite(LoggerTest.class); - suite.addTestSuite(AjaxAppenderTest.class); - suite.addTestSuite(XMLLayoutTest.class); - //$JUnit-END$ - return suite; - } - -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/BasicLayoutTest.java b/log4js/src/test/java/de/berlios/log4js/js/BasicLayoutTest.java deleted file mode 100644 index def41ff..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/BasicLayoutTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - - -public class BasicLayoutTest extends AbstractLog4jsTestCase { - - public BasicLayoutTest(String name) { - super(name); - - } - - @Test - public void testLayoutInterface() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.BasicLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger));"); - } - - @Test - public void testFormat(){ - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.BasicLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger));"); - - } -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/ConsoleAppenderTest.java b/log4js/src/test/java/de/berlios/log4js/js/ConsoleAppenderTest.java deleted file mode 100644 index d8cc2c5..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/ConsoleAppenderTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - -public class ConsoleAppenderTest extends AbstractLog4jsTestCase { - - public ConsoleAppenderTest(String name) { - super(name); - - } - - @Test - public void testInterface() { - eval("var logger = Log4js.getLogger('ajax');"); - eval("var appender = new Log4js.ConsoleAppender();"); - // eval("ajaxAppender.doAppend(" + - // "new Log4js.LoggingEvent('categoryName', " + - // "Log4js.Level.DEBUG, 'message', ajaxLogger));"); - //eval("appender.doClear();"); - eval("appender.setLayout(new Log4js.SimpleLayout());"); - eval("appender.setLogger(logger);"); - - eval("appender.setAccessKey('d');"); - } - - @Test - public void testWindow() { - - eval("var logger = new Log4js.getLogger('windowTest'); "); - eval("logger.setLevel(Log4js.Level.ALL); "); - eval("logger.addAppender(new Log4js.ConsoleAppender());"); - - } -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/DateFormatterTest.java b/log4js/src/test/java/de/berlios/log4js/js/DateFormatterTest.java deleted file mode 100644 index 14a60d8..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/DateFormatterTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - -public class DateFormatterTest extends AbstractLog4jsTestCase { - - public DateFormatterTest(String name) { - super(name); - } - - @Test - public void testConstant() { - assertExpressionEquals("Log4js.DateFormatter.DEFAULT_DATE_FORMAT", - "'yyyy-MM-ddThh:mm:ssO'"); - - eval("var dateFormatter = new Log4js.DateFormatter();"); - } - - @Test - public void testFormatDateYear() { - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'yyyy')", - "'2006'"); - } - - @Test - public void testFormatDateMonth() { - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'MM')", - "'01'"); - } - - @Test - public void testFormatDateDay() { - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'dd')", - "'02'"); - } - - @Test - public void testFormatDateHour() { - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'hh')", - "'03'"); - } - - @Test - public void testFormatDateMinute() { - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - assertExpressionEquals("dateFormatter.formatDate(testDate, 'mm')", - "'04'"); - } - - @Test - public void testFormatDateSeconds() { - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'ss')", - "'06'"); - - } - - @Test - public void testFormatDateTimezoneOffset() { - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, 'O')", - "'+0100'"); - } - - @Test - public void testFormatDateDefault() { - assertExpressionEquals("Log4js.DateFormatter.DEFAULT_DATE_FORMAT", - "'yyyy-MM-ddThh:mm:ssO'"); - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - - assertExpressionEquals("dateFormatter.formatDate(testDate, " - + "Log4js.DateFormatter.DEFAULT_DATE_FORMAT)", - "'2006-01-02T03:04:06+0100'"); - - } - - @Test - public void testFormatDate() { - assertExpressionEquals("Log4js.DateFormatter.DEFAULT_DATE_FORMAT", - "'yyyy-MM-ddThh:mm:ssO'"); - - eval("var dateFormatter = new Log4js.DateFormatter();"); - - eval("var testDate = new Date(2006, 00, 02, 03, 04, 06, 07)"); - assertExpressionEquals( - "dateFormatter.formatDate(testDate, 'yyyy-MM-dd hh:mm:ss')", - "'2006-01-02 03:04:06'"); - } - -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/LoggerTest.java b/log4js/src/test/java/de/berlios/log4js/js/LoggerTest.java deleted file mode 100644 index fc1ffa3..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/LoggerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - -public class LoggerTest extends AbstractLog4jsTestCase { - - public LoggerTest(String name) { - super(name); - } - - @Test - public void testBasics() { - - assertNotNull("Log4js"); - assertExpressionEquals("Version String check", "Log4js.version", "'1.0'"); - } - - @Test - public void testGetDefaultLogger() { - - assertExpressionEquals("Log4js.getDefaultLogger().toString()", - "new Log4js.Logger('[default]').toString()"); - assertExpressionEquals("Log4js.loggers['[default]'].toString()", - "Log4js.getDefaultLogger().toString()"); - } - - @Test - public void testGetLogger() { - assertNotNull("Log4js.getLogger('category')"); - assertExpressionEquals("Log4js.getLogger('category').toString()", - "new Log4js.Logger('category').toString()"); - } - -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/PatternLayoutTest.java b/log4js/src/test/java/de/berlios/log4js/js/PatternLayoutTest.java deleted file mode 100644 index 34627c5..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/PatternLayoutTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - -public class PatternLayoutTest extends AbstractLog4jsTestCase { - - public PatternLayoutTest(String name) { - super(name); - - } - - @Test - public void testLayoutInterface() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.PatternLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger));"); - } - - @Test - public void testFormat() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.PatternLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger))"); - - } -} diff --git a/log4js/src/test/java/de/berlios/log4js/js/XMLLayoutTest.java b/log4js/src/test/java/de/berlios/log4js/js/XMLLayoutTest.java deleted file mode 100644 index 7065ecd..0000000 --- a/log4js/src/test/java/de/berlios/log4js/js/XMLLayoutTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package de.berlios.log4js.js; - -import org.junit.Test; - -public class XMLLayoutTest extends AbstractLog4jsTestCase { - - public XMLLayoutTest(String name) { - super(name); - } - - @Test - public void testLayoutInterface() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.XMLLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger));"); - } - - @Test - public void testFormat() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.XMLLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger))"); - - } - - @Test - public void testRefererFormat() { - eval("var logger = Log4js.getLogger('test');"); - eval("var layout = new Log4js.XMLLayout();"); - eval("layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger))"); - - } -} diff --git a/log4js/src/test/js/unit/appenders/ajax.js b/log4js/src/test/js/unit/appenders/ajax.js new file mode 100644 index 0000000..ae71569 --- /dev/null +++ b/log4js/src/test/js/unit/appenders/ajax.js @@ -0,0 +1,19 @@ +describe('appenders/ajax', function () { + 'use strict'; + var assert = chai.assert; + + it('interface', function() { + var ajaxLogger = Log4js.getLogger('ajax'); + var appender = new Log4js.AjaxAppender(ajaxLogger, '/log4js'); + assert.equal(appender instanceof Log4js.Appender, true); + appender.setLayout(new Log4js.SimpleLayout()); + appender.setLogger(ajaxLogger); + }); + + + it('set threshold', function() { + var ajaxLogger = Log4js.getLogger('ajax'); + + var ajaxAppender = new Log4js.AjaxAppender(ajaxLogger, '/log4js'); + }); +}); diff --git a/log4js/src/test/js/unit/appenders/console.js b/log4js/src/test/js/unit/appenders/console.js new file mode 100644 index 0000000..b93b74a --- /dev/null +++ b/log4js/src/test/js/unit/appenders/console.js @@ -0,0 +1,19 @@ +describe('appenders/ajax', function () { + 'use strict'; + var assert = chai.assert; + + it("interface", function() { + var logger = Log4js.getLogger('ajax'); + var appender = new Log4js.ConsoleAppender(); + appender.setLayout(new Log4js.SimpleLayout()); + appender.setLogger(logger); + + appender.setAccessKey('d'); + }); + + it("window", function() { + var logger = new Log4js.getLogger('windowTest'); + logger.setLevel(Log4js.Level.ALL); + logger.addAppender(new Log4js.ConsoleAppender()); + }); +}); diff --git a/log4js/src/test/js/unit/formatters/date.js b/log4js/src/test/js/unit/formatters/date.js new file mode 100644 index 0000000..5d2b0bc --- /dev/null +++ b/log4js/src/test/js/unit/formatters/date.js @@ -0,0 +1,89 @@ +describe('formatters/date', function () { + 'use strict'; + var assert = chai.assert; + + it("constant", function() { + assert.equal(Log4js.DateFormatter.DEFAULT_DATE_FORMAT, 'yyyy-MM-ddThh:mm:ssO'); + + var dateFormatter = new Log4js.DateFormatter(); + }); + + it("format date year", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'yyyy'), '2006'); + }); + + it("format date month", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'MM'), '01'); + }); + + it("format date day", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'dd'), '02'); + }); + + it("format date hour", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'hh'), '03'); + }); + + it("format date minute", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + assert.equal(dateFormatter.formatDate(testDate, 'mm'), '04'); + }); + + it("format date seconds", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'ss'), '06'); + + }); + + it.skip("format date timezone offset", function() { + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'O'), '+0100'); + }); + + it.skip("format date default", function() { + assert.equal(Log4js.DateFormatter.DEFAULT_DATE_FORMAT, 'yyyy-MM-ddThh:mm:ssO'); + + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal( + dateFormatter.formatDate(testDate, Log4js.DateFormatter.DEFAULT_DATE_FORMAT), + '2006-01-02T03:04:06+0100' + ); + }); + + it("format date", function() { + assert.equal(Log4js.DateFormatter.DEFAULT_DATE_FORMAT, 'yyyy-MM-ddThh:mm:ssO'); + + var dateFormatter = new Log4js.DateFormatter(); + + var testDate = new Date(2006, 0, 2, 3, 4, 6, 7); + + assert.equal(dateFormatter.formatDate(testDate, 'yyyy-MM-dd hh:mm:ss'), '2006-01-02 03:04:06'); + }); +}); diff --git a/log4js/src/test/js/unit/layouts/basic.js b/log4js/src/test/js/unit/layouts/basic.js new file mode 100644 index 0000000..9ce49c3 --- /dev/null +++ b/log4js/src/test/js/unit/layouts/basic.js @@ -0,0 +1,16 @@ +describe('layouts/basic', function () { + 'use strict'; + var assert = chai.assert; + + it("layout interface", function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.BasicLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); + + if("format", function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.BasicLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); +}); diff --git a/log4js/src/test/js/unit/layouts/pattern.js b/log4js/src/test/js/unit/layouts/pattern.js new file mode 100644 index 0000000..79e950f --- /dev/null +++ b/log4js/src/test/js/unit/layouts/pattern.js @@ -0,0 +1,16 @@ +describe('layouts/pattern', function () { + 'use strict'; + var assert = chai.assert; + + it('layout interface', function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.PatternLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); + + it('format', function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.PatternLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); +}); diff --git a/log4js/src/test/js/unit/layouts/xml.js b/log4js/src/test/js/unit/layouts/xml.js new file mode 100644 index 0000000..2e5e63f --- /dev/null +++ b/log4js/src/test/js/unit/layouts/xml.js @@ -0,0 +1,22 @@ +describe('layouts/pattern', function () { + 'use strict'; + var assert = chai.assert; + + it("layout interface", function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.XMLLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); + + it("format", function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.XMLLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); + + it("referer format", function() { + var logger = Log4js.getLogger('test'); + var layout = new Log4js.XMLLayout(); + layout.format(new Log4js.LoggingEvent('categoryName', Log4js.Level.DEBUG, 'message', 'exception', logger)); + }); +}); diff --git a/log4js/src/test/js/unit/logger.js b/log4js/src/test/js/unit/logger.js new file mode 100644 index 0000000..0152747 --- /dev/null +++ b/log4js/src/test/js/unit/logger.js @@ -0,0 +1,18 @@ +describe('layouts/basic', function () { + 'use strict'; + var assert = chai.assert; + + it("basics Version String check", function() { + assert.equal(Log4js.version, '1.0.0'); + }); + + it("get default logger", function() { + assert.equal(Log4js.getDefaultLogger().toString(), new Log4js.Logger('[default]').toString()); + assert.equal(Log4js.loggers['[default]'].toString(), Log4js.getDefaultLogger().toString()); + }); + + it("get logger", function() { + assert.isNotNull(Log4js.getLogger('category')); + assert.equal(Log4js.getLogger('category').toString(), new Log4js.Logger('category').toString()); + }); +}); diff --git a/log4js/src/test/karma.conf.js b/log4js/src/test/karma.conf.js new file mode 100644 index 0000000..c36d0cd --- /dev/null +++ b/log4js/src/test/karma.conf.js @@ -0,0 +1,83 @@ +module.exports = function(config) { + config.set({ + + // base path, that will be used to resolve files and exclude + basePath : '../../', + + frameworks : ['mocha'], + + // list of files / patterns to load in the browser + files : [ + 'node_modules/chai/chai.js', + 'target/files/log4js/main/js/log4js.js', + 'src/test/js/unit/**/*.js', + 'src/test/js/unit/*.js' + // 'test/functional/**/*.js', + // {pattern: 'src/test/**/*.png', watched: false, included: false, served: true} + ], + + // list of files to exclude + //exclude : [], + + // use dolts reporter, as travis terminal does not support escaping sequences + // possible values: 'dots', 'progress', 'junit', 'teamcity' + // CLI --reporters progress + reporters : ['spec'], + + // web server port + // CLI --port 9876 + port : 9876, + + // cli runner port + // CLI --runner-port 9100 + runnerPort : 9100, + + // enable / disable colors in the output (reporters and logs) + // CLI --colors --no-colors + colors : true, + + // level of logging + // possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG + // CLI --log-level debug + logLevel : config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + // CLI --auto-watch --no-auto-watch + autoWatch : false, + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari (only Mac) + // - PhantomJS + // - IE (only Windows) + // CLI --browsers Chrome,Firefox,Safari + browsers : ['Firefox'], + + // If browser does not capture in given timeout [ms], kill it + // CLI --capture-timeout 60000 + captureTimeout : 60000, + + // Auto run tests on start (when browsers are captured) and exit + // CLI --single-run --no-single-run + singleRun : true, + + // report which specs are slower than 500ms + // CLI --report-slower-than 500 + reportSlowerThan : 5000, + + preprocessors : { + // '**/client/js/*.js': 'coverage' + }, + + plugins : [ + // 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-mocha', + // 'karma-phantomjs-launcher' + 'karma-spec-reporter' + ] + }); +}; diff --git a/log4js/tasks/karma.js b/log4js/tasks/karma.js new file mode 100644 index 0000000..e20aca5 --- /dev/null +++ b/log4js/tasks/karma.js @@ -0,0 +1,22 @@ +module.exports = function (grunt) { + 'use strict'; + + var path = require('path'); + var server = require('karma').server; + + grunt.registerMultiTask('karma', 'run karma.', function(target) { + //merge data onto options, with data taking precedence + var options = grunt.util._.merge(this.options(), this.data), + done = this.async(); + + if (options.configFile) { + options.configFile = grunt.template.process(options.configFile); + options.configFile = path.resolve(options.configFile); + } + + done = this.async(); + server.start(options, function(code) { + done(!code); + }); + }); +};