Best JavaScript code snippet using mochawesome
integration.test.js
Source:integration.test.js
...162 //});163 });164 });165 }166 function contextTests(data, mapping, kbSchemes, requestLine, tests) {167 if (data != null && typeof data !== 'string') {168 data = JSON.stringify(data, null, 3);169 }170 for (let t = 0; t < tests.length; t++) {171 processContextTest(data, mapping, kbSchemes, requestLine, tests[t]);172 }173 }174 const SEARCH_KB = {175 endpoints: {176 _search: {177 methods: ['GET', 'POST'],178 patterns: ['{indices}/_search', '_search'],179 data_autocomplete_rules: {180 query: {181 match_all: {},182 term: { '{field}': { __template: { f: 1 } } },183 },184 size: {},185 facets: {186 __template: {187 FIELD: {},188 },189 '*': { terms: { field: '{field}' } },190 },191 },192 },193 },194 };195 const MAPPING = {196 index1: {197 properties: {198 'field1.1.1': { type: 'string' },199 'field1.1.2': { type: 'string' },200 },201 },202 index2: {203 properties: {204 'field2.1.1': { type: 'string' },205 'field2.1.2': { type: 'string' },206 },207 },208 };209 contextTests({}, MAPPING, SEARCH_KB, 'POST _search', [210 {211 name: 'Empty doc',212 cursor: { row: 0, column: 1 },213 initialValue: '',214 addTemplate: true,215 prefixToAdd: '',216 suffixToAdd: '',217 rangeToReplace: {218 start: { row: 0, column: 1 },219 end: { row: 0, column: 1 },220 },221 autoCompleteSet: ['facets', 'query', 'size'],222 },223 ]);224 contextTests({}, MAPPING, SEARCH_KB, 'POST _no_context', [225 {226 name: 'Missing KB',227 cursor: { row: 0, column: 1 },228 no_context: true,229 },230 ]);231 contextTests(232 {233 query: {234 f: 1,235 },236 },237 MAPPING,238 {239 globals: {240 query: {241 t1: 2,242 },243 },244 endpoints: {},245 },246 'POST _no_context',247 [248 {249 name: 'Missing KB - global auto complete',250 cursor: { row: 2, column: 5 },251 autoCompleteSet: ['t1'],252 },253 ]254 );255 contextTests(256 {257 query: {258 field: 'something',259 },260 facets: {},261 size: 20,262 },263 MAPPING,264 SEARCH_KB,265 'POST _search',266 [267 {268 name: 'existing dictionary key, no template',269 cursor: { row: 1, column: 6 },270 initialValue: 'query',271 addTemplate: false,272 prefixToAdd: '',273 suffixToAdd: '',274 rangeToReplace: {275 start: { row: 1, column: 3 },276 end: { row: 1, column: 10 },277 },278 autoCompleteSet: ['facets', 'query', 'size'],279 },280 {281 name: 'existing inner dictionary key',282 cursor: { row: 2, column: 7 },283 initialValue: 'field',284 addTemplate: false,285 prefixToAdd: '',286 suffixToAdd: '',287 rangeToReplace: {288 start: { row: 2, column: 6 },289 end: { row: 2, column: 13 },290 },291 autoCompleteSet: ['match_all', 'term'],292 },293 {294 name: 'existing dictionary key, yes template',295 cursor: { row: 4, column: 7 },296 initialValue: 'facets',297 addTemplate: true,298 prefixToAdd: '',299 suffixToAdd: '',300 rangeToReplace: {301 start: { row: 4, column: 3 },302 end: { row: 4, column: 15 },303 },304 autoCompleteSet: ['facets', 'query', 'size'],305 },306 {307 name: 'ignoring meta keys',308 cursor: { row: 4, column: 14 },309 no_context: true,310 },311 ]312 );313 contextTests(314 '{\n' +315 ' "query": {\n' +316 ' "field": "something"\n' +317 ' },\n' +318 ' "facets": {},\n' +319 ' "size": 20 \n' +320 '}',321 MAPPING,322 SEARCH_KB,323 'POST _search',324 [325 {326 name: 'trailing comma, end of line',327 cursor: { row: 4, column: 16 },328 initialValue: '',329 addTemplate: true,330 prefixToAdd: '',331 suffixToAdd: ', ',332 rangeToReplace: {333 start: { row: 4, column: 16 },334 end: { row: 4, column: 16 },335 },336 autoCompleteSet: ['facets', 'query', 'size'],337 },338 {339 name: 'trailing comma, beginning of line',340 cursor: { row: 5, column: 1 },341 initialValue: '',342 addTemplate: true,343 prefixToAdd: '',344 suffixToAdd: ', ',345 rangeToReplace: {346 start: { row: 5, column: 1 },347 end: { row: 5, column: 1 },348 },349 autoCompleteSet: ['facets', 'query', 'size'],350 },351 {352 name: 'prefix comma, beginning of line',353 cursor: { row: 6, column: 0 },354 initialValue: '',355 addTemplate: true,356 prefixToAdd: ', ',357 suffixToAdd: '',358 rangeToReplace: {359 start: { row: 6, column: 0 },360 end: { row: 6, column: 0 },361 },362 autoCompleteSet: ['facets', 'query', 'size'],363 },364 {365 name: 'prefix comma, end of line',366 cursor: { row: 5, column: 14 },367 initialValue: '',368 addTemplate: true,369 prefixToAdd: ', ',370 suffixToAdd: '',371 rangeToReplace: {372 start: { row: 5, column: 14 },373 end: { row: 5, column: 14 },374 },375 autoCompleteSet: ['facets', 'query', 'size'],376 },377 ]378 );379 contextTests(380 {381 object: 1,382 array: 1,383 value_one_of: 1,384 value: 2,385 something_else: 5,386 },387 MAPPING,388 {389 endpoints: {390 _test: {391 patterns: ['_test'],392 data_autocomplete_rules: {393 object: { bla: 1 },394 array: [1],395 value_one_of: { __one_of: [1, 2] },396 value: 3,397 '*': { __one_of: [4, 5] },398 },399 },400 },401 },402 'GET _test',403 [404 {405 name: 'not matching object when { is not opened',406 cursor: { row: 1, column: 12 },407 initialValue: '',408 autoCompleteSet: ['{'],409 },410 {411 name: 'not matching array when [ is not opened',412 cursor: { row: 2, column: 12 },413 initialValue: '',414 autoCompleteSet: ['['],415 },416 {417 name: 'matching value with one_of',418 cursor: { row: 3, column: 19 },419 initialValue: '',420 autoCompleteSet: [1, 2],421 },422 {423 name: 'matching value',424 cursor: { row: 4, column: 12 },425 initialValue: '',426 autoCompleteSet: [3],427 },428 {429 name: 'matching any value with one_of',430 cursor: { row: 5, column: 21 },431 initialValue: '',432 autoCompleteSet: [4, 5],433 },434 ]435 );436 contextTests(437 {438 query: {439 field: 'something',440 },441 facets: {442 name: {},443 },444 size: 20,445 },446 MAPPING,447 SEARCH_KB,448 'GET _search',449 [450 {451 name: '* matching everything',452 cursor: { row: 5, column: 15 },453 initialValue: '',454 addTemplate: true,455 prefixToAdd: '',456 suffixToAdd: '',457 rangeToReplace: {458 start: { row: 5, column: 15 },459 end: { row: 5, column: 15 },460 },461 autoCompleteSet: [{ name: 'terms', meta: 'API' }],462 },463 ]464 );465 contextTests(466 {467 index: '123',468 },469 MAPPING,470 {471 endpoints: {472 _test: {473 patterns: ['_test'],474 data_autocomplete_rules: {475 index: '{index}',476 },477 },478 },479 },480 'GET _test',481 [482 {483 name: '{index} matching',484 cursor: { row: 1, column: 15 },485 autoCompleteSet: [{ name: 'index1', meta: 'index' }, { name: 'index2', meta: 'index' }],486 },487 ]488 );489 function tt(term, template, meta) {490 term = { name: term, template: template };491 if (meta) {492 term.meta = meta;493 }494 return term;495 }496 contextTests(497 {498 array: ['a'],499 oneof: '1',500 },501 MAPPING,502 {503 endpoints: {504 _endpoint: {505 patterns: ['_endpoint'],506 data_autocomplete_rules: {507 array: ['a', 'b'],508 number: 1,509 object: {},510 fixed: { __template: { a: 1 } },511 oneof: { __one_of: ['o1', 'o2'] },512 },513 },514 },515 },516 'GET _endpoint',517 [518 {519 name: 'Templates 1',520 cursor: { row: 1, column: 0 },521 autoCompleteSet: [522 tt('array', []),523 tt('fixed', { a: 1 }),524 tt('number', 1),525 tt('object', {}),526 tt('oneof', 'o1'),527 ],528 },529 {530 name: 'Templates - one off',531 cursor: { row: 4, column: 12 },532 autoCompleteSet: [tt('o1'), tt('o2')],533 },534 ]535 );536 contextTests(537 {538 string: 'value',539 context: {},540 },541 MAPPING,542 {543 endpoints: {544 _endpoint: {545 patterns: ['_endpoint'],546 data_autocomplete_rules: {547 context: {548 __one_of: [549 {550 __condition: {551 lines_regex: 'value',552 },553 match: {},554 },555 {556 __condition: {557 lines_regex: 'other',558 },559 no_match: {},560 },561 { always: {} },562 ],563 },564 },565 },566 },567 },568 'GET _endpoint',569 [570 {571 name: 'Conditionals',572 cursor: { row: 2, column: 15 },573 autoCompleteSet: [tt('always', {}), tt('match', {})],574 },575 ]576 );577 contextTests(578 {579 any_of_numbers: [1],580 any_of_obj: [581 {582 a: 1,583 },584 ],585 any_of_mixed: [586 {587 a: 1,588 },589 2,590 ],591 },592 MAPPING,593 {594 endpoints: {595 _endpoint: {596 patterns: ['_endpoint'],597 data_autocomplete_rules: {598 any_of_numbers: { __template: [1, 2], __any_of: [1, 2, 3] },599 any_of_obj: {600 __template: [{ c: 1 }],601 __any_of: [{ a: 1, b: 2 }, { c: 1 }],602 },603 any_of_mixed: {604 __any_of: [{ a: 1 }, 3],605 },606 },607 },608 },609 },610 'GET _endpoint',611 [612 {613 name: 'Any of - templates',614 cursor: { row: 1, column: 0 },615 autoCompleteSet: [616 tt('any_of_mixed', []),617 tt('any_of_numbers', [1, 2]),618 tt('any_of_obj', [{ c: 1 }]),619 ],620 },621 {622 name: 'Any of - numbers',623 cursor: { row: 2, column: 2 },624 autoCompleteSet: [1, 2, 3],625 },626 {627 name: 'Any of - object',628 cursor: { row: 6, column: 2 },629 autoCompleteSet: [tt('a', 1), tt('b', 2), tt('c', 1)],630 },631 {632 name: 'Any of - mixed - obj',633 cursor: { row: 11, column: 2 },634 autoCompleteSet: [tt('a', 1)],635 },636 {637 name: 'Any of - mixed - both',638 cursor: { row: 13, column: 2 },639 autoCompleteSet: [tt('{'), tt(3)],640 },641 ]642 );643 contextTests(644 {},645 MAPPING,646 {647 endpoints: {648 _endpoint: {649 patterns: ['_endpoint'],650 data_autocomplete_rules: {651 query: '',652 },653 },654 },655 },656 'GET _endpoint',657 [658 {659 name: 'Empty string as default',660 cursor: { row: 0, column: 1 },661 autoCompleteSet: [tt('query', '')],662 },663 ]664 );665 // NOTE: This test emits "error while getting completion terms Error: failed to resolve link666 // [GLOBAL.broken]: Error: failed to resolve global components for ['broken']". but that's667 // expected.668 contextTests(669 {670 a: {671 b: {},672 c: {},673 d: {674 t1a: {},675 },676 e: {},677 f: [{}],678 g: {},679 h: {},680 },681 },682 MAPPING,683 {684 globals: {685 gtarget: {686 t1: 2,687 t1a: {688 __scope_link: '.',689 },690 },691 },692 endpoints: {693 _current: {694 patterns: ['_current'],695 data_autocomplete_rules: {696 a: {697 b: {698 __scope_link: '.a',699 },700 c: {701 __scope_link: 'ext.target',702 },703 d: {704 __scope_link: 'GLOBAL.gtarget',705 },706 e: {707 __scope_link: 'ext',708 },709 f: [710 {711 __scope_link: 'ext.target',712 },713 ],714 g: {715 __scope_link: function() {716 return {717 a: 1,718 b: 2,719 };720 },721 },722 h: {723 __scope_link: 'GLOBAL.broken',724 },725 },726 },727 },728 ext: {729 patterns: ['ext'],730 data_autocomplete_rules: {731 target: {732 t2: 1,733 },734 },735 },736 },737 },738 'GET _current',739 [740 {741 name: 'Relative scope link test',742 cursor: { row: 2, column: 12 },743 autoCompleteSet: [744 tt('b', {}),745 tt('c', {}),746 tt('d', {}),747 tt('e', {}),748 tt('f', [{}]),749 tt('g', {}),750 tt('h', {}),751 ],752 },753 {754 name: 'External scope link test',755 cursor: { row: 3, column: 12 },756 autoCompleteSet: [tt('t2', 1)],757 },758 {759 name: 'Global scope link test',760 cursor: { row: 4, column: 12 },761 autoCompleteSet: [tt('t1', 2), tt('t1a', {})],762 },763 {764 name: 'Global scope link with an internal scope link',765 cursor: { row: 5, column: 17 },766 autoCompleteSet: [tt('t1', 2), tt('t1a', {})],767 },768 {769 name: 'Entire endpoint scope link test',770 cursor: { row: 7, column: 12 },771 autoCompleteSet: [tt('target', {})],772 },773 {774 name: 'A scope link within an array',775 cursor: { row: 9, column: 10 },776 autoCompleteSet: [tt('t2', 1)],777 },778 {779 name: 'A function based scope link',780 cursor: { row: 11, column: 12 },781 autoCompleteSet: [tt('a', 1), tt('b', 2)],782 },783 {784 name: 'A global scope link with wrong link',785 cursor: { row: 12, column: 12 },786 assertThrows: /broken/,787 },788 ]789 );790 contextTests(791 {},792 MAPPING,793 {794 globals: {795 gtarget: {796 t1: 2,797 },798 },799 endpoints: {800 _current: {801 patterns: ['_current'],802 id: 'GET _current',803 data_autocomplete_rules: {804 __scope_link: 'GLOBAL.gtarget',805 },806 },807 },808 },809 'GET _current',810 [811 {812 name: 'Top level scope link',813 cursor: { row: 0, column: 1 },814 autoCompleteSet: [tt('t1', 2)],815 },816 ]817 );818 contextTests(819 {820 a: {},821 },822 MAPPING,823 {824 endpoints: {825 _endpoint: {826 patterns: ['_endpoint'],827 data_autocomplete_rules: {828 a: {},829 b: {},830 },831 },832 },833 },834 'GET _endpoint',835 [836 {837 name: 'Path after empty object',838 cursor: { row: 1, column: 10 },839 autoCompleteSet: ['a', 'b'],840 },841 ]842 );843 contextTests(844 {845 '': {},846 },847 MAPPING,848 SEARCH_KB,849 'POST _search',850 [851 {852 name: 'Replace an empty string',853 cursor: { row: 1, column: 4 },854 rangeToReplace: {855 start: { row: 1, column: 3 },856 end: { row: 1, column: 9 },857 },858 },859 ]860 );861 contextTests(862 {863 a: [864 {865 c: {},866 },867 ],868 },869 MAPPING,870 {871 endpoints: {872 _endpoint: {873 patterns: ['_endpoint'],874 data_autocomplete_rules: {875 a: [{ b: 1 }],876 },877 },878 },879 },880 'GET _endpoint',881 [882 {883 name: 'List of objects - internal autocomplete',884 cursor: { row: 3, column: 10 },885 autoCompleteSet: ['b'],886 },887 {888 name: 'List of objects - external template',889 cursor: { row: 0, column: 1 },890 autoCompleteSet: [tt('a', [{}])],891 },892 ]893 );894 contextTests(895 {896 query: {897 term: {898 field: 'something',899 },900 },901 facets: {902 test: {903 terms: {904 field: 'test',905 },906 },907 },908 size: 20,909 },910 MAPPING,911 SEARCH_KB,912 'POST index1/_search',913 [914 {915 name: 'Field completion as scope',916 cursor: { row: 3, column: 10 },917 autoCompleteSet: [918 tt('field1.1.1', { f: 1 }, 'string'),919 tt('field1.1.2', { f: 1 }, 'string'),920 ],921 },922 {923 name: 'Field completion as value',924 cursor: { row: 9, column: 23 },925 autoCompleteSet: [926 { name: 'field1.1.1', meta: 'string' },927 { name: 'field1.1.2', meta: 'string' },928 ],929 },930 ]931 );932 // NOTE: This test emits "Can't extract a valid url token path", but that's expected.933 contextTests('POST _search\n', MAPPING, SEARCH_KB, null, [934 {935 name: 'initial doc start',936 cursor: { row: 1, column: 0 },937 autoCompleteSet: ['{'],938 prefixToAdd: '',939 suffixToAdd: '',940 },941 ]);942 contextTests(943 '{\n' + ' "query": {} \n' + '}\n' + '\n' + '\n',944 MAPPING,945 SEARCH_KB,946 'POST _search',947 [948 {949 name: 'Cursor rows after request end',950 cursor: { row: 4, column: 0 },951 autoCompleteSet: ['GET', 'PUT', 'POST', 'DELETE', 'HEAD'],952 prefixToAdd: '',953 suffixToAdd: ' ',954 },955 {956 name: 'Cursor just after request end',957 cursor: { row: 2, column: 1 },958 no_context: true,959 },960 ]961 );962 const CLUSTER_KB = {963 endpoints: {964 _search: {965 patterns: ['_search', '{indices}/_search'],966 url_params: {967 search_type: ['count', 'query_then_fetch'],968 scroll: '10m',969 },970 methods: ['GET'],971 data_autocomplete_rules: {},972 },973 '_cluster/stats': {974 patterns: ['_cluster/stats'],975 indices_mode: 'none',976 data_autocomplete_rules: {},977 methods: ['GET'],978 },979 '_cluster/nodes/stats': {980 patterns: ['_cluster/nodes/stats'],981 data_autocomplete_rules: {},982 methods: ['GET'],983 },984 },985 };986 contextTests(null, MAPPING, CLUSTER_KB, 'GET _cluster', [987 {988 name: 'Endpoints with slashes - no slash',989 cursor: { row: 0, column: 8 },990 autoCompleteSet: ['_cluster/nodes/stats', '_cluster/stats', '_search', 'index1', 'index2'],991 prefixToAdd: '',992 suffixToAdd: '',993 },994 ]);995 contextTests(null, MAPPING, CLUSTER_KB, 'GET _cluster/', [996 {997 name: 'Endpoints with slashes - before slash',998 cursor: { row: 0, column: 7 },999 autoCompleteSet: ['_cluster/nodes/stats', '_cluster/stats', '_search', 'index1', 'index2'],1000 prefixToAdd: '',1001 suffixToAdd: '',1002 },1003 {1004 name: 'Endpoints with slashes - on slash',1005 cursor: { row: 0, column: 12 },1006 autoCompleteSet: ['_cluster/nodes/stats', '_cluster/stats', '_search', 'index1', 'index2'],1007 prefixToAdd: '',1008 suffixToAdd: '',1009 },1010 {1011 name: 'Endpoints with slashes - after slash',1012 cursor: { row: 0, column: 13 },1013 autoCompleteSet: ['nodes/stats', 'stats'],1014 prefixToAdd: '',1015 suffixToAdd: '',1016 },1017 ]);1018 contextTests(null, MAPPING, CLUSTER_KB, 'GET _cluster/no', [1019 {1020 name: 'Endpoints with slashes - after slash',1021 cursor: { row: 0, column: 14 },1022 autoCompleteSet: [1023 { name: 'nodes/stats', meta: 'endpoint' },1024 { name: 'stats', meta: 'endpoint' },1025 ],1026 prefixToAdd: '',1027 suffixToAdd: '',1028 initialValue: 'no',1029 },1030 ]);1031 contextTests(null, MAPPING, CLUSTER_KB, 'GET _cluster/nodes/st', [1032 {1033 name: 'Endpoints with two slashes',1034 cursor: { row: 0, column: 20 },1035 autoCompleteSet: ['stats'],1036 prefixToAdd: '',1037 suffixToAdd: '',1038 initialValue: 'st',1039 },1040 ]);1041 contextTests(null, MAPPING, CLUSTER_KB, 'GET ', [1042 {1043 name: 'Immediately after space + method',1044 cursor: { row: 0, column: 4 },1045 autoCompleteSet: [1046 { name: '_cluster/nodes/stats', meta: 'endpoint' },1047 { name: '_cluster/stats', meta: 'endpoint' },1048 { name: '_search', meta: 'endpoint' },1049 { name: 'index1', meta: 'index' },1050 { name: 'index2', meta: 'index' },1051 ],1052 prefixToAdd: '',1053 suffixToAdd: '',1054 initialValue: '',1055 },1056 ]);1057 contextTests(null, MAPPING, CLUSTER_KB, 'GET cl', [1058 {1059 name: 'Endpoints by subpart GET',1060 cursor: { row: 0, column: 6 },1061 autoCompleteSet: [1062 { name: '_cluster/nodes/stats', meta: 'endpoint' },1063 { name: '_cluster/stats', meta: 'endpoint' },1064 { name: '_search', meta: 'endpoint' },1065 { name: 'index1', meta: 'index' },1066 { name: 'index2', meta: 'index' },1067 ],1068 prefixToAdd: '',1069 suffixToAdd: '',1070 initialValue: 'cl',1071 method: 'GET',1072 },1073 ]);1074 contextTests(null, MAPPING, CLUSTER_KB, 'POST cl', [1075 {1076 name: 'Endpoints by subpart POST',1077 cursor: { row: 0, column: 7 },1078 no_context: true,1079 prefixToAdd: '',1080 suffixToAdd: '',1081 initialValue: 'cl',1082 },1083 ]);1084 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?', [1085 {1086 name: 'Params just after ?',1087 cursor: { row: 0, column: 12 },1088 autoCompleteSet: [1089 { name: 'filter_path', meta: 'param', insertValue: 'filter_path=' },1090 { name: 'format', meta: 'param', insertValue: 'format=' },1091 { name: 'pretty', meta: 'flag' },1092 { name: 'scroll', meta: 'param', insertValue: 'scroll=' },1093 { name: 'search_type', meta: 'param', insertValue: 'search_type=' },1094 ],1095 prefixToAdd: '',1096 suffixToAdd: '',1097 },1098 ]);1099 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?format=', [1100 {1101 name: 'Params values',1102 cursor: { row: 0, column: 19 },1103 autoCompleteSet: [{ name: 'json', meta: 'format' }, { name: 'yaml', meta: 'format' }],1104 prefixToAdd: '',1105 suffixToAdd: '',1106 },1107 ]);1108 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?format=yaml&', [1109 {1110 name: 'Params after amp',1111 cursor: { row: 0, column: 24 },1112 autoCompleteSet: [1113 { name: 'filter_path', meta: 'param', insertValue: 'filter_path=' },1114 { name: 'format', meta: 'param', insertValue: 'format=' },1115 { name: 'pretty', meta: 'flag' },1116 { name: 'scroll', meta: 'param', insertValue: 'scroll=' },1117 { name: 'search_type', meta: 'param', insertValue: 'search_type=' },1118 ],1119 prefixToAdd: '',1120 suffixToAdd: '',1121 },1122 ]);1123 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?format=yaml&search', [1124 {1125 name: 'Params on existing param',1126 cursor: { row: 0, column: 26 },1127 rangeToReplace: {1128 start: { row: 0, column: 24 },1129 end: { row: 0, column: 30 },1130 },1131 autoCompleteSet: [1132 { name: 'filter_path', meta: 'param', insertValue: 'filter_path=' },1133 { name: 'format', meta: 'param', insertValue: 'format=' },1134 { name: 'pretty', meta: 'flag' },1135 { name: 'scroll', meta: 'param', insertValue: 'scroll=' },1136 { name: 'search_type', meta: 'param', insertValue: 'search_type=' },1137 ],1138 prefixToAdd: '',1139 suffixToAdd: '',1140 },1141 ]);1142 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?format=yaml&search_type=cou', [1143 {1144 name: 'Params on existing value',1145 cursor: { row: 0, column: 37 },1146 rangeToReplace: {1147 start: { row: 0, column: 36 },1148 end: { row: 0, column: 39 },1149 },1150 autoCompleteSet: [1151 { name: 'count', meta: 'search_type' },1152 { name: 'query_then_fetch', meta: 'search_type' },1153 ],1154 prefixToAdd: '',1155 suffixToAdd: '',1156 },1157 ]);1158 contextTests(null, MAPPING, CLUSTER_KB, 'GET _search?format=yaml&search_type=cou', [1159 {1160 name: 'Params on just after = with existing value',1161 cursor: { row: 0, column: 36 },1162 rangeToReplace: {1163 start: { row: 0, column: 36 },1164 end: { row: 0, column: 36 },1165 },1166 autoCompleteSet: [1167 { name: 'count', meta: 'search_type' },1168 { name: 'query_then_fetch', meta: 'search_type' },1169 ],1170 prefixToAdd: '',1171 suffixToAdd: '',1172 },1173 ]);1174 contextTests(1175 {1176 query: {1177 field: 'something',1178 },1179 facets: {},1180 size: 20,1181 },1182 MAPPING,1183 SEARCH_KB,1184 'POST http://somehost/_search',1185 [1186 {1187 name: 'fullurl - existing dictionary key, no template',1188 cursor: { row: 1, column: 6 },...
Using AI Code Generation
1const Mochawesome = require('mochawesome');2const contextTests = Mochawesome.contextTests;3const Mochawesome = require('mochawesome');4const contextTests = Mochawesome.contextTests;5const assert = require('assert');6describe('Test', function() {7 it('should be true', function() {8 assert.equal(true, true);9 });10 it('should be false', function() {11 assert.equal(true, false);12 });13});14contextTests();15### Context (this) in Mocha16- `skip()` - Skip the current test17- `timeout()` - Set the timeout for the current test18- `slow()` - Set the slow threshold for the current test19- `enableTimeouts()` - Enable timeouts for the current test20- `disableTimeouts()` - Disable timeouts for the current test21- `runnable()` - Get the current runnable22- `runnable(bool)` - Set the current runnable23const Mochawesome = require('mochawesome');24const contextTests = Mochawesome.contextTests;25describe('Test', function() {26 it('should be true', function() {27 assert.equal(this.title, 'should be true');28 });29});30contextTests();31See [CHANGELOG.md](
Using AI Code Generation
1const { contextTests } = require('mochawesome/addContext');2const addContext = require('mochawesome/addContext');3describe('Test Suite', function() {4 it('Test Case', function() {5 contextTests(this, 'Test Case');6 addContext(this, 'Test Case');7 });8});9const { contextTests } = require('mochawesome/addContext');10describe('Test Suite', function() {11 it('Test Case', function() {12 contextTests(this, 'Test Case');13 });14});15const addContext = require('mochawesome/addContext');16describe('Test Suite', function() {17 it('Test Case', function() {18 addContext(this, 'Test Case');19 });20});21const path = require('path');22const { generate } = require('mochawesome-report-generator');23const mochawesomeReportDir = path.join(__dirname, '..', 'mochawesome-report');24const report = generate({ jsonDir: mochawesomeReportDir });25const { merge } = require('mochawesome-merge');26const mochawesomeReportDir = path.join(__dirname, '..', 'mochawesome-report');27const report = merge({28 path.join(mochawesomeReportDir, 'mochawesome.json'),29 path.join(mochawesomeReportDir, 'mochawesome-1.json'),30 path.join(mochawesomeReportDir, 'mochawesome-2.json')31});32const { merge } = require('mochawesome-merge');33const mochawesomeReportDir = path.join(__dirname, '..', 'mochawesome-report');34const report = merge({35 path.join(moch
Using AI Code Generation
1var contextTests = require('mochawesome/addContext');2var expect = require('chai').expect;3var request = require('request');4var fs = require('fs');5var assert = require('assert');6describe('API Testing', function () {7 describe('GET Request', function () {8 it('should return all the users', function (done) {9 contextTests(this, 'API Response: ' + body);10 assert.equal(200, res.statusCode);11 done();12 });13 });14 });15 describe('POST Request', function () {16 it('should create a new user', function (done) {17 var data = {18 };19 request({20 }, function (err, res, body) {21 contextTests(this, 'API Response: ' + JSON.stringify(body));22 assert.equal(201, res.statusCode);23 done();24 });25 });26 });27 describe('PUT Request', function () {28 it('should update an existing user', function (done) {29 var data = {30 };31 request({32 }, function (err, res, body) {33 contextTests(this, 'API Response: ' + JSON.stringify(body));34 assert.equal(200, res.statusCode);35 done();36 });37 });38 });39 describe('DELETE Request', function () {40 it('should delete an existing user', function (done) {41 request({42 }, function (err, res, body) {43 contextTests(this, 'API Response: ' + body);44 assert.equal(204, res.statusCode);45 done();46 });47 });48 });49});
Using AI Code Generation
1let contextTests = require('mochawesome/addContext');2let assert = require('assert');3describe('Mochawesome', function() {4 it('should add context', function() {5 contextTests(this, 'my context');6 assert.equal(1, 1);7 });8});9docker run --rm -v $(pwd)/reports:/app/reports mochawesome10docker run --rm -v $(pwd)/reports:/app/reports mochawesome
Using AI Code Generation
1import { contextTests } from 'mochawesome/addContext';2import { expect } from 'chai';3import { browser } from 'protractor';4import { LoginPage } from './loginPage';5import { BasePage } from './basePage';6import { ProfilePage } from './profilePage';7import { PostPage } from './postPage';8import { CommentPage } from './commentPage';9import { UserPage } from './userPage';10import { Post } from '../models/post';11import { Comment } from '../models/comment';12import { User } from '../models/user';13export class Test {14 async runTest() {15 let loginPage = new LoginPage();16 let basePage = new BasePage();17 let profilePage = new ProfilePage();18 let postPage = new PostPage();19 let commentPage = new CommentPage();20 let userPage = new UserPage();21 let post = new Post();22 let comment = new Comment();23 let user = new User();24 user.username = await basePage.getUsername();25 user.password = await basePage.getPassword();26 await basePage.get();27 await loginPage.login(user.username, user.password);28 await basePage.get();29 await profilePage.createPost(post);30 await basePage.get();31 await postPage.addComment(comment);32 await basePage.get();33 await profilePage.addUser(user);34 await basePage.get();35 await userPage.deleteUser(user);36 await basePage.get();37 await postPage.deletePost(post);38 await basePage.get();39 await profilePage.logout();40 }41}
Using AI Code Generation
1const { contextTests } = require('mochawesome/addContext');2const { expect } = require('chai');3it('should pass', function() {4 contextTests(this, {5 });6});7it('should fail', function() {8 contextTests(this, {9 });10 expect(true).to.equal(false);11});12it('should pass', function() {13 contextTests(this, {14 });15});16![Mochawesome Report](
Using AI Code Generation
1const mochawesome = require('mochawesome');2const context = mochawesome.getContext();3const { expect } = require('chai');4const { add } = require('../utils');5describe('My Test Suite', function() {6 it('My Test Case', function() {7 const result = add(1, 2);8 expect(result).to.equal(3);9 context.addTestContext('This is a custom message');10 });11});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!