How to use expectedLength method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

simpleLoggerTest.js

Source:simpleLoggerTest.js Github

copy

Full Screen

1/*2 * Copyright 2016 Axel Faust3 *4 * Licensed under the Eclipse Public License (EPL), Version 1.0 (the "License"); you may not use5 * this file except in compliance with the License. You may obtain a copy of the License at6 *7 * https://www.eclipse.org/legal/epl-v10.html8 *9 * Unless required by applicable law or agreed to in writing, software distributed under the10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,11 * either express or implied. See the License for the specific language governing permissions12 * and limitations under the License.13 */14(function simpleLoggerTest()15{16 // need to bind ctxt early - won't be available when testObj.<fn> is invoked via extracted interface17 var testObj, ctxt = context;18 testObj = {19 getTestFunctionNames : function simpleLoggerTest_getTestFunctionNames()20 {21 return Java.to([ 'testAPIDefined', 'testTraceLogging', 'testDebugLogging', 'testInfoLogging', 'testWarnLogging',22 'testErrorLogging' ], 'java.util.List');23 },24 beforeScript : function simpleLoggerTest_beforeScript()25 {26 var SimpleScriptTestCase = Java.type('de.axelfaust.alfresco.nashorn.repo.junit.tests.SimpleScriptTestCase');27 SimpleScriptTestCase.initializeAMD(engine, ctxt);28 // now we can use define29 define.preload('loaderMetaLoader!nashorn');30 // we don't remove Java here to allow simpler use of org.junit.Assert31 SimpleScriptTestCase.removeGlobals(engine, ctxt, [ 'print', 'Packages', 'JavaImporter', 'JSAdapter', 'com', 'edu', 'java',32 'javax', 'javafx', 'org' ]);33 // empty config34 require.config({});35 },36 testAPIDefined : function simpleLoggerTest_testAPIDefined(testCase)37 {38 'use strict';39 var Assert = Java.type('org.junit.Assert'), logger;40 Assert.assertFalse('getSimpleLogger should have been defined', getSimpleLogger === undefined);41 Assert.assertEquals('getSimpleLogger should have been a function', 'function', typeof getSimpleLogger);42 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo');43 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);44 Assert.assertEquals('logger.trace should have been a function', 'function', typeof logger.trace);45 Assert.assertEquals('logger.debug should have been a function', 'function', typeof logger.debug);46 Assert.assertEquals('logger.info should have been a function', 'function', typeof logger.info);47 Assert.assertEquals('logger.warn should have been a function', 'function', typeof logger.warn);48 Assert.assertEquals('logger.error should have been a function', 'function', typeof logger.error);49 Assert.assertEquals('logger.isTraceEnabled should have been a function', 'function', typeof logger.isTraceEnabled);50 Assert.assertEquals('logger.isDebugEnabled should have been a function', 'function', typeof logger.isDebugEnabled);51 Assert.assertEquals('logger.isInfoEnabled should have been a function', 'function', typeof logger.isInfoEnabled);52 Assert.assertEquals('logger.isWarnEnabled should have been a function', 'function', typeof logger.isWarnEnabled);53 Assert.assertEquals('logger.isErrorEnabled should have been a function', 'function', typeof logger.isErrorEnabled);54 Assert.assertEquals('logger.traceEnabled should have been a boolean', 'boolean', typeof logger.traceEnabled);55 Assert.assertEquals('logger.debugEnabled should have been a boolean', 'boolean', typeof logger.debugEnabled);56 Assert.assertEquals('logger.infoEnabled should have been a boolean', 'boolean', typeof logger.infoEnabled);57 Assert.assertEquals('logger.warnEnabled should have been a boolean', 'boolean', typeof logger.warnEnabled);58 Assert.assertEquals('logger.errorEnabled should have been a boolean', 'boolean', typeof logger.errorEnabled);59 },60 testTraceLogging : function simpleLoggerTest_testTraceLogging(testCase)61 {62 'use strict';63 var Assert, ListAppender, lockbackLogger, logger, traceAppender, expectedLength;64 Assert = Java.type('org.junit.Assert');65 ListAppender = Java.type('ch.qos.logback.core.read.ListAppender');66 lockbackLogger = Java.type('org.slf4j.LoggerFactory').getLogger(67 'de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.trace');68 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.trace');69 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);70 lockbackLogger.setLevel(Java.type('ch.qos.logback.classic.Level').TRACE);71 traceAppender = new ListAppender();72 traceAppender.start();73 expectedLength = 0;74 lockbackLogger.addAppender(traceAppender);75 Assert.assertTrue('logger.traceEnabled should report TRACE logging as enabled', logger.traceEnabled);76 Assert.assertTrue('logger.isTraceEnabled() should report TRACE logging as enabled', logger.isTraceEnabled());77 // test simple message78 logger.trace('Simple trace message');79 expectedLength++;80 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);81 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Simple trace message',82 traceAppender.list[expectedLength - 1].message);83 // test message with var-arg like parameters84 logger.trace('Trace message {}={}', 'key', 'value');85 expectedLength++;86 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);87 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Trace message {}={}',88 traceAppender.list[expectedLength - 1].message);89 Assert.assertEquals('traceAppender received logging event with incorrect number of parameters', 2,90 traceAppender.list[expectedLength - 1].argumentArray.length, 0);91 Assert.assertEquals('traceAppender received logging event with incorrect 1st parameter', 'key',92 traceAppender.list[expectedLength - 1].argumentArray[0]);93 Assert.assertEquals('traceAppender received logging event with incorrect 2nd parameter', 'value',94 traceAppender.list[expectedLength - 1].argumentArray[1]);95 Assert.assertEquals('traceAppender received logging event with incorrect formatted message', 'Trace message key=value',96 traceAppender.list[expectedLength - 1].formattedMessage);97 // test message with array-based parameters98 logger.trace('Trace message {}={}', [ 'key', 'value' ]);99 expectedLength++;100 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);101 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Trace message {}={}',102 traceAppender.list[expectedLength - 1].message);103 Assert.assertEquals('traceAppender received logging event with incorrect number of parameters', 2,104 traceAppender.list[expectedLength - 1].argumentArray.length, 0);105 Assert.assertEquals('traceAppender received logging event with incorrect 1st parameter', 'key',106 traceAppender.list[expectedLength - 1].argumentArray[0]);107 Assert.assertEquals('traceAppender received logging event with incorrect 2nd parameter', 'value',108 traceAppender.list[expectedLength - 1].argumentArray[1]);109 Assert.assertEquals('traceAppender received logging event with incorrect formatted message', 'Trace message key=value',110 traceAppender.list[expectedLength - 1].formattedMessage);111 // test message with toString-enabled script object parameter112 logger.trace('Trace message {}', {113 toString : function()114 {115 return 'value';116 }117 });118 expectedLength++;119 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);120 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Trace message {}',121 traceAppender.list[expectedLength - 1].message);122 Assert.assertEquals('traceAppender received logging event with incorrect number of parameters', 1,123 traceAppender.list[expectedLength - 1].argumentArray.length, 0);124 Assert.assertEquals('traceAppender received logging event with incorrect formatted message', 'Trace message value',125 traceAppender.list[expectedLength - 1].formattedMessage);126 // test message with native error127 logger.trace('Trace message', new Error('My native error'));128 expectedLength++;129 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);130 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Trace message',131 traceAppender.list[expectedLength - 1].message);132 Assert.assertTrue('traceAppender received logging event without a throwable instance',133 traceAppender.list[expectedLength - 1].throwableProxy !== null);134 Assert135 .assertEquals(136 'traceAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',137 'Error: My native error', traceAppender.list[expectedLength - 1].throwableProxy.message);138 Assert.assertEquals('traceAppender received logging event with incorrect formatted message', 'Trace message',139 traceAppender.list[expectedLength - 1].formattedMessage);140 // test message with params AND native error141 logger.trace('Trace message {}={}', 'key', 'value', new Error('My native error'));142 expectedLength++;143 Assert.assertEquals('traceAppender should have received the logging event', expectedLength, traceAppender.list.length, 0);144 Assert.assertEquals('traceAppender received logging event with incorrect message', 'Trace message {}={}',145 traceAppender.list[expectedLength - 1].message);146 Assert.assertEquals('traceAppender received logging event with incorrect number of parameters', 2,147 traceAppender.list[expectedLength - 1].argumentArray.length, 0);148 Assert.assertEquals('traceAppender received logging event with incorrect 1st parameter', 'key',149 traceAppender.list[expectedLength - 1].argumentArray[0]);150 Assert.assertEquals('traceAppender received logging event with incorrect 2nd parameter', 'value',151 traceAppender.list[expectedLength - 1].argumentArray[1]);152 Assert.assertTrue('traceAppender received logging event without a throwable instance',153 traceAppender.list[expectedLength - 1].throwableProxy !== null);154 Assert155 .assertEquals(156 'traceAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',157 'Error: My native error', traceAppender.list[expectedLength - 1].throwableProxy.message);158 Assert.assertEquals('traceAppender received logging event with incorrect formatted message', 'Trace message key=value',159 traceAppender.list[expectedLength - 1].formattedMessage);160 },161 testDebugLogging : function simpleLoggerTest_testDebugLogging(testCase)162 {163 'use strict';164 var Assert, ListAppender, lockbackLogger, logger, debugAppender, expectedLength;165 Assert = Java.type('org.junit.Assert');166 ListAppender = Java.type('ch.qos.logback.core.read.ListAppender');167 lockbackLogger = Java.type('org.slf4j.LoggerFactory').getLogger(168 'de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.debug');169 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.debug');170 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);171 lockbackLogger.setLevel(Java.type('ch.qos.logback.classic.Level').DEBUG);172 debugAppender = new ListAppender();173 debugAppender.start();174 expectedLength = 0;175 lockbackLogger.addAppender(debugAppender);176 Assert.assertTrue('logger.debugEnabled should report TRACE logging as enabled', logger.debugEnabled);177 Assert.assertTrue('logger.isDebugEnabled() should report TRACE logging as enabled', logger.isDebugEnabled());178 // test simple message179 logger.debug('Simple debug message');180 expectedLength++;181 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);182 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Simple debug message',183 debugAppender.list[expectedLength - 1].message);184 // test message with var-arg like parameters185 logger.debug('Debug message {}={}', 'key', 'value');186 expectedLength++;187 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);188 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Debug message {}={}',189 debugAppender.list[expectedLength - 1].message);190 Assert.assertEquals('debugAppender received logging event with incorrect number of parameters', 2,191 debugAppender.list[expectedLength - 1].argumentArray.length, 0);192 Assert.assertEquals('debugAppender received logging event with incorrect 1st parameter', 'key',193 debugAppender.list[expectedLength - 1].argumentArray[0]);194 Assert.assertEquals('debugAppender received logging event with incorrect 2nd parameter', 'value',195 debugAppender.list[expectedLength - 1].argumentArray[1]);196 Assert.assertEquals('debugAppender received logging event with incorrect formatted message', 'Debug message key=value',197 debugAppender.list[expectedLength - 1].formattedMessage);198 // test message with array-based parameters199 logger.debug('Debug message {}={}', [ 'key', 'value' ]);200 expectedLength++;201 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);202 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Debug message {}={}',203 debugAppender.list[expectedLength - 1].message);204 Assert.assertEquals('debugAppender received logging event with incorrect number of parameters', 2,205 debugAppender.list[expectedLength - 1].argumentArray.length, 0);206 Assert.assertEquals('debugAppender received logging event with incorrect 1st parameter', 'key',207 debugAppender.list[expectedLength - 1].argumentArray[0]);208 Assert.assertEquals('debugAppender received logging event with incorrect 2nd parameter', 'value',209 debugAppender.list[expectedLength - 1].argumentArray[1]);210 Assert.assertEquals('debugAppender received logging event with incorrect formatted message', 'Debug message key=value',211 debugAppender.list[expectedLength - 1].formattedMessage);212 // test message with toString-enabled script object parameter213 logger.debug('Debug message {}', {214 toString : function()215 {216 return 'value';217 }218 });219 expectedLength++;220 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);221 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Debug message {}',222 debugAppender.list[expectedLength - 1].message);223 Assert.assertEquals('debugAppender received logging event with incorrect number of parameters', 1,224 debugAppender.list[expectedLength - 1].argumentArray.length, 0);225 Assert.assertEquals('debugAppender received logging event with incorrect formatted message', 'Debug message value',226 debugAppender.list[expectedLength - 1].formattedMessage);227 // test message with native error228 logger.debug('Debug message', new Error('My native error'));229 expectedLength++;230 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);231 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Debug message',232 debugAppender.list[expectedLength - 1].message);233 Assert.assertTrue('debugAppender received logging event without a throwable instance',234 debugAppender.list[expectedLength - 1].throwableProxy !== null);235 Assert236 .assertEquals(237 'debugAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',238 'Error: My native error', debugAppender.list[expectedLength - 1].throwableProxy.message);239 Assert.assertEquals('debugAppender received logging event with incorrect formatted message', 'Debug message',240 debugAppender.list[expectedLength - 1].formattedMessage);241 // test message with params AND native error242 logger.debug('Debug message {}={}', 'key', 'value', new Error('My native error'));243 expectedLength++;244 Assert.assertEquals('debugAppender should have received the logging event', expectedLength, debugAppender.list.length, 0);245 Assert.assertEquals('debugAppender received logging event with incorrect message', 'Debug message {}={}',246 debugAppender.list[expectedLength - 1].message);247 Assert.assertEquals('debugAppender received logging event with incorrect number of parameters', 2,248 debugAppender.list[expectedLength - 1].argumentArray.length, 0);249 Assert.assertEquals('debugAppender received logging event with incorrect 1st parameter', 'key',250 debugAppender.list[expectedLength - 1].argumentArray[0]);251 Assert.assertEquals('debugAppender received logging event with incorrect 2nd parameter', 'value',252 debugAppender.list[expectedLength - 1].argumentArray[1]);253 Assert.assertTrue('debugAppender received logging event without a throwable instance',254 debugAppender.list[expectedLength - 1].throwableProxy !== null);255 Assert256 .assertEquals(257 'debugAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',258 'Error: My native error', debugAppender.list[expectedLength - 1].throwableProxy.message);259 Assert.assertEquals('debugAppender received logging event with incorrect formatted message', 'Debug message key=value',260 debugAppender.list[expectedLength - 1].formattedMessage);261 },262 testInfoLogging : function simpleLoggerTest_testInfoLogging(testCase)263 {264 'use strict';265 var Assert, ListAppender, lockbackLogger, logger, infoAppender, expectedLength;266 Assert = Java.type('org.junit.Assert');267 ListAppender = Java.type('ch.qos.logback.core.read.ListAppender');268 lockbackLogger = Java.type('org.slf4j.LoggerFactory').getLogger(269 'de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.info');270 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.info');271 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);272 lockbackLogger.setLevel(Java.type('ch.qos.logback.classic.Level').DEBUG);273 infoAppender = new ListAppender();274 infoAppender.start();275 expectedLength = 0;276 lockbackLogger.addAppender(infoAppender);277 Assert.assertTrue('logger.infoEnabled should report TRACE logging as enabled', logger.infoEnabled);278 Assert.assertTrue('logger.isInfoEnabled() should report TRACE logging as enabled', logger.isInfoEnabled());279 // test simple message280 logger.info('Simple info message');281 expectedLength++;282 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);283 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Simple info message',284 infoAppender.list[expectedLength - 1].message);285 // test message with var-arg like parameters286 logger.info('Info message {}={}', 'key', 'value');287 expectedLength++;288 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);289 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Info message {}={}',290 infoAppender.list[expectedLength - 1].message);291 Assert.assertEquals('infoAppender received logging event with incorrect number of parameters', 2,292 infoAppender.list[expectedLength - 1].argumentArray.length, 0);293 Assert.assertEquals('infoAppender received logging event with incorrect 1st parameter', 'key',294 infoAppender.list[expectedLength - 1].argumentArray[0]);295 Assert.assertEquals('infoAppender received logging event with incorrect 2nd parameter', 'value',296 infoAppender.list[expectedLength - 1].argumentArray[1]);297 Assert.assertEquals('infoAppender received logging event with incorrect formatted message', 'Info message key=value',298 infoAppender.list[expectedLength - 1].formattedMessage);299 // test message with array-based parameters300 logger.info('Info message {}={}', [ 'key', 'value' ]);301 expectedLength++;302 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);303 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Info message {}={}',304 infoAppender.list[expectedLength - 1].message);305 Assert.assertEquals('infoAppender received logging event with incorrect number of parameters', 2,306 infoAppender.list[expectedLength - 1].argumentArray.length, 0);307 Assert.assertEquals('infoAppender received logging event with incorrect 1st parameter', 'key',308 infoAppender.list[expectedLength - 1].argumentArray[0]);309 Assert.assertEquals('infoAppender received logging event with incorrect 2nd parameter', 'value',310 infoAppender.list[expectedLength - 1].argumentArray[1]);311 Assert.assertEquals('infoAppender received logging event with incorrect formatted message', 'Info message key=value',312 infoAppender.list[expectedLength - 1].formattedMessage);313 // test message with toString-enabled script object parameter314 logger.info('Info message {}', {315 toString : function()316 {317 return 'value';318 }319 });320 expectedLength++;321 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);322 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Info message {}',323 infoAppender.list[expectedLength - 1].message);324 Assert.assertEquals('infoAppender received logging event with incorrect number of parameters', 1,325 infoAppender.list[expectedLength - 1].argumentArray.length, 0);326 Assert.assertEquals('infoAppender received logging event with incorrect formatted message', 'Info message value',327 infoAppender.list[expectedLength - 1].formattedMessage);328 // test message with native error329 logger.info('Info message', new Error('My native error'));330 expectedLength++;331 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);332 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Info message',333 infoAppender.list[expectedLength - 1].message);334 Assert.assertTrue('infoAppender received logging event without a throwable instance',335 infoAppender.list[expectedLength - 1].throwableProxy !== null);336 Assert337 .assertEquals(338 'infoAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',339 'Error: My native error', infoAppender.list[expectedLength - 1].throwableProxy.message);340 Assert.assertEquals('infoAppender received logging event with incorrect formatted message', 'Info message',341 infoAppender.list[expectedLength - 1].formattedMessage);342 // test message with params AND native error343 logger.info('Info message {}={}', 'key', 'value', new Error('My native error'));344 expectedLength++;345 Assert.assertEquals('infoAppender should have received the logging event', expectedLength, infoAppender.list.length, 0);346 Assert.assertEquals('infoAppender received logging event with incorrect message', 'Info message {}={}',347 infoAppender.list[expectedLength - 1].message);348 Assert.assertEquals('infoAppender received logging event with incorrect number of parameters', 2,349 infoAppender.list[expectedLength - 1].argumentArray.length, 0);350 Assert.assertEquals('infoAppender received logging event with incorrect 1st parameter', 'key',351 infoAppender.list[expectedLength - 1].argumentArray[0]);352 Assert.assertEquals('infoAppender received logging event with incorrect 2nd parameter', 'value',353 infoAppender.list[expectedLength - 1].argumentArray[1]);354 Assert.assertTrue('infoAppender received logging event without a throwable instance',355 infoAppender.list[expectedLength - 1].throwableProxy !== null);356 Assert357 .assertEquals(358 'infoAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',359 'Error: My native error', infoAppender.list[expectedLength - 1].throwableProxy.message);360 Assert.assertEquals('infoAppender received logging event with incorrect formatted message', 'Info message key=value',361 infoAppender.list[expectedLength - 1].formattedMessage);362 },363 testWarnLogging : function simpleLoggerTest_testWarnLogging(testCase)364 {365 'use strict';366 var Assert, ListAppender, lockbackLogger, logger, warnAppender, expectedLength;367 Assert = Java.type('org.junit.Assert');368 ListAppender = Java.type('ch.qos.logback.core.read.ListAppender');369 lockbackLogger = Java.type('org.slf4j.LoggerFactory').getLogger(370 'de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.warn');371 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.warn');372 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);373 lockbackLogger.setLevel(Java.type('ch.qos.logback.classic.Level').DEBUG);374 warnAppender = new ListAppender();375 warnAppender.start();376 expectedLength = 0;377 lockbackLogger.addAppender(warnAppender);378 Assert.assertTrue('logger.warnEnabled should report TRACE logging as enabled', logger.warnEnabled);379 Assert.assertTrue('logger.isWarnEnabled() should report TRACE logging as enabled', logger.isWarnEnabled());380 // test simple message381 logger.warn('Simple warn message');382 expectedLength++;383 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);384 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Simple warn message',385 warnAppender.list[expectedLength - 1].message);386 // test message with var-arg like parameters387 logger.warn('Warn message {}={}', 'key', 'value');388 expectedLength++;389 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);390 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Warn message {}={}',391 warnAppender.list[expectedLength - 1].message);392 Assert.assertEquals('warnAppender received logging event with incorrect number of parameters', 2,393 warnAppender.list[expectedLength - 1].argumentArray.length, 0);394 Assert.assertEquals('warnAppender received logging event with incorrect 1st parameter', 'key',395 warnAppender.list[expectedLength - 1].argumentArray[0]);396 Assert.assertEquals('warnAppender received logging event with incorrect 2nd parameter', 'value',397 warnAppender.list[expectedLength - 1].argumentArray[1]);398 Assert.assertEquals('warnAppender received logging event with incorrect formatted message', 'Warn message key=value',399 warnAppender.list[expectedLength - 1].formattedMessage);400 // test message with array-based parameters401 logger.warn('Warn message {}={}', [ 'key', 'value' ]);402 expectedLength++;403 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);404 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Warn message {}={}',405 warnAppender.list[expectedLength - 1].message);406 Assert.assertEquals('warnAppender received logging event with incorrect number of parameters', 2,407 warnAppender.list[expectedLength - 1].argumentArray.length, 0);408 Assert.assertEquals('warnAppender received logging event with incorrect 1st parameter', 'key',409 warnAppender.list[expectedLength - 1].argumentArray[0]);410 Assert.assertEquals('warnAppender received logging event with incorrect 2nd parameter', 'value',411 warnAppender.list[expectedLength - 1].argumentArray[1]);412 Assert.assertEquals('warnAppender received logging event with incorrect formatted message', 'Warn message key=value',413 warnAppender.list[expectedLength - 1].formattedMessage);414 // test message with toString-enabled script object parameter415 logger.warn('Warn message {}', {416 toString : function()417 {418 return 'value';419 }420 });421 expectedLength++;422 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);423 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Warn message {}',424 warnAppender.list[expectedLength - 1].message);425 Assert.assertEquals('warnAppender received logging event with incorrect number of parameters', 1,426 warnAppender.list[expectedLength - 1].argumentArray.length, 0);427 Assert.assertEquals('warnAppender received logging event with incorrect formatted message', 'Warn message value',428 warnAppender.list[expectedLength - 1].formattedMessage);429 // test message with native error430 logger.warn('Warn message', new Error('My native error'));431 expectedLength++;432 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);433 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Warn message',434 warnAppender.list[expectedLength - 1].message);435 Assert.assertTrue('warnAppender received logging event without a throwable instance',436 warnAppender.list[expectedLength - 1].throwableProxy !== null);437 Assert438 .assertEquals(439 'warnAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',440 'Error: My native error', warnAppender.list[expectedLength - 1].throwableProxy.message);441 Assert.assertEquals('warnAppender received logging event with incorrect formatted message', 'Warn message',442 warnAppender.list[expectedLength - 1].formattedMessage);443 // test message with params AND native error444 logger.warn('Warn message {}={}', 'key', 'value', new Error('My native error'));445 expectedLength++;446 Assert.assertEquals('warnAppender should have received the logging event', expectedLength, warnAppender.list.length, 0);447 Assert.assertEquals('warnAppender received logging event with incorrect message', 'Warn message {}={}',448 warnAppender.list[expectedLength - 1].message);449 Assert.assertEquals('warnAppender received logging event with incorrect number of parameters', 2,450 warnAppender.list[expectedLength - 1].argumentArray.length, 0);451 Assert.assertEquals('warnAppender received logging event with incorrect 1st parameter', 'key',452 warnAppender.list[expectedLength - 1].argumentArray[0]);453 Assert.assertEquals('warnAppender received logging event with incorrect 2nd parameter', 'value',454 warnAppender.list[expectedLength - 1].argumentArray[1]);455 Assert.assertTrue('warnAppender received logging event without a throwable instance',456 warnAppender.list[expectedLength - 1].throwableProxy !== null);457 Assert458 .assertEquals(459 'warnAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',460 'Error: My native error', warnAppender.list[expectedLength - 1].throwableProxy.message);461 Assert.assertEquals('warnAppender received logging event with incorrect formatted message', 'Warn message key=value',462 warnAppender.list[expectedLength - 1].formattedMessage);463 },464 testErrorLogging : function simpleLoggerTest_testErrorLogging(testCase)465 {466 'use strict';467 var Assert, ListAppender, lockbackLogger, logger, errorAppender, expectedLength;468 Assert = Java.type('org.junit.Assert');469 ListAppender = Java.type('ch.qos.logback.core.read.ListAppender');470 lockbackLogger = Java.type('org.slf4j.LoggerFactory').getLogger(471 'de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.error');472 logger = getSimpleLogger('de.axelfaust.alfresco.nashorn.repo.tests.core.simpleLoggerTest.error');473 Assert.assertFalse('logger instance should have been provided', logger === undefined || logger === null);474 lockbackLogger.setLevel(Java.type('ch.qos.logback.classic.Level').DEBUG);475 errorAppender = new ListAppender();476 errorAppender.start();477 expectedLength = 0;478 lockbackLogger.addAppender(errorAppender);479 Assert.assertTrue('logger.errorEnabled should report TRACE logging as enabled', logger.errorEnabled);480 Assert.assertTrue('logger.isErrorEnabled() should report TRACE logging as enabled', logger.isErrorEnabled());481 // test simple message482 logger.error('Simple error message');483 expectedLength++;484 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);485 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Simple error message',486 errorAppender.list[expectedLength - 1].message);487 // test message with var-arg like parameters488 logger.error('Error message {}={}', 'key', 'value');489 expectedLength++;490 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);491 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Error message {}={}',492 errorAppender.list[expectedLength - 1].message);493 Assert.assertEquals('errorAppender received logging event with incorrect number of parameters', 2,494 errorAppender.list[expectedLength - 1].argumentArray.length, 0);495 Assert.assertEquals('errorAppender received logging event with incorrect 1st parameter', 'key',496 errorAppender.list[expectedLength - 1].argumentArray[0]);497 Assert.assertEquals('errorAppender received logging event with incorrect 2nd parameter', 'value',498 errorAppender.list[expectedLength - 1].argumentArray[1]);499 Assert.assertEquals('errorAppender received logging event with incorrect formatted message', 'Error message key=value',500 errorAppender.list[expectedLength - 1].formattedMessage);501 // test message with array-based parameters502 logger.error('Error message {}={}', [ 'key', 'value' ]);503 expectedLength++;504 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);505 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Error message {}={}',506 errorAppender.list[expectedLength - 1].message);507 Assert.assertEquals('errorAppender received logging event with incorrect number of parameters', 2,508 errorAppender.list[expectedLength - 1].argumentArray.length, 0);509 Assert.assertEquals('errorAppender received logging event with incorrect 1st parameter', 'key',510 errorAppender.list[expectedLength - 1].argumentArray[0]);511 Assert.assertEquals('errorAppender received logging event with incorrect 2nd parameter', 'value',512 errorAppender.list[expectedLength - 1].argumentArray[1]);513 Assert.assertEquals('errorAppender received logging event with incorrect formatted message', 'Error message key=value',514 errorAppender.list[expectedLength - 1].formattedMessage);515 // test message with toString-enabled script object parameter516 logger.error('Error message {}', {517 toString : function()518 {519 return 'value';520 }521 });522 expectedLength++;523 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);524 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Error message {}',525 errorAppender.list[expectedLength - 1].message);526 Assert.assertEquals('errorAppender received logging event with incorrect number of parameters', 1,527 errorAppender.list[expectedLength - 1].argumentArray.length, 0);528 Assert.assertEquals('errorAppender received logging event with incorrect formatted message', 'Error message value',529 errorAppender.list[expectedLength - 1].formattedMessage);530 // test message with native error531 logger.error('Error message', new Error('My native error'));532 expectedLength++;533 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);534 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Error message',535 errorAppender.list[expectedLength - 1].message);536 Assert.assertTrue('errorAppender received logging event without a throwable instance',537 errorAppender.list[expectedLength - 1].throwableProxy !== null);538 Assert539 .assertEquals(540 'errorAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',541 'Error: My native error', errorAppender.list[expectedLength - 1].throwableProxy.message);542 Assert.assertEquals('errorAppender received logging event with incorrect formatted message', 'Error message',543 errorAppender.list[expectedLength - 1].formattedMessage);544 // test message with params AND native error545 logger.error('Error message {}={}', 'key', 'value', new Error('My native error'));546 expectedLength++;547 Assert.assertEquals('errorAppender should have received the logging event', expectedLength, errorAppender.list.length, 0);548 Assert.assertEquals('errorAppender received logging event with incorrect message', 'Error message {}={}',549 errorAppender.list[expectedLength - 1].message);550 Assert.assertEquals('errorAppender received logging event with incorrect number of parameters', 2,551 errorAppender.list[expectedLength - 1].argumentArray.length, 0);552 Assert.assertEquals('errorAppender received logging event with incorrect 1st parameter', 'key',553 errorAppender.list[expectedLength - 1].argumentArray[0]);554 Assert.assertEquals('errorAppender received logging event with incorrect 2nd parameter', 'value',555 errorAppender.list[expectedLength - 1].argumentArray[1]);556 Assert.assertTrue('errorAppender received logging event without a throwable instance',557 errorAppender.list[expectedLength - 1].throwableProxy !== null);558 Assert559 .assertEquals(560 'errorAppender received logging event where throwable message does not match native error message (with implied prefix from error type)',561 'Error: My native error', errorAppender.list[expectedLength - 1].throwableProxy.message);562 Assert.assertEquals('errorAppender received logging event with incorrect formatted message', 'Error message key=value',563 errorAppender.list[expectedLength - 1].formattedMessage);564 }565 };566 return testObj;...

Full Screen

Full Screen

initializeCards.test.js

Source:initializeCards.test.js Github

copy

Full Screen

1import { initializeCards } from "../../utils/helpers";2describe("Initialize Decks", () => {3 describe("Initialize Playable Decks Array", () => {4 const [playableDecks] = initializeCards();5 it("should have length of 10", () => {6 const expectedLength = 10;7 expect(playableDecks).toHaveLength(expectedLength);8 });9 describe("Initialize Decks", () => {10 it("should have arrays with length of 6 at indexes 0 to 3", () => {11 const [firstDeck, secondDeck, thirdDeck, fourthDeck] = playableDecks;12 const expectedLength = 6;13 expect(firstDeck).toHaveLength(expectedLength);14 expect(secondDeck).toHaveLength(expectedLength);15 expect(thirdDeck).toHaveLength(expectedLength);16 expect(fourthDeck).toHaveLength(expectedLength);17 });18 it("should have arrays with length of 5 at indexes 4 to 9", () => {19 const [20 ,21 ,22 ,23 ,24 fifthDeck,25 sixthDeck,26 seventhDeck,27 eighthtDeck,28 ninethDeck,29 tenthDeck,30 ] = playableDecks;31 const expectedLength = 5;32 expect(fifthDeck).toHaveLength(expectedLength);33 expect(sixthDeck).toHaveLength(expectedLength);34 expect(seventhDeck).toHaveLength(expectedLength);35 expect(eighthtDeck).toHaveLength(expectedLength);36 expect(ninethDeck).toHaveLength(expectedLength);37 expect(tenthDeck).toHaveLength(expectedLength);38 });39 test.each(playableDecks[0])("should have properties", (card) => {40 expect(card).toHaveProperty("id");41 expect(card).toHaveProperty("value");42 expect(card).toHaveProperty("isDraggable");43 expect(card).toHaveProperty("isOpen");44 });45 test.each(playableDecks[0])("should have value between 1-13", (card) => {46 const cardValue = card.value;47 expect(cardValue).toBeLessThanOrEqual(13);48 expect(cardValue).toBeGreaterThanOrEqual(1);49 });50 });51 });52 describe("Initialize Spare Decks Array", () => {53 const [, spareDecks] = initializeCards();54 it("should have length of 5", () => {55 const expectedLength = 5;56 expect(spareDecks).toHaveLength(expectedLength);57 });58 describe("Initialize Decks", () => {59 it("should have arrays with length of 10", () => {60 const [firstDeck, secondDeck, thirdDeck, fourthDeck, fifthDeck] =61 spareDecks;62 const expectedLength = 10;63 expect(firstDeck).toHaveLength(expectedLength);64 expect(secondDeck).toHaveLength(expectedLength);65 expect(thirdDeck).toHaveLength(expectedLength);66 expect(fourthDeck).toHaveLength(expectedLength);67 expect(fifthDeck).toHaveLength(expectedLength);68 });69 test.each(spareDecks[0])("should have properties", (card) => {70 expect(card).toHaveProperty("id");71 expect(card).toHaveProperty("value");72 expect(card).toHaveProperty("isDraggable");73 expect(card).toHaveProperty("isOpen");74 });75 test.each(spareDecks[0])("should have value between 1-13", (card) => {76 const cardValue = card.value;77 expect(cardValue).toBeLessThanOrEqual(13);78 expect(cardValue).toBeGreaterThanOrEqual(1);79 });80 });81 });...

Full Screen

Full Screen

test_binary_stream2.js

Source:test_binary_stream2.js Github

copy

Full Screen

1const { BinaryStreamSizeCalculator, BinaryStream } = require("..");2const should = require("should");3const testCases = [4 { suffix: "Int8", value: 100, expectedLength: 1 },5 { suffix: "UInt8", value: 100, expectedLength: 1 },6 { suffix: "Int16", value: 100, expectedLength: 2 },7 { suffix: "UInt16", value: 100, expectedLength: 2 },8 { suffix: "Integer", value: 100, expectedLength: 4 },9 { suffix: "UInt32", value: 100, expectedLength: 4 },10 { suffix: "ByteStream", value: Buffer.from([1, 2, 3]), expectedLength: 4 + 3 },11 { suffix: "ByteStream", value: Buffer.alloc(0), expectedLength: 4 },12 { suffix: "ByteStream", value: null, expectedLength: 4 },13 { suffix: "String", value: "étienne", expectedLength: 4 + 8 },14 { suffix: "String", value: "", expectedLength: 4 },15 { suffix: "String", value: null, expectedLength: 4 },16 { suffix: "Float", value: 0, expectedLength: 4 },17 { suffix: "Double", value: 0, expectedLength: 8 },18 { suffix: "ArrayBuffer", value: new ArrayBuffer(10), expectedLength: 10 }19 //{ suffix: "Int64", value: [0, 100], expectedLength: 8 },20 //{ suffix: "UInt64", value: [0, 100], expectedLength: 8 },21]22describe("BinaryStreamSizeCalculator", () => {23 for (const { suffix, value, expectedLength } of testCases) {24 it(`${suffix}`, () => {25 const binarySizeCalculator = new BinaryStreamSizeCalculator();26 const p = binarySizeCalculator["write" + suffix];27 should.exist(p, " BinaryStreamSizeCalculator#write" + suffix + " not found");28 p.call(binarySizeCalculator, value);29 binarySizeCalculator.length.should.eql(expectedLength);30 binarySizeCalculator.rewind();31 binarySizeCalculator.length.should.eql(0);32 })33 }34});35describe("BinaryStream", () => {36 for (const { suffix, value, expectedLength } of testCases) {37 it(`${suffix}`, () => {38 const stream = new BinaryStream();39 const p = stream["write" + suffix];40 p.call(stream, value);41 stream.length.should.eql(expectedLength);42 stream.rewind();43 const r = stream["read" + suffix];44 const value2 = r.call(stream);45 if (value === null) {46 should(value2).eql(null);47 } else if (value instanceof ArrayBuffer) {48 // nothing49 } else if (value instanceof Buffer) {50 value.toString("base64").should.eql(value2.toString("base64"));51 } else {52 value.should.eql(value2);53 }54 })55 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2fc.assert(3 fc.property(fc.nat(), fc.nat(), (a, b) => {4 return a + b >= a;5 })6);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { expectedLength } = require('fast-check-monorepo');2const { array } = require('fast-check');3const fc = require('fast-check');4const arb = array(fc.string());5const length = expectedLength(arb);6console.log(length);7const { expectedLength } = require('fast-check-monorepo');8const { array } = require('fast-check');9const fc = require('fast-check');10const arb = array(fc.string());11const length = expectedLength(arb);12console.log(length);13const { expectedLength } = require('fast-check-monorepo');14const { array } = require('fast-check');15const fc = require('fast-check');16const arb = array(fc.string());17const length = expectedLength(arb);18console.log(length);19const { expectedLength } = require('fast-check-monorepo');20const { array } = require('fast-check');21const fc = require('fast-check');22const arb = array(fc.string());23const length = expectedLength(arb);24console.log(length);25const { expectedLength } = require('fast-check-monorepo');26const { array } = require('fast-check');27const fc = require('fast-check');28const arb = array(fc.string());29const length = expectedLength(arb);30console.log(length);31const { expectedLength } = require('fast-check-monorepo');32const { array } = require('fast-check');33const fc = require('fast-check');34const arb = array(fc.string());35const length = expectedLength(arb);36console.log(length);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { expectedLength } from 'fast-check-monorepo';2console.log(expectedLength(10, 100, 0.99));3import { expectedLength } from 'fast-check-monorepo';4console.log(expectedLength(10, 100, 0.99));5import { expectedLength } from 'fast-check-monorepo';6console.log(expectedLength(10, 100, 0.99));7import { expectedLength } from 'fast-check-monorepo';8console.log(expectedLength(10, 100, 0.99));9import { expectedLength } from 'fast-check-monorepo';10console.log(expectedLength(10, 100, 0.99));11import { expectedLength } from 'fast-check-monorepo';12console.log(expectedLength(10, 100, 0.99));13import { expectedLength } from 'fast-check-monorepo';14console.log(expectedLength(10, 100, 0.99));15import { expectedLength } from 'fast-check-monorepo';16console.log(expectedLength(10, 100, 0.99));17import { expectedLength } from 'fast-check-monorepo';18console.log(expectedLength(10, 100, 0.99));19import { expectedLength } from 'fast-check-monorepo

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful