Best JavaScript code snippet using storybook-test-runner
define-property-command-tests.js
Source:define-property-command-tests.js
...8/***************************************************************************************************9 * define property command tests10 */11__(function() {12 module.exports = util.makeTest({13 /***************************************************************************14 * name15 */16 name: 'DefinePropertyCommandTests',17 /***************************************************************************18 * description19 */20 description: 'Define property command tests',21 /***************************************************************************22 * setup23 */24 setup: function () { },25 /***************************************************************************26 * teardown27 */28 teardown: function () { },29 /***************************************************************************30 * tests31 */32 tests: [33 util.makeTest({34 name: 'SetTests',35 tests: [36 util.makeTest({37 name: 'PropertyPathSetTest',38 doTest: function() {39 let _prototype = {40 a: {41 b: {42 c: 143 }44 }45 }46 let object = o({47 _type: _prototype,48 '$a.b.c': 2,49 d: 350 })51 util.isMatch(object, {52 a: {53 b: {54 c: 255 }56 },57 d: 358 })59 }60 }),61 util.makeTest({62 name: 'PropertyPathSetNonExistentPathTest',63 doTest: function() {64 let _prototype = {65 a: {66 b: {67 c: 168 }69 }70 }71 let object = o({72 _type: _prototype,73 '$d.e.f': 274 })75 util.isMatch(object, {76 a: {77 b: {78 c: 179 }80 },81 d: {82 e: {83 f: 284 }85 }86 })87 }88 }),89 util.makeTest({90 name: 'PropertyPathArrayIndexTest',91 doTest: function() {92 let _prototype = {93 a: {94 b: {95 c: 196 }97 }98 }99 let object = o({100 _type: _prototype,101 '$a.b.d[0]': 2102 })103 util.isMatch(object, {104 a: {105 b: {106 c: 1,107 d: [2]108 }109 },110 })111 }112 }),113 util.makeTest({114 name: 'PropertyPathSparseArrayIndexTest',115 doTest: function() {116 let _prototype = {117 a: {118 b: {119 c: 1120 }121 }122 }123 let object = o({124 _type: _prototype,125 '$a.b.d[100]': 2126 })127 util.isMatch(object, {128 a: {129 b: {130 c: 1,131 d: _.map(_.range(100), i => i === 99 ? 2 : undefined)132 }133 },134 })135 }136 }),137 util.makeTest({138 name: 'PropertyPathIntLikeStringsTreatedAsPropertiesTest',139 description: 'Test the behavior of integer like strings (e.g., "01")',140 doTest: function() {141 let _prototype = {142 a: {143 b: {144 c: 1145 }146 }147 }148 let object = o({149 _type: _prototype,150 '$a.b.d[01]': 2151 })152 util.isMatch(object, {153 a: {154 b: {155 c: 1,156 d: {157 '01': 2158 }159 }160 },161 })162 }163 }),164 util.makeTest({165 name: 'PropertyPathArrayIndexIntoObjectTest',166 doTest: function() {167 let _prototype = {168 a: {169 b: {170 c: 1,171 d: {172 e: 2173 }174 }175 }176 }177 let object = o({178 _type: _prototype,179 '$a.b.d[1]': 3180 })181 util.isMatch(object, {182 a: {183 b: {184 c: 1,185 d: {186 e: 2,187 1: 3188 }189 }190 },191 })192 }193 }),194 util.makeTest({195 name: 'PropertyPathStringIndexThrowsTest',196 doTest: function() {197 let _prototype = {198 a: {199 b: {200 c: 'bar',201 }202 }203 }204 assert.throws(205 () => {206 let object = o({207 _type: _prototype,208 '$a.b.c[2]': 'z'209 })210 }, TypeError)211 }212 }),213 util.makeTest({214 name: 'PropertyPathLeaderCharaterNonPropertyPathTest',215 description: 'Test that a leader character followed by a non property path is ' +216 'not interpreted as a property path',217 doTest: function() {218 let _prototype = {219 a: {220 b: {221 c: 1,222 }223 }224 }225 let object = o({226 _type: _prototype,227 $a: 2228 })229 util.isMatch(object, {230 $a: 2231 })232 }233 }),234 util.makeTest({235 name: 'PropertyPathLeaderCharaterEscapeNonPropertyPathTest',236 description: 'Test that an even number of leader characters (e.g., "$") does not' +237 'does not get interpreted as a property path.',238 doTest: function() {239 let _prototype = {240 a: {241 b: {242 c: 1,243 }244 }245 }246 let object = o({247 _type: _prototype,248 '$$$$a.b.c': 2249 })250 util.isMatch(object, {251 a: {252 b: {253 c: 1254 }255 },256 '$$a.b.c': 2257 })258 }259 }),260 util.makeTest({261 name: 'PropertyPathLeaderCharaterEscapeTest',262 description: 'Test that an odd number of leader characters (e.g., "$") gets ' +263 'interpreted as a property path with trailing leader characters ' +264 'escaped properly.',265 doTest: function() {266 let _prototype = {267 a: {268 b: {269 c: 1,270 }271 }272 }273 let object = o({274 _type: _prototype,275 '$$$$$a.b.c': 2276 })277 util.isMatch(object, {278 a: {279 b: {280 c: 1281 }282 },283 $$a: {284 b: {285 c: 2286 }287 }288 })289 }290 }),291 util.makeTest({292 name: 'PropertyPathLeaderCharaterInPathTreatedLiterallyTest',293 description: 'Test that a property name with leader characters in the ' +294 'property path is treated literally',295 doTest: function() {296 let _prototype = {297 a: {298 b: {299 c: 1,300 }301 }302 }303 let object = o({304 _type: _prototype,305 '$a.b.$c': 2,306 '$a.b.$$c': 3,307 '$a.b.$$$c': 4308 })309 util.isMatch(object, {310 a: {311 b: {312 c: 1,313 $c: 2,314 $$c: 3,315 $$$c: 4316 }317 },318 })319 }320 }),321 ]322 }),323 util.makeTest({324 name: 'MergeTests',325 tests: [326 util.makeTest({327 name: 'SingleLevelMergeTest',328 doTest: function() {329 let _prototype = {330 a: 1,331 b: 2,332 c: {333 d: 3,334 e: 4335 }336 }337 let object = o({338 _type: _prototype,339 g: 5,340 c: {341 $merge: {342 d: 6,343 f: 7344 }345 }346 })347 util.isMatch(object, {348 a: 1,349 b: 2,350 g: 5,351 c: {352 d: 6,353 e: 4,354 f: 7355 }356 })357 }358 }),359 util.makeTest({360 name: 'MultiLevelMergeOverwriteTest',361 doTest: function() {362 let _prototype = {363 a: 1,364 b: 2,365 c: {366 d: {367 e: 3368 }369 }370 }371 let object = o({372 _type: _prototype,373 c: {374 $merge: {375 d: {376 f: 4377 },378 g: 5379 }380 }381 })382 // confirm "c.d.f" is present383 util.isMatch(object, {384 a: 1,385 b: 2,386 c: {387 d: {388 f: 4389 },390 g: 5391 }392 })393 // confirm "c.d.e" is not394 util.notIsMatch(object, {395 c: {396 d: {397 e: 4398 }399 }400 })401 }402 }),403 util.makeTest({404 name: 'InnerUnchainedMergeDoesNotMergeTest',405 description: 'Verify that a nested "$merge" whose parent objects do ' +406 'not contain "$merge" commands does not merge',407 doTest: function() {408 let _prototype = {409 a: 1,410 b: 2,411 c: {412 d: {413 e: 3414 }415 }416 }417 let object = o({418 _type: _prototype,419 c: {420 d: {421 $merge: {422 f: 4423 }424 },425 g: 5426 }427 })428 // confirm "c.d.$merge.f" is present429 util.isMatch(object, {430 a: 1,431 b: 2,432 c: {433 d: {434 $merge: {435 f: 4436 }437 }438 }439 })440 }441 }),442 util.makeTest({443 name: 'ChainMergeTest',444 doTest: function() {445 let _prototype = {446 a: 1,447 b: 2,448 c: {449 d: {450 e: {451 f: 3452 }453 }454 }455 }456 let object = o({457 _type: _prototype,458 c: {459 $merge: {460 d: {461 $merge: {462 e: {463 $merge: {464 g: 4465 }466 }467 }468 }469 }470 }471 })472 util.isMatch(object, {473 a: 1,474 b: 2,475 c: {476 d: {477 e: {478 f: 3,479 g: 4480 }481 }482 }483 })484 }485 }),486 util.makeTest({487 name: 'ChainMergeNonExistentPathTest',488 doTest: function() {489 let _prototype = {490 a: 1,491 b: 2,492 c: {493 d: {494 e: {495 f: 3496 }497 }498 }499 }500 let object = o({501 _type: _prototype,502 g: {503 $merge: {504 h: {505 $merge: {506 i: {507 $merge: {508 j: 4509 }510 }511 }512 }513 }514 }515 })516 util.isMatch(object, {517 a: 1,518 b: 2,519 c: {520 d: {521 e: {522 f: 3,523 }524 }525 },526 g: {527 h: {528 i: {529 j: 4530 }531 }532 }533 })534 }535 }),536 util.makeTest({537 name: 'PropertyPathInnerMergeTest',538 description: 'Test dot notation $merge',539 doTest: function() {540 let _prototype = {541 a: 1,542 b: 2,543 c: {544 d: {545 e: {546 f: 3547 }548 }549 }550 }551 let object = o({552 _type: _prototype,553 '$c.d.e': {554 $merge: {555 g: 4556 }557 }558 })559 util.isMatch(object, {560 a: 1,561 b: 2,562 c: {563 d: {564 e: {565 f: 3,566 g: 4567 }568 }569 }570 })571 }572 }),573 util.makeTest({574 name: 'PropertyPathInnerMergeNonExistentPathTest',575 description: 'Test dot notation $merge on non existent path',576 doTest: function() {577 let _prototype = {578 a: 1,579 b: 2,580 c: {581 d: {582 e: {583 f: 3584 }585 }586 }587 }588 let object = o({589 _type: _prototype,590 '$g.h.i': {591 $merge: {592 j: 4593 }594 }595 })596 util.isMatch(object, {597 a: 1,598 b: 2,599 c: {600 d: {601 e: {602 f: 3603 }604 }605 },606 g: {607 h: {608 i: {609 j: 4610 }611 }612 }613 })614 }615 }),616 util.makeTest({617 name: 'ObjectWithMergeCommandContainsExtraKeysTest',618 description: 'Test dot notation $merge on non existent path',619 doTest: function() {620 let _prototype = {621 a: 1,622 b: 2,623 c: {624 d: {625 e: {626 f: 3627 }628 }629 }630 }631 let object = o({632 _type: _prototype,633 'c.d.e': {634 $merge: {635 g: 4636 },637 h: 5638 }639 })640 util.isMatch(object, {641 a: 1,642 b: 2,643 c: {644 d: {645 e: {646 f: 3647 }648 }649 },650 'c.d.e': {651 $merge: {652 g: 4653 },654 h: 5655 }656 })657 }658 }),659 util.makeTest({660 name: 'MergeWithArrayTest',661 doTest: function() {662 let _prototype = {663 a: {664 b: {665 c: [0]666 }667 }668 }669 let object = o({670 _type: _prototype,671 '$a.b.c': {672 $merge: {673 j: 4674 }675 }676 })677 util.isMatch(object, {678 a: {679 b: {680 c: _.assign([0], {j: 4})681 }682 }683 })684 }685 }),686 util.makeTest({687 name: 'MergeWithArrayElementTest',688 doTest: function() {689 let _prototype = {690 a: {691 b: {692 c: [{693 d: 1694 }]695 }696 }697 }698 let object = o({699 _type: _prototype,700 '$a.b.c[0]': {701 $merge: {702 e: 2703 }704 }705 })706 util.isMatch(object, {707 a: {708 b: {709 c: [{710 d: 1,711 e: 2712 }]713 }714 }715 })716 }717 }),718 util.makeTest({719 name: 'MergeWithNonObjectThrowsTest',720 doTest: function() {721 let _prototype = {722 a: 'foo'723 }724 assert.throws(725 () => {726 let object = o({727 _type: _prototype,728 a: {729 $merge: {730 b: 1731 }732 }733 })734 }, TypeError)735 }736 }),737 ]738 }),739 util.makeTest({740 name: 'PropertyTests',741 tests: [742 util.makeTest({743 name: 'PropertyPathPropertyTest',744 doTest: function() {745 let _prototype = {746 a: {747 b: {748 c: 1749 }750 }751 }752 let object = o({753 _type: _prototype,754 '$a.b.c': {755 $property: {756 enumerable: false,757 configurable: false,758 writable: false,759 value: 2760 }761 }762 })763 util.isMatch(object, {764 a: {765 b: {766 c: 2767 }768 }769 })770 object.a.b.c = 3771 assert.equal(object.a.b.c, 2)772 assert.equal(_.keys(object.a.b).length, 0)773 }774 }),775 util.makeTest({776 name: 'PropertyPathPropertyNonExistentPathTest',777 doTest: function() {778 let _prototype = {779 a: {780 b: {781 c: 1782 }783 }784 }785 let object = o({786 _type: _prototype,787 '$d.e.f': {788 $property: {789 enumerable: false,790 configurable: false,791 writable: false,792 value: 2793 }794 }795 })796 util.isMatch(object, {797 a: {798 b: {799 c: 1800 }801 },802 d: {803 e: {804 f: 2805 }806 }807 })808 object.a.b.c = 3809 assert.equal(object.a.b.c, 3)810 object.d.e.f = 3811 assert.equal(object.d.e.f, 2)812 assert.equal(_.keys(object.a.b).length, 1)813 assert.equal(_.keys(object.d.e).length, 0)814 }815 })816 ]817 }),818 util.makeTest({819 name: 'DeleteTests',820 tests: [821 util.makeTest({822 name: 'SingleLevelDeleteTest',823 doTest: function() {824 let _prototype = {825 a: 1,826 b: 2,827 c: {828 d: 3,829 e: 4830 }831 }832 let object = o({833 _type: _prototype,834 c: {835 $delete: 'e'836 }837 })838 assert.equal(object.c.d, 3)839 assert.ok(_.isNil(object.c.e))840 }841 }),842 util.makeTest({843 name: 'SingleLevelMultiDeleteTest',844 doTest: function() {845 let _prototype = {846 a: 1,847 b: 2,848 c: {849 d: 3,850 e: 4851 }852 }853 let object = o({854 _type: _prototype,855 c: {856 $delete: ['d', 'e']857 }858 })859 assert.ok(_.isNil(object.c.d))860 assert.ok(_.isNil(object.c.e))861 }862 }),863 util.makeTest({864 name: 'PropertyPathDeleteTest',865 doTest: function() {866 let _prototype = {867 a: 1,868 b: 2,869 c: {870 d: {871 e: 3,872 f: 4873 }874 }875 }876 let object = o({877 _type: _prototype,878 '$c.d': {879 $delete: ['f']880 }881 })882 util.isMatch(object, {883 a: 1,884 b: 2,885 c: {886 d: {887 e: 3888 }889 }890 })891 assert.ok(_.isNil(object.c.d.f))892 }893 }),894 ]895 }),896 util.makeTest({897 name: 'MultiOpTests',898 tests: [899 util.makeTest({900 name: 'SingleLevelMultiOpTest',901 doTest: function() {902 let _prototype = {903 a: 1,904 b: 2,905 c: {906 d: 3,907 e: 4908 }909 }910 let object = o({911 _type: _prototype,912 c: {913 $multiop: [914 {$delete: 'e'},915 {$merge: {f: 5, g: 6}}916 ]917 }918 })919 util.isMatch(object, {920 a: 1,921 b: 2,922 c: {923 d: 3,924 f: 5,925 g: 6,926 }927 })928 assert.ok(_.isNil(object.c.e))929 }930 }),931 util.makeTest({932 name: 'SingleLevelMultiOpSetOverrideTest',933 doTest: function() {934 let _prototype = {935 a: 1,936 b: 2,937 c: {938 d: 3,939 e: 4940 }941 }942 let object = o({943 _type: _prototype,944 c: {945 $multiop: [946 {$delete: 'e'},947 {$merge: {f: 5, g: 6}},948 {h: 7}949 ]950 }951 })952 util.isMatch(object, {953 a: 1,954 b: 2,955 c: {956 h: 7957 }958 })959 assert.ok(_.isNil(object.c.d))960 assert.ok(_.isNil(object.c.e))961 assert.ok(_.isNil(object.c.f))962 assert.ok(_.isNil(object.c.g))963 }964 }),965 util.makeTest({966 name: 'PropertyPathMultiOpTest',967 doTest: function() {968 let _prototype = {969 a: 1,970 b: 2,971 c: {972 d: {973 e: 3,974 f: 4975 }976 }977 }978 let object = o({979 _type: _prototype,...
ConstChecker.js
Source:ConstChecker.js
...17import {CollectingErrorReporter as ErrorReporter} from '../../../src/util/CollectingErrorReporter.js';18import {validate as validateConst} from '../../../src/semantics/ConstChecker.js';19import {Options} from '../../../src/Options.js';20suite('ConstChecker.js', function() {21 function makeTest(name, code, expectedErrors, mode) {22 test(name, function() {23 var options = new Options();24 options.arrayComprehension = true;25 options.blockBinding = true;26 options.generatorComprehension = true;27 var reporter = new ErrorReporter();28 var parser =29 new Parser(new SourceFile('SOURCE', code), reporter, options);30 var tree = mode === 'script' ?31 parser.parseScript() : parser.parseModule();32 assert.deepEqual(reporter.errors, []);33 validateConst(tree, reporter);34 assert.deepEqual(reporter.errors, expectedErrors);35 });36 }37 makeTest('var', 'var x = 1; x += 1;', []);38 makeTest('const assignment', 'const x = 1; x &= 1;',39 ['SOURCE:1:14: x is read-only']);40 makeTest('const assignment', 'const x = 1; x |= 1;',41 ['SOURCE:1:14: x is read-only']);42 makeTest('const assignment', 'const x = 1; x ^= 1;',43 ['SOURCE:1:14: x is read-only']);44 makeTest('const assignment', 'const x = 1; x = 1;',45 ['SOURCE:1:14: x is read-only']);46 makeTest('const assignment', 'const x = 1; x <<= 1;',47 ['SOURCE:1:14: x is read-only']);48 makeTest('const assignment', 'const x = 1; x -= 1;',49 ['SOURCE:1:14: x is read-only']);50 makeTest('const assignment', 'const x = 1; x %= 1;',51 ['SOURCE:1:14: x is read-only']);52 makeTest('const assignment', 'const x = 1; x += 1;',53 ['SOURCE:1:14: x is read-only']);54 makeTest('const assignment', 'const x = 1; x >>= 1;',55 ['SOURCE:1:14: x is read-only']);56 makeTest('const assignment', 'const x = 1; x /= 1;',57 ['SOURCE:1:14: x is read-only']);58 makeTest('const assignment', 'const x = 1; x *= 1;',59 ['SOURCE:1:14: x is read-only']);60 makeTest('const assignment', 'const x = 1; x >>>= 1;',61 ['SOURCE:1:14: x is read-only']);62 makeTest('const prefix', 'const x = 1; ++x;', ['SOURCE:1:16: x is read-only']);63 makeTest('const prefix', 'const x = 1; --x;', ['SOURCE:1:16: x is read-only']);64 makeTest('const postfix', 'const x = 1; x++;', ['SOURCE:1:14: x is read-only']);65 makeTest('const postfix', 'const x = 1; x--;', ['SOURCE:1:14: x is read-only']);66 makeTest('function expression', '(function f() {\nf = 2;})',67 ['SOURCE:2:1: f is read-only']);68 makeTest('function declaration', 'function f() {\nf = 2;}', []);69 makeTest('import', 'import {x} from "abc";\nx = 1;',70 ['SOURCE:2:1: x is read-only']);71 makeTest('import', 'import {x, y} from "abc";\ny = 1;',72 ['SOURCE:2:1: y is read-only']);73 makeTest('import', 'import {x as z, y} from "abc";\nz = 1;',74 ['SOURCE:2:1: z is read-only']);75 makeTest('import default', 'import x from "abc";\nx = 1;',76 ['SOURCE:2:1: x is read-only']);77 makeTest('function params',78 'const x = 1;\n' +79 'function f(x) {\n' +80 ' x = 2;\n' +81 '}', []);82 makeTest('function params',83 'const x = 1;\n' +84 'function f({x}) {\n' +85 ' x = 2;\n' +86 '}', []);87 makeTest('function params',88 'const x = 1;\n' +89 'function f(y) {\n' +90 ' x = 2;\n' +91 '}', ['SOURCE:3:3: x is read-only']);92 makeTest('function params',93 'const x = 1;\n' +94 'function f(y = (x = 2)) {}',95 ['SOURCE:2:17: x is read-only']);96 makeTest('assign in initializer', 'const x = 1;\nvar y = (x = 2);',97 ['SOURCE:2:10: x is read-only']);98 makeTest('let',99 'const x = 1;\n' +100 '{\n' +101 ' let x;\n' +102 ' x = 2;\n' +103 '}', []);104 makeTest('let',105 'const x = 1;\n' +106 '{\n' +107 ' let y;\n' +108 ' x = 2;\n' +109 '}', ['SOURCE:4:3: x is read-only']);110 makeTest('let',111 'const x = 1;\n' +112 '{\n' +113 ' const x = 2;\n' +114 '}', []);115 makeTest('let',116 'let x;\n' +117 '{\n' +118 ' const x = 1;\n' +119 '}\n' +120 'x = 2;', []);121 makeTest('function expression and let',122 '(function f() { { let f = 1 } })', []);123 makeTest('function expression and let',124 '(function f() { { let f = 1 } f = 2; })',125 ['SOURCE:1:31: f is read-only']);126 makeTest('arrow', 'x => { x = 1 }', []);127 makeTest('arrow', '(x) => { x = 1 }', []);128 makeTest('class declaration',129 'const x = 1;\n' +130 '{\n'+131 ' class x {}\n' +132 ' x = 2;\n' +133 '}',134 []);135 makeTest('class declaration',136 'var m;\n' +137 'class C { m() { m = 2; } }',138 []);139 makeTest('class declaration',140 'class C {\n' +141 ' m() {\n' +142 ' C = 2;\n' +143 ' }\n' +144 '}',145 ['SOURCE:3:5: C is read-only']);146 makeTest('class expression',147 'const x = 1;\n' +148 '{\n'+149 ' (class x {})\n' +150 ' x = 2;\n' +151 '}',152 ['SOURCE:4:3: x is read-only']);153 makeTest('class expression',154 'var m;\n' +155 '(class C { m() { m = 2; } })',156 []);157 makeTest('class expression',158 '(class C {\n' +159 ' m() {\n' +160 ' C = 2;\n' +161 ' }\n' +162 '})',163 ['SOURCE:3:5: C is read-only']);164 makeTest('Duplicate declarations', 'let x; let x;',165 ['SOURCE:1:12: Duplicate declaration, x']);166 makeTest('Duplicate declarations', 'let x; const x = 1;',167 ['SOURCE:1:14: Duplicate declaration, x']);168 makeTest('Duplicate declarations', 'const x = 1; const x = 2;',169 ['SOURCE:1:20: Duplicate declaration, x']);170 makeTest('Duplicate declarations', 'const x = 1; let x;',171 ['SOURCE:1:18: Duplicate declaration, x']);172 makeTest('Duplicate declarations', 'var x; let x;',173 ['SOURCE:1:12: Duplicate declaration, x']);174 makeTest('Duplicate declarations', 'var x; var x;', []);175 makeTest('Duplicate declarations',176 'let x;\n' +177 '{\n' +178 ' var x;\n' +179 '}',180 ['SOURCE:3:7: Duplicate declaration, x']);181 makeTest('let bound function declaration',182 'const x = 1;\n' +183 '{\n' +184 ' function x() {}\n' +185 '}',186 []);187 makeTest('sloppy functions',188 'let x = 1;\n' +189 '{\n' +190 ' function x() {}\n' +191 '}',192 ['SOURCE:3:12: Duplicate declaration, x'],193 'script');194 makeTest('sloppy functions',195 '{\n' +196 ' let x = 1;\n' +197 ' function x() {}\n' +198 '}',199 ['SOURCE:3:12: Duplicate declaration, x'],200 'script');201 makeTest('sloppy functions',202 '{\n' +203 ' function x() {}\n' +204 '}\n' +205 'let x = 1;',206 ['SOURCE:4:5: Duplicate declaration, x'],207 'script');208 makeTest('catch var',209 'try {\n' +210 '} catch (ex) {\n' +211 ' let ex;\n' +212 '}',213 ['SOURCE:3:7: Duplicate declaration, ex']);214 makeTest('catch var',215 'try {\n' +216 '} catch (ex) {\n' +217 '}\n' +218 'let ex;',219 []);220 makeTest('catch var',221 'const ex = 1;\n' +222 'try {\n' +223 '} catch (ex) {\n' +224 ' ex = 2;\n' +225 '}',226 []);227 makeTest('for of loop',228 '{\n' +229 ' let x = 1;\n' +230 ' for (let x of iterable) {\n' +231 ' x;\n' +232 ' }\n' +233 '}',234 []);235 makeTest('for of loop',236 '{\n' +237 ' let x = 1;\n' +238 ' for (let x of iterable) {\n' +239 ' let x;\n' +240 ' }\n' +241 '}',242 []);243 makeTest('for of loop',244 '{\n' +245 ' const x = 1;\n' +246 ' for (const x of iterable) {\n' +247 ' const x = 2;\n' +248 ' }\n' +249 '}',250 []);251 makeTest('for of loop',252 '{\n' +253 ' for (const x of iterable) {\n' +254 ' x = 1;\n' +255 ' }\n' +256 '}',257 ['SOURCE:3:5: x is read-only']);258 makeTest('for in loop',259 '{\n' +260 ' let x = 1;\n' +261 ' for (let x in iterable) {\n' +262 ' x;\n' +263 ' }\n' +264 '}',265 []);266 makeTest('for in loop',267 '{\n' +268 ' let x = 1;\n' +269 ' for (let x in iterable) {\n' +270 ' let x;\n' +271 ' }\n' +272 '}',273 []);274 makeTest('for in loop',275 '{\n' +276 ' const x = 1;\n' +277 ' for (const x in iterable) {\n' +278 ' const x = 2;\n' +279 ' }\n' +280 '}',281 []);282 makeTest('for in loop',283 '{\n' +284 ' for (const x in iterable) {\n' +285 ' x = 1;\n' +286 ' }\n' +287 '}',288 ['SOURCE:3:5: x is read-only']);289 makeTest('for loop',290 '{\n' +291 ' let x = 1;\n' +292 ' for (let x = 2; ;) {\n' +293 ' x;\n' +294 ' }\n' +295 '}',296 []);297 makeTest('for loop',298 '{\n' +299 ' let x = 1;\n' +300 ' for (let x; ;) {\n' +301 ' let x;\n' +302 ' }\n' +303 '}',304 []);305 makeTest('for loop',306 '{\n' +307 ' const x = 1;\n' +308 ' for (const x = 2; ; ) {\n' +309 ' const x = 3;\n' +310 ' }\n' +311 '}',312 []);313 makeTest('for loop',314 '{\n' +315 ' for (const x = 1; ; ) {\n' +316 ' x = 2;\n' +317 ' }\n' +318 '}',319 ['SOURCE:3:5: x is read-only']);320 makeTest('for loop', 'for (;;) {}', []);321 makeTest('Array comprehension',322 'let x;\n' +323 '[for (x of []) x]',324 []);325 makeTest('Array comprehension',326 'let x;\n' +327 '[for (x of []) for (x of []) x]',328 []);329 makeTest('Array comprehension',330 'const x = 1;\n' +331 '[for (x of []) x]',332 []);333 makeTest('Array comprehension',334 'const x = 1;\n' +335 '[for (y of (x = [])) x]',336 ['SOURCE:2:13: x is read-only']);337 makeTest('Array comprehension',338 'const x = 1;\n' +339 '[for (y of []) x = 2]',340 ['SOURCE:2:16: x is read-only']);341 makeTest('Generator comprehension',342 'let x;\n' +343 '(for (x of []) x)',344 []);345 makeTest('Generator comprehension',346 'let x;\n' +347 '(for (x of []) for (x of []) x)',348 []);349 makeTest('Generator comprehension',350 'const x = 1;\n' +351 '(for (x of []) x)',352 []);353 makeTest('Generator comprehension',354 'const x = 1;\n' +355 '(for (y of (x = [])) x)',356 ['SOURCE:2:13: x is read-only']);357 makeTest('Generator comprehension',358 'const x = 1;\n' +359 '(for (y of []) x = 2)',360 ['SOURCE:2:16: x is read-only']);361 makeTest('with',362 'with ({}) {\n' +363 ' let x;\n' +364 ' let x;\n' +365 '}',366 ['SOURCE:3:7: Duplicate declaration, x'],367 'script');368 makeTest('with',369 'const x = 1;\n' +370 'with ({}) {\n' +371 ' x = 2;\n' +372 '}',373 [],374 'script');...
FreeVariableChecker.js
Source:FreeVariableChecker.js
...17import {CollectingErrorReporter as ErrorReporter} from '../../../src/util/CollectingErrorReporter.js';18import {validate as validateFreeVars} from '../../../src/semantics/FreeVariableChecker.js';19import {Options} from '../../../src/Options.js';20suite('FreeVariableChecker.js', function() {21 function makeTest(name, code, expectedErrors, global, mode) {22 test(name, function() {23 var options = new Options();24 options.arrayComprehension = true;25 options.blockBinding = true;26 options.generatorComprehension = true;27 var reporter = new ErrorReporter();28 var parser = new Parser(new SourceFile('CODE', code), reporter, options);29 var tree = mode === 'module' ?30 parser.parseModule() : parser.parseScript();31 assert.deepEqual(reporter.errors, []);32 // Make sure we use a global that has not been polluted.33 validateFreeVars(tree, reporter, global || Object.create(null));34 assert.deepEqual(reporter.errors, expectedErrors);35 });36 }37 makeTest('basic', 'x', ['CODE:1:1: x is not defined']);38 makeTest('basic binop', 'x + 1', ['CODE:1:1: x is not defined']);39 makeTest('basic assign', 'x = 1', ['CODE:1:1: x is not defined']);40 makeTest('basic member', 'x.y', ['CODE:1:1: x is not defined']);41 makeTest('basic lookup', 'x[0]', ['CODE:1:1: x is not defined']);42 makeTest('basic unary', '++x', ['CODE:1:3: x is not defined']);43 makeTest('basic postfix', 'x++', ['CODE:1:1: x is not defined']);44 makeTest('basic call', 'x(1, 2)', ['CODE:1:1: x is not defined']);45 makeTest('basic new ', 'new x(1, 2)', ['CODE:1:5: x is not defined']);46 makeTest('var', 'var y = x', ['CODE:1:9: x is not defined']);47 makeTest('let', 'let y = x', ['CODE:1:9: x is not defined']);48 makeTest('const', 'const y = x', ['CODE:1:11: x is not defined']);49 makeTest('globals', 'x', [], {x: 1});50 makeTest('call args', 'f(x, 2);', ['CODE:1:3: x is not defined'], {f: 1});51 makeTest('new args', 'new f(x, 2);', ['CODE:1:7: x is not defined'], {f: 1});52 makeTest('nested function', 'function f() { x }',53 ['CODE:1:16: x is not defined']);54 makeTest('nested function', 'function f() { f }', []);55 makeTest('nested function expression', '(function f() { x })',56 ['CODE:1:17: x is not defined']);57 makeTest('nested function expression', '(function f() { f })', []);58 makeTest('nested class', 'class f { m() { x } }',59 ['CODE:1:17: x is not defined']);60 makeTest('nested class', 'class f { m() { f } }', []);61 makeTest('nested class', 'class f { m() { m } }',62 ['CODE:1:17: m is not defined']);63 makeTest('nested class expression', '(class f { m() { x } })',64 ['CODE:1:18: x is not defined']);65 makeTest('nested class expression', '(class f { m() { f } })', []);66 makeTest('nested class expression', '(class f { m() { m } })',67 ['CODE:1:18: m is not defined']);68 makeTest('arrow function', '() => x', ['CODE:1:7: x is not defined']);69 makeTest('arrow function', 'x => x', []);70 makeTest('arrow function', 'function f() { f }', []);71 makeTest('arrow function', '() => arguments',72 ['CODE:1:7: arguments is not defined']);73 makeTest('arrow function', '() => { arguments }',74 ['CODE:1:9: arguments is not defined']);75 makeTest('arrow function', '() => 1; function f() { arguments }', []);76 makeTest('arrow function', '(x = function() { arguments }) => 42', []);77 makeTest('if', 'if (true) { x; }', ['CODE:1:13: x is not defined']);78 makeTest('if', 'if (true) {} else { x; }', ['CODE:1:21: x is not defined']);79 makeTest('block let', '{ let x = 5; } x', ['CODE:1:16: x is not defined']);80 makeTest('block const', '{ const x = 5; } x',81 ['CODE:1:18: x is not defined']);82 makeTest('block let', '{ var x = 5; } x', []);83 makeTest('block function', '{ function f() {} } f', []);84 makeTest('block function', '"use strict"; { function f() {} } f',85 ['CODE:1:35: f is not defined']);86 makeTest('module', 'import {x} from "x"; x', [], undefined, 'module');87 makeTest('module', 'import x from "x"; x', [], undefined, 'module');88 makeTest('module', 'import * as x from "x"; x', [], undefined, 'module');89 makeTest('module', 'import {y as x} from "x"; x', [], undefined, 'module');90 makeTest('module', 'import {x as y} from "x"; x',91 ['CODE:1:27: x is not defined'], undefined, 'module');92 makeTest('module magic name', '__moduleName', [], undefined, 'module');93 makeTest('array comprehension', '[for (x of []) x]', []);94 makeTest('array comprehension', '[for (y of []) x]',95 ['CODE:1:16: x is not defined']);96 makeTest('generator comprehension', '(for (x of []) x)', []);97 makeTest('generator comprehension', '(for (y of []) x)',98 ['CODE:1:16: x is not defined']);99 makeTest('spread', 'var x = [1, 2]; var y = [0, ...x, 3]', []);100 makeTest('getter',101 '({\n' +102 ' get p() { return x; }\n' +103 '})',104 ['CODE:2:20: x is not defined']);105 makeTest('getter',106 '({\n' +107 ' get x() { return x; }\n' +108 '})',109 ['CODE:2:20: x is not defined']);110 makeTest('setter',111 '({\n' +112 ' set p(_) { x; }\n' +113 '})',114 ['CODE:2:14: x is not defined']);115 makeTest('setter',116 '({\n' +117 ' set x(_) { x; }\n' +118 '})',119 ['CODE:2:14: x is not defined']);...
test.js
Source:test.js
...22 str4,23 }24 },25})26function makeTest(obj) {27 var name = JSON.stringify(obj) || 'undefined'28 if (name.length > 100) {29 name = name.slice(0, 97) + '...'30 }31 it(name, function () {32 expect(obj).toMatchParsedOfSelfStringifiedAndSnapshot()33 })34}35describe('URLON', function () {36 describe('Booleans', function () {37 makeTest(true)38 makeTest(false)39 makeTest(null)40 })41 describe('undefined', function () {42 it('stringifies to undefined', function () {43 expect(URLON.stringify(undefined)).toEqual(undefined)44 })45 it('throws to parse', function () {46 expect(function () {47 URLON.parse(undefined)48 }).toThrow()49 })50 })51 describe('Numbers', function () {52 makeTest(1234567890)53 makeTest(0.123456789e-12)54 makeTest(-9876.54321)55 makeTest(23456789012e66)56 makeTest(0)57 makeTest(1)58 makeTest(0.5)59 makeTest(98.6)60 makeTest(99.44)61 makeTest(1066)62 makeTest(1e1)63 makeTest(0.1e1)64 makeTest(1e-1)65 makeTest(1)66 makeTest(2)67 makeTest(2)68 makeTest(-42)69 })70 describe('Strings', function () {71 makeTest('')72 makeTest(';')73 makeTest('@')74 makeTest('/')75 makeTest('|')76 makeTest('&')77 makeTest(' ')78 makeTest('"')79 makeTest('\\')80 makeTest('\b\f\n\r\t')81 makeTest('/ & /')82 makeTest('abcdefghijklmnopqrstuvwyz')83 makeTest('ABCDEFGHIJKLMNOPQRSTUVWYZ')84 makeTest('0123456789')85 makeTest("`1~!@#$%^&*()_+-={':[,]}|;.</>?")86 makeTest('\u0123\u4567\u89AB\uCDEF\uabcd\uef4A')87 makeTest('// /* <!-- --')88 makeTest('# -- --> */')89 makeTest('@:0&@:0&@:0&:0')90 makeTest('{"object with 1 member":["array with 1 element"]}')91 makeTest('" \u0022 %22 0x22 034 "')92 makeTest(93 '/\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?'94 )95 })96 describe('Array', function () {97 makeTest([])98 makeTest([[0]])99 makeTest([[[[[0]]]]])100 makeTest([[[[[0], 0]], 0]])101 makeTest([0, [0, [0, 0]]])102 makeTest([null])103 makeTest([undefined])104 })105 describe('Object', function () {106 makeTest({})107 makeTest({ '': '' })108 makeTest({ a: { b: 1 }, c: 'x' })109 })110 describe('Complex', function () {111 makeTest([{}, {}])112 makeTest({ foo: [2, { bar: [4, { baz: [6, { 'deep enough': 7 }] }] }] })113 makeTest({114 num: 1,115 alpha: 'abc',116 ignore: 'me',117 change: 'to a function',118 toUpper: true,119 obj: { nested_num: 50, undef: undefined, alpha: 'abc', nullable: null },120 arr: [1, 7, 2],121 })122 makeTest([123 'JSON makeTest Pattern pass1',124 { 'object with 1 member': ['array with 1 element'] },125 {},126 [],127 -42,128 true,129 false,130 null,131 {132 integer: 1234567890,133 real: -9876.54321,134 e: 0.123456789e-12,135 E: 1.23456789e34,136 '': 23456789012e66,137 zero: 0,138 one: 1,139 space: ' ',140 quote: '"',141 backslash: '\\',142 controls: '\b\f\n\r\t',143 slash: '/ & /',144 alpha: 'abcdefghijklmnopqrstuvwyz',145 ALPHA: 'ABCDEFGHIJKLMNOPQRSTUVWYZ',146 digit: '0123456789',147 '0123456789': 'digit',148 special: "`1~!@#$%^&*()_+-={':[,]}|;.</>?",149 hex: '\u0123\u4567\u89AB\uCDEF\uabcd\uef4A',150 true: true,151 false: false,152 null: null,153 array: [],154 object: {},155 address: '50 St. James Street',156 url: 'http://www.JSON.org/',157 comment: '// /* <!-- --',158 '# -- --> */': ' ',159 ' s p a c e d ': [1, 2, 3, 4, 5, 6, 7],160 compact: [1, 2, 3, 4, 5, 6, 7],161 jsontext: '{"object with 1 member":["array with 1 element"]}',162 quotes: '" \u0022 %22 0x22 034 "',163 '/\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?':164 'A key can be any string',165 },166 0.5,167 98.6,168 99.44,169 1066,170 1e1,171 0.1e1,172 1e-1,173 1,174 2,175 2,176 'rosebud',177 ])178 makeTest(geojson)179 })...
bindingsInDestructuringPattern.js
Source:bindingsInDestructuringPattern.js
...15import {Parser} from '../../../src/syntax/Parser.js';16import {SourceFile} from '../../../src/syntax/SourceFile.js';17import bindingsInDestructuringPattern from '../../../src/semantics/bindingsInDestructuringPattern.js';18suite('bindingsInDestructuringPattern.js', function() {19 function makeTest(code, names) {20 test(code, function() {21 const parser = new Parser(new SourceFile('CODE', code));22 const tree = parser.parseScript();23 assert.equal(tree.scriptItemList.length, 1);24 const set = bindingsInDestructuringPattern(tree.scriptItemList[0]);25 assert.deepEqual(set.valuesAsArray(), names);26 });27 }28 makeTest('var x', ['x']);29 makeTest('let x = 1', ['x']);30 makeTest('const {x} = {x: 1}', ['x']);31 makeTest('var {x: y} = {x: 1}', ['y']);32 makeTest('let [x] = [1]', ['x']);33 makeTest('const [...x] = [1]', ['x']);34 makeTest('var x, y', ['x', 'y']);35 makeTest('let x = 1, y = 2', ['x', 'y']);36 makeTest('const {x, y} = {x: 1, y: 2}', ['x', 'y']);37 makeTest('var {x, y: y} = {x: 1, y: 2}', ['x', 'y']);38 makeTest('let [x, y] = [1, 2]', ['x', 'y']);39 makeTest('const [x, ...y] = [1]', ['x', 'y']);40 makeTest('var {x: {y}} = {x: {y: 2}}', ['y']);41 makeTest('let {x: {y: y}} = {x: {y: 2}}', ['y']);42 makeTest('const {x: [y]} = {x: [2]}', ['y']);43 makeTest('var {x: [...y]} = {x: [2]}', ['y']);44 makeTest('var {x = function f() { var z; }} = {x: 1}', ['x']);45 makeTest('let {x: x = function f() { var z; }} = {x: 1}', ['x']);46 makeTest('const [x = function f() { var z; }] = [1]', ['x']);47 makeTest('var {x} = {x: function f() { var z; }}', ['x']);...
calculator.js
Source:calculator.js
...8 it(`add(${x},${y}) expected result ${expected} PASS`, ()=>{9 expect.equal(calculator.add(x,y), expected);10 });11 }12 makeTest(5,2)13})14describe("Add", ()=>{15 makeTest = (x,y) =>{16 let expected = x + y;17 it(`add(${x},${y}) expected result 8 Fail`, ()=>{18 expect.equal(calculator.add(x,y), 8);19 });20 }21 makeTest(5,2)22})23describe("sub", ()=>{24 makeTest = (x,y) =>{25 let expected = x - y;26 it(`sub(${x},${y}) expected result ${expected} PASS`, ()=>{27 expect.equal(calculator.sub(x,y), expected);28 });29 }30 makeTest(5,2)31})32describe("sub", ()=>{33 makeTest = (x,y) =>{34 let expected = x - y;35 it(`sub(${x},${y}) expected result 5 Fail`, ()=>{36 expect.equal(calculator.sub(x,y), 8);37 });38 }39 makeTest(5,2)40})41describe("Mul", ()=>{42 makeTest = (x,y) =>{43 let expected = x * y;44 it(`mul(${x},${y}) expected result ${expected} PASS`, ()=>{45 expect.equal(calculator.mul(x,y), expected);46 });47 }48 makeTest(5,2)49})50describe("Mul", ()=>{51 makeTest = (x,y) =>{52 let expected = x * y;53 it(`mul(${x},${y}) expected result 12 Fail`, ()=>{54 expect.equal(calculator.mul(x,y), 8);55 });56 }57 makeTest(5,2)58})59describe("Div", ()=>{60 makeTest = (x,y) =>{61 let expected = x / y;62 it(`div(${x},${y}) expected result ${expected} PASS`, ()=>{63 expect.equal(calculator.div(x,y), expected);64 });65 }66 makeTest(10,2)67})68describe("Div", ()=>{69 makeTest = (x,y) =>{70 let expected = x / y;71 it(`div(${x},${y}) expected result 8 Fail`, ()=>{72 expect.equal(calculator.div(x,y), 2);73 });74 }75 makeTest(10,2)...
vectors.js
Source:vectors.js
...46 })47 })48}49if (process.argv[2]) {50 makeTest(process.argv[2], parseInt(process.argv[3], 10), true)51} else {52 vectors.forEach(function (v, i) {53 makeTest('sha', i)54 makeTest('sha1', i)55 makeTest('sha224', i)56 makeTest('sha256', i)57 makeTest('sha384', i)58 makeTest('sha512', i)59 })...
index.spec.js
Source:index.spec.js
...8 done()9 })10}11describe('human timeout', () => {12 makeTest('1ns', 1e-6)13 makeTest('1us', 0.001)14 makeTest('1µs', 0.001)15 makeTest('1ms', 1)16 makeTest('1s', 1000)17 makeTest('1m', 60000)18 makeTest('1h', 3.6e+6)19 makeTest('1h30m', 3.6e+6 + 30 * 60000)20 makeTest('1.5h', 1.5 * 3.6e+6)...
Using AI Code Generation
1import { makeTest } from 'storybook-test-runner';2import { storiesOf } from '@storybook/react';3import { withKnobs, text } from '@storybook/addon-knobs';4import { action } from '@storybook/addon-actions';5import Button from './button';6const stories = storiesOf('Button', module);7stories.addDecorator(withKnobs);8stories.add('default', () => (9 <Button onClick={action('click')} disabled={false}>10 {text('Label', 'Hello Storybook')}11));12stories.add('disabled', () => <Button disabled={true}>Disabled</Button>);13makeTest(stories, 'Button');14import './test';15import { storiesOf } from '@storybook/react';16import { withKnobs, text } from '@storybook/addon-knobs';17import { action } from '@storybook/addon-actions';18import Button from './button';19const stories = storiesOf('Button', module);20stories.addDecorator(withKnobs);21stories.add('default', () => (22 <Button onClick={action('click')} disabled={false}>23 {text('Label', 'Hello Storybook')}24));25stories.add('disabled', () => <Button disabled={true}>Disabled</Button>);26makeTest(stories, 'Button');27import './test';28import { storiesOf } from '@storybook/react';29import { withKnobs, text } from '@storybook/addon-knobs';30import { action } from '@storybook/addon-actions';31import Button from './button';32const stories = storiesOf('Button', module);33stories.addDecorator(withKnobs);34stories.add('default', () => (35 <Button onClick={action('click')} disabled={false}>36 {text('Label', 'Hello Storybook')}37));38stories.add('disabled', () => <Button disabled={true}>Disabled</Button>);39makeTest(stories, 'Button');40import './test';41import { storiesOf } from '@storybook/react';42import { withKnobs, text } from '@storybook/addon-knobs';43import { action } from '@storybook
Using AI Code Generation
1const { makeTest } = require('storybook-test-runner')2const { storiesOf } = require('@storybook/react')3const stories = storiesOf('My Component', module)4stories.add('Default', () => <MyComponent />)5stories.add('With Props', () => <MyComponent prop1="value" />)6module.exports = makeTest(stories)7const { makeTest } = require('storybook-test-runner')8const { storiesOf } = require('@storybook/react')9const stories = storiesOf('My Component', module)10stories.add('Default', () => <MyComponent />)11stories.add('With Props', () => <MyComponent prop1="value" />)12module.exports = makeTest(stories)13const { makeTest } = require('storybook-test-runner')14const { storiesOf } = require('@storybook/react')15const stories = storiesOf('My Component', module)16stories.add('Default', () => <MyComponent />)17stories.add('With Props', () => <MyComponent prop1="value" />)18module.exports = makeTest(stories)19const { makeTest } = require('storybook-test-runner')20const { storiesOf } = require('@storybook/react')21const stories = storiesOf('My Component', module)22stories.add('Default', () => <MyComponent />)23stories.add('With Props', () => <MyComponent prop1="value" />)24module.exports = makeTest(stories)25const { makeTest } = require('storybook-test-runner')26const { storiesOf } = require('@storybook/react')27const stories = storiesOf('My Component', module)28stories.add('Default', () => <MyComponent />)29stories.add('With Props', () => <MyComponent prop1="value" />)30module.exports = makeTest(stories)31const { makeTest } = require('storybook-test-runner')32const { storiesOf } = require('@storybook/react')33const stories = storiesOf('My Component', module)34stories.add('Default', () => <MyComponent />)35stories.add('With
Using AI Code Generation
1const makeTest = require('storybook-test-runner').makeTest;2const makeTest = require('storybook-test-runner').makeTest;3 {4 {5 props: {6 },7 },8 },9];10const makeTest = require('storybook-test-runner').makeTest;11 {12 {13 props: {14 },15 },16 },17];18const makeTest = require('storybook-test-runner').makeTest;19 {20 {21 props: {22 },23 },24 },25];26const makeTest = require('storybook-test-runner').makeTest;27 {28 {29 props: {30 },31 },32 },33];34const makeTest = require('storybook-test-runner').makeTest;35 {36 {37 props: {38 },39 },40 },41];42const makeTest = require('storybook-test-runner').makeTest;43 {44 {45 props: {46 },
Using AI Code Generation
1const {makeTest} = require('storybook-test-runner');2const {Storybook} = require('storybook-test-runner/storybook');3const {Jest} = require('storybook-test-runner/jest');4module.exports = makeTest({5 storybook: new Storybook({configDir: './.storybook'}),6 jest: new Jest({config: './jest.config.js'}),7});8module.exports = {9};10module.exports = {11 stories: ['../src/**/*.stories.(js|mdx)'],12};13import {addDecorator} from '@storybook/react';14import {withTests} from '@storybook/addon-jest';15import results from '../test-results.json';16addDecorator(17 withTests({18 }),19);20module.exports = async ({config}) => {21 config.module.rules.push({22 loaders: [require.resolve('@storybook/source-loader')],23 });24 return config;25};26import {addons} from '@storybook/addons';27import {themes} from '@storybook/theming';28addons.setConfig({29});30import {addParameters} from '@storybook/react';31import {DocsPage, DocsContainer} from '@storybook/addon-docs/blocks';32addParameters({33 docs: {34 },35});36import {addons} from '@storybook/addons';37import {withTests} from '@storybook/addon-jest';38import results from '../test-results.json';39addons.setConfig({40});41addons.register('addon-jest', api => {42 addons.add('addon-jest/panel', {43 render: ({active, key}) => (44 <AddonPanel active={active} key={key}>45 <Panel api={api} channel={addons.getChannel()} results={results} />
Using AI Code Generation
1import { makeTest } from 'storybook-test-runner';2describe('My component', () => {3 makeTest('My component', {4 tests: {5 'story1': {6 'test1': () => {7 }8 }9 }10 });11});12const { makeTest } = require('storybook-test-runner');13describe('My component', () => {14 makeTest('My component', {15 tests: {16 'story1': {17 'test1': () => {18 }19 }20 }21 });22});23makeTest('My component', {24 tests: {25 'story1': {26 'test1': () => {27 }28 }29 }30});
Using AI Code Generation
1const { makeTest } = require('storybook-test-runner');2const test = makeTest(__dirname);3test('test1', (story) => {4 expect(story).toMatchImageSnapshot();5});6test('test2', (story) => {7 expect(story).toMatchImageSnapshot();8});9test('test3', (story) => {10 expect(story).toMatchImageSnapshot();11});12test('test4', (story) => {13 expect(story).toMatchImageSnapshot();14});15test('test5', (story) => {16 expect(story).toMatchImageSnapshot();17});18test('test6', (story) => {19 expect(story).toMatchImageSnapshot();20});21test('test7', (story) => {22 expect(story).toMatchImageSnapshot();23});24test('test8', (story) => {25 expect(story).toMatchImageSnapshot();26});27test('test9', (story) => {28 expect(story).toMatchImageSnapshot();29});30test('test10', (story) => {31 expect(story).toMatchImageSnapshot();32});33test('test11', (story) => {34 expect(story).toMatchImageSnapshot();35});36test('test12', (story) => {37 expect(story).toMatchImageSnapshot();38});39test('test13', (story) => {40 expect(story).toMatchImageSnapshot();41});42test('test14', (story) => {43 expect(story).toMatchImageSnapshot();44});45test('test15', (story) => {46 expect(story).toMatchImageSnapshot();47});48test('test16', (story) => {49 expect(story).toMatchImageSnapshot();50});51test('test17', (story) => {
Using AI Code Generation
1import makeTest from 'storybook-test-runner'2makeTest({3})4import React from 'react'5import './Checkbox.scss'6const Checkbox = ({ label, children }) => {7 return (8 {label}9 <div className='checkbox__label'>{children}</div>10}11import React from 'react'12import Checkbox from './Checkbox'13const CheckboxGroup = ({ children }) => {14 return (15 {children}16}17import makeTest from 'storybook-test-runner'18makeTest({19})
Using AI Code Generation
1const makeTest = require('storybook-test-runner').makeTest;2makeTest('stories/**/*.js', {3});4const makeTest = require('storybook-test-runner').makeTest;5makeTest('stories/**/*.js', {6});7() => {8);9});10const makeTest = require('storybook-test-runner').makeTest;11makeTest('stories/**/*.js', {12});13const makeTest = require('storybook-test-runner').makeTest;14makeTest('stories/**/*.js', {15});
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!!