How to use testRunner method in Jest

Best JavaScript code snippet using jest

duplicateLocalVariable1.amd.js

Source:duplicateLocalVariable1.amd.js Github

copy

Full Screen

1define(["require", "exports"], function(require, exports) {2 var TestFileDir = ".\\TempTestFiles";34 var TestCase = (function () {5 function TestCase(name, test, errorMessageRegEx) {6 this.name = name;7 this.test = test;8 this.errorMessageRegEx = errorMessageRegEx;9 }10 return TestCase;11 })();12 exports.TestCase = TestCase;13 var TestRunner = (function () {14 function TestRunner() {15 this.tests = [];16 }17 TestRunner.arrayCompare = function (arg1, arg2) {18 return (arg1.every(function (val, index) {19 return val === arg2[index];20 }));21 };2223 TestRunner.prototype.addTest = function (test) {24 this.tests.push(test);25 };26 TestRunner.prototype.run = function () {27 var success = true;28 for (var test in this.tests) {29 var exception = false;30 var testcase = this.tests[test];31 var testResult = false;32 try {33 testResult = testcase.test();34 } catch (e) {35 exception = true;36 testResult = false;37 if (typeof testcase.errorMessageRegEx === "string") {38 if (testcase.errorMessageRegEx === "") {39 testResult = true;40 } else if (e.message) {41 var regex = new RegExp(testcase.errorMessageRegEx);42 testResult = regex.test(e.message);43 }44 }45 if (testResult === false) {46 //console.log(e.message);47 }48 }49 if ((testcase.errorMessageRegEx !== undefined) && !exception) {50 success = false;51 } else if (!testResult) {52 success = false;53 }54 }55 if (success) {56 } else {57 }58 };59 return TestRunner;60 })();61 exports.TestRunner = TestRunner;6263 exports.tests = (function () {64 var testRunner = new TestRunner();6566 // First 3 are for simple harness validation67 testRunner.addTest(new TestCase("Basic test", function () {68 return true;69 }));70 testRunner.addTest(new TestCase("Test for any error", function () {71 throw new Error();72 return false;73 }, ""));74 testRunner.addTest(new TestCase("Test RegEx error message match", function () {75 throw new Error("Should also pass");76 return false;77 }, "Should [also]+ pass"));78 testRunner.addTest(new TestCase("Test array compare true", function () {79 return TestRunner.arrayCompare([1, 2, 3], [1, 2, 3]);80 }));81 testRunner.addTest(new TestCase("Test array compare false", function () {82 return !TestRunner.arrayCompare([3, 2, 3], [1, 2, 3]);83 }));8485 // File detection tests86 testRunner.addTest(new TestCase("Check file exists", function () {87 return FileManager.DirectoryManager.fileExists(TestFileDir + "\\Test.txt");88 }));89 testRunner.addTest(new TestCase("Check file doesn't exist", function () {90 return !FileManager.DirectoryManager.fileExists(TestFileDir + "\\Test2.txt");91 }));9293 // File pattern matching tests94 testRunner.addTest(new TestCase("Check text file match", function () {95 return (FileManager.FileBuffer.isTextFile("C:\\somedir\\readme.txt") && FileManager.FileBuffer.isTextFile("C:\\spaces path\\myapp.str") && FileManager.FileBuffer.isTextFile("C:\\somedir\\code.js"));96 }));97 testRunner.addTest(new TestCase("Check makefile match", function () {98 return FileManager.FileBuffer.isTextFile("C:\\some dir\\makefile");99 }));100 testRunner.addTest(new TestCase("Check binary file doesn't match", function () {101 return (!FileManager.FileBuffer.isTextFile("C:\\somedir\\app.exe") && !FileManager.FileBuffer.isTextFile("C:\\somedir\\my lib.dll"));102 }));103104 // Command-line parameter tests105 testRunner.addTest(new TestCase("Check App defaults", function () {106 var app = new App.App([]);107 return (app.fixLines === false && app.recurse === true && app.lineEndings === "CRLF" && app.matchPattern === undefined && app.rootDirectory === ".\\" && app.encodings[0] === "ascii" && app.encodings[1] === "utf8nobom");108 }));109 testRunner.addTest(new TestCase("Check App params", function () {110 var app = new App.App(["-dir=C:\\test dir", "-lineEndings=LF", "-encodings=utf16be,ascii", "-recurse=false", "-fixlines"]);111 return (app.fixLines === true && app.lineEndings === "LF" && app.recurse === false && app.matchPattern === undefined && app.rootDirectory === "C:\\test dir" && app.encodings[0] === "utf16be" && app.encodings[1] === "ascii" && app.encodings.length === 2);112 }));113114 // File BOM detection tests115 testRunner.addTest(new TestCase("Check encoding detection no BOM", function () {116 var fb = new FileManager.FileBuffer(TestFileDir + "\\noBOM.txt");117 return fb.bom === 'none' && fb.encoding === 'utf8';118 }));119 testRunner.addTest(new TestCase("Check encoding detection UTF8 BOM", function () {120 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");121 return fb.bom === 'utf8' && fb.encoding === 'utf8';122 }));123 testRunner.addTest(new TestCase("Check encoding detection UTF16be BOM", function () {124 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF16BE.txt");125 return fb.bom === 'utf16be' && fb.encoding === 'utf16be';126 }));127 testRunner.addTest(new TestCase("Check encoding detection UTF16le BOM", function () {128 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF16LE.txt");129 return fb.bom === 'utf16le' && fb.encoding === 'utf16le';130 }));131 testRunner.addTest(new TestCase("Check encoding on 1 bytes file", function () {132 var fb = new FileManager.FileBuffer(TestFileDir + "\\1bytefile.txt");133 return fb.bom === 'none' && fb.encoding === 'utf8';134 }));135 testRunner.addTest(new TestCase("Check encoding on 0 bytes file", function () {136 var fb = new FileManager.FileBuffer(TestFileDir + "\\0bytefile.txt");137 return fb.bom === 'none' && fb.encoding === 'utf8';138 }));139140 // UTF8 encoding tests141 testRunner.addTest(new TestCase("Check byte reader", function () {142 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");143 var chars = [];144 for (var i = 0; i < 11; i++) {145 chars.push(fb.readByte());146 }147 return TestRunner.arrayCompare(chars, [0x54, 0xC3, 0xA8, 0xE1, 0xB4, 0xA3, 0xE2, 0x80, 0xA0, 0x0D, 0x0A]);148 }));149150 testRunner.addTest(new TestCase("Check UTF8 decoding", function () {151 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");152 var chars = [];153 for (var i = 0; i < 6; i++) {154 chars.push(fb.readUtf8CodePoint());155 }156 return TestRunner.arrayCompare(chars, [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A]);157 }));158159 testRunner.addTest(new TestCase("Check UTF8 encoding", function () {160 var fb = new FileManager.FileBuffer(20);161 fb.writeUtf8Bom();162 var chars = [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A];163 for (var i in chars) {164 fb.writeUtf8CodePoint(chars[i]);165 }166 fb.index = 0;167 var bytes = [];168 for (var i = 0; i < 14; i++) {169 bytes.push(fb.readByte());170 }171 var expected = [0xEF, 0xBB, 0xBF, 0x54, 0xC3, 0xA8, 0xE1, 0xB4, 0xA3, 0xE2, 0x80, 0xA0, 0x0D, 0x0A];172 return TestRunner.arrayCompare(bytes, expected);173 }));174175 // Test reading and writing files176 testRunner.addTest(new TestCase("Check saving a file", function () {177 var filename = TestFileDir + "\\tmpUTF16LE.txt";178 var fb = new FileManager.FileBuffer(14);179 fb.writeUtf16leBom();180 var chars = [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A];181 chars.forEach(function (val) {182 fb.writeUtf16CodePoint(val, false);183 });184 fb.save(filename);185186 var savedFile = new FileManager.FileBuffer(filename);187 if (savedFile.encoding !== 'utf16le') {188 throw Error("Incorrect encoding");189 }190 var expectedBytes = [0xFF, 0xFE, 0x54, 0x00, 0xE8, 0x00, 0x23, 0x1D, 0x20, 0x20, 0x0D, 0x00, 0x0A, 0x00];191 savedFile.index = 0;192 expectedBytes.forEach(function (val) {193 var byteVal = savedFile.readByte();194 if (byteVal !== val) {195 throw Error("Incorrect byte value");196 }197 });198 return true;199 }));200201 testRunner.addTest(new TestCase("Check reading past buffer asserts", function () {202 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");203 var result = fb.readByte(200);204 return true;205 }, "read beyond buffer length"));206 testRunner.addTest(new TestCase("Check writing past buffer asserts", function () {207 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");208 fb.writeByte(5, 200);209 return true;210 }, "write beyond buffer length"));211212 // Non-BMP unicode char tests213 testRunner.addTest(new TestCase("Read non-BMP utf16 chars", function () {214 var savedFile = new FileManager.FileBuffer(TestFileDir + "\\utf16leNonBmp.txt");215 if (savedFile.encoding !== 'utf16le') {216 throw Error("Incorrect encoding");217 }218219 var codePoints = [];220 for (var i = 0; i < 6; i++) {221 codePoints.push(savedFile.readUtf16CodePoint(false));222 }223 var expectedCodePoints = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];224 return TestRunner.arrayCompare(codePoints, expectedCodePoints);225 }));226227 testRunner.addTest(new TestCase("Read non-BMP utf8 chars", function () {228 var savedFile = new FileManager.FileBuffer(TestFileDir + "\\utf8NonBmp.txt");229 if (savedFile.encoding !== 'utf8') {230 throw Error("Incorrect encoding");231 }232233 var codePoints = [];234 for (var i = 0; i < 6; i++) {235 codePoints.push(savedFile.readUtf8CodePoint());236 }237 var expectedCodePoints = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];238 return TestRunner.arrayCompare(codePoints, expectedCodePoints);239 }));240241 testRunner.addTest(new TestCase("Write non-BMP utf8 chars", function () {242 var filename = TestFileDir + "\\tmpUTF8nonBmp.txt";243 var fb = new FileManager.FileBuffer(15);244 var chars = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];245 chars.forEach(function (val) {246 fb.writeUtf8CodePoint(val);247 });248 fb.save(filename);249250 var savedFile = new FileManager.FileBuffer(filename);251 if (savedFile.encoding !== 'utf8') {252 throw Error("Incorrect encoding");253 }254 var expectedBytes = [0xF0, 0x90, 0x92, 0x80, 0xF0, 0x90, 0x92, 0x81, 0xF0, 0x90, 0x92, 0x82, 0x54, 0x68, 0x69];255 expectedBytes.forEach(function (val) {256 var byteVal = savedFile.readByte();257 if (byteVal !== val) {258 throw Error("Incorrect byte value");259 }260 });261 return true;262 }));263264 testRunner.addTest(new TestCase("Test invalid lead UTF8 byte", function () {265 var filename = TestFileDir + "\\utf8BadLeadByte.txt";266 var fb = new FileManager.FileBuffer(filename);267 return true;268 }, "Invalid UTF8 byte sequence at index: 4"));269270 testRunner.addTest(new TestCase("Test invalid tail UTF8 byte", function () {271 var filename = TestFileDir + "\\utf8InvalidTail.txt";272 var fb = new FileManager.FileBuffer(filename);273 return true;274 }, "Trailing byte invalid at index: 8"));275276 testRunner.addTest(new TestCase("Test ANSI fails validation", function () {277 var filename = TestFileDir + "\\ansi.txt";278 var fb = new FileManager.FileBuffer(filename);279 return true;280 }, "Trailing byte invalid at index: 6"));281282 testRunner.addTest(new TestCase("Test UTF-16LE with invalid surrogate trail fails", function () {283 var filename = TestFileDir + "\\utf16leInvalidSurrogate.txt";284 var fb = new FileManager.FileBuffer(filename);285 return true;286 }, "Trail surrogate has an invalid value"));287288 testRunner.addTest(new TestCase("Test UTF-16BE with invalid surrogate head fails", function () {289 var filename = TestFileDir + "\\UTF16BEInvalidSurrogate.txt";290 var fb = new FileManager.FileBuffer(filename);291 return true;292 }, "Byte sequence starts with a trail surrogate"));293294 testRunner.addTest(new TestCase("Test UTF-16LE with missing trail surrogate fails", function () {295 var filename = TestFileDir + "\\utf16leMissingTrailSurrogate.txt";296 var fb = new FileManager.FileBuffer(filename);297 return true;298 }, "Trail surrogate has an invalid value"));299300 // Count of CRs & LFs301 testRunner.addTest(new TestCase("Count character occurrences", function () {302 var filename = TestFileDir + "\\charCountASCII.txt";303 var fb = new FileManager.FileBuffer(filename);304 var result = (fb.countCR === 5 && fb.countLF === 4 && fb.countCRLF === 5 && fb.countHT === 3);305 return result;306 }));307308 // Control characters in text309 testRunner.addTest(new TestCase("Test file with control character", function () {310 var filename = TestFileDir + "\\controlChar.txt";311 var fb = new FileManager.FileBuffer(filename);312 return true;313 }, "Codepoint at index: 3 has control value: 8"));314315 return testRunner;316 })(); ...

Full Screen

Full Screen

duplicateLocalVariable1.commonjs.js

Source:duplicateLocalVariable1.commonjs.js Github

copy

Full Screen

1var TestFileDir = ".\\TempTestFiles";23var TestCase = (function () {4 function TestCase(name, test, errorMessageRegEx) {5 this.name = name;6 this.test = test;7 this.errorMessageRegEx = errorMessageRegEx;8 }9 return TestCase;10})();11exports.TestCase = TestCase;12var TestRunner = (function () {13 function TestRunner() {14 this.tests = [];15 }16 TestRunner.arrayCompare = function (arg1, arg2) {17 return (arg1.every(function (val, index) {18 return val === arg2[index];19 }));20 };2122 TestRunner.prototype.addTest = function (test) {23 this.tests.push(test);24 };25 TestRunner.prototype.run = function () {26 var success = true;27 for (var test in this.tests) {28 var exception = false;29 var testcase = this.tests[test];30 var testResult = false;31 try {32 testResult = testcase.test();33 } catch (e) {34 exception = true;35 testResult = false;36 if (typeof testcase.errorMessageRegEx === "string") {37 if (testcase.errorMessageRegEx === "") {38 testResult = true;39 } else if (e.message) {40 var regex = new RegExp(testcase.errorMessageRegEx);41 testResult = regex.test(e.message);42 }43 }44 if (testResult === false) {45 //console.log(e.message);46 }47 }48 if ((testcase.errorMessageRegEx !== undefined) && !exception) {49 success = false;50 } else if (!testResult) {51 success = false;52 }53 }54 if (success) {55 } else {56 }57 };58 return TestRunner;59})();60exports.TestRunner = TestRunner;6162exports.tests = (function () {63 var testRunner = new TestRunner();6465 // First 3 are for simple harness validation66 testRunner.addTest(new TestCase("Basic test", function () {67 return true;68 }));69 testRunner.addTest(new TestCase("Test for any error", function () {70 throw new Error();71 return false;72 }, ""));73 testRunner.addTest(new TestCase("Test RegEx error message match", function () {74 throw new Error("Should also pass");75 return false;76 }, "Should [also]+ pass"));77 testRunner.addTest(new TestCase("Test array compare true", function () {78 return TestRunner.arrayCompare([1, 2, 3], [1, 2, 3]);79 }));80 testRunner.addTest(new TestCase("Test array compare false", function () {81 return !TestRunner.arrayCompare([3, 2, 3], [1, 2, 3]);82 }));8384 // File detection tests85 testRunner.addTest(new TestCase("Check file exists", function () {86 return FileManager.DirectoryManager.fileExists(TestFileDir + "\\Test.txt");87 }));88 testRunner.addTest(new TestCase("Check file doesn't exist", function () {89 return !FileManager.DirectoryManager.fileExists(TestFileDir + "\\Test2.txt");90 }));9192 // File pattern matching tests93 testRunner.addTest(new TestCase("Check text file match", function () {94 return (FileManager.FileBuffer.isTextFile("C:\\somedir\\readme.txt") && FileManager.FileBuffer.isTextFile("C:\\spaces path\\myapp.str") && FileManager.FileBuffer.isTextFile("C:\\somedir\\code.js"));95 }));96 testRunner.addTest(new TestCase("Check makefile match", function () {97 return FileManager.FileBuffer.isTextFile("C:\\some dir\\makefile");98 }));99 testRunner.addTest(new TestCase("Check binary file doesn't match", function () {100 return (!FileManager.FileBuffer.isTextFile("C:\\somedir\\app.exe") && !FileManager.FileBuffer.isTextFile("C:\\somedir\\my lib.dll"));101 }));102103 // Command-line parameter tests104 testRunner.addTest(new TestCase("Check App defaults", function () {105 var app = new App.App([]);106 return (app.fixLines === false && app.recurse === true && app.lineEndings === "CRLF" && app.matchPattern === undefined && app.rootDirectory === ".\\" && app.encodings[0] === "ascii" && app.encodings[1] === "utf8nobom");107 }));108 testRunner.addTest(new TestCase("Check App params", function () {109 var app = new App.App(["-dir=C:\\test dir", "-lineEndings=LF", "-encodings=utf16be,ascii", "-recurse=false", "-fixlines"]);110 return (app.fixLines === true && app.lineEndings === "LF" && app.recurse === false && app.matchPattern === undefined && app.rootDirectory === "C:\\test dir" && app.encodings[0] === "utf16be" && app.encodings[1] === "ascii" && app.encodings.length === 2);111 }));112113 // File BOM detection tests114 testRunner.addTest(new TestCase("Check encoding detection no BOM", function () {115 var fb = new FileManager.FileBuffer(TestFileDir + "\\noBOM.txt");116 return fb.bom === 'none' && fb.encoding === 'utf8';117 }));118 testRunner.addTest(new TestCase("Check encoding detection UTF8 BOM", function () {119 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");120 return fb.bom === 'utf8' && fb.encoding === 'utf8';121 }));122 testRunner.addTest(new TestCase("Check encoding detection UTF16be BOM", function () {123 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF16BE.txt");124 return fb.bom === 'utf16be' && fb.encoding === 'utf16be';125 }));126 testRunner.addTest(new TestCase("Check encoding detection UTF16le BOM", function () {127 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF16LE.txt");128 return fb.bom === 'utf16le' && fb.encoding === 'utf16le';129 }));130 testRunner.addTest(new TestCase("Check encoding on 1 bytes file", function () {131 var fb = new FileManager.FileBuffer(TestFileDir + "\\1bytefile.txt");132 return fb.bom === 'none' && fb.encoding === 'utf8';133 }));134 testRunner.addTest(new TestCase("Check encoding on 0 bytes file", function () {135 var fb = new FileManager.FileBuffer(TestFileDir + "\\0bytefile.txt");136 return fb.bom === 'none' && fb.encoding === 'utf8';137 }));138139 // UTF8 encoding tests140 testRunner.addTest(new TestCase("Check byte reader", function () {141 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");142 var chars = [];143 for (var i = 0; i < 11; i++) {144 chars.push(fb.readByte());145 }146 return TestRunner.arrayCompare(chars, [0x54, 0xC3, 0xA8, 0xE1, 0xB4, 0xA3, 0xE2, 0x80, 0xA0, 0x0D, 0x0A]);147 }));148149 testRunner.addTest(new TestCase("Check UTF8 decoding", function () {150 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");151 var chars = [];152 for (var i = 0; i < 6; i++) {153 chars.push(fb.readUtf8CodePoint());154 }155 return TestRunner.arrayCompare(chars, [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A]);156 }));157158 testRunner.addTest(new TestCase("Check UTF8 encoding", function () {159 var fb = new FileManager.FileBuffer(20);160 fb.writeUtf8Bom();161 var chars = [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A];162 for (var i in chars) {163 fb.writeUtf8CodePoint(chars[i]);164 }165 fb.index = 0;166 var bytes = [];167 for (var i = 0; i < 14; i++) {168 bytes.push(fb.readByte());169 }170 var expected = [0xEF, 0xBB, 0xBF, 0x54, 0xC3, 0xA8, 0xE1, 0xB4, 0xA3, 0xE2, 0x80, 0xA0, 0x0D, 0x0A];171 return TestRunner.arrayCompare(bytes, expected);172 }));173174 // Test reading and writing files175 testRunner.addTest(new TestCase("Check saving a file", function () {176 var filename = TestFileDir + "\\tmpUTF16LE.txt";177 var fb = new FileManager.FileBuffer(14);178 fb.writeUtf16leBom();179 var chars = [0x0054, 0x00E8, 0x1D23, 0x2020, 0x000D, 0x000A];180 chars.forEach(function (val) {181 fb.writeUtf16CodePoint(val, false);182 });183 fb.save(filename);184185 var savedFile = new FileManager.FileBuffer(filename);186 if (savedFile.encoding !== 'utf16le') {187 throw Error("Incorrect encoding");188 }189 var expectedBytes = [0xFF, 0xFE, 0x54, 0x00, 0xE8, 0x00, 0x23, 0x1D, 0x20, 0x20, 0x0D, 0x00, 0x0A, 0x00];190 savedFile.index = 0;191 expectedBytes.forEach(function (val) {192 var byteVal = savedFile.readByte();193 if (byteVal !== val) {194 throw Error("Incorrect byte value");195 }196 });197 return true;198 }));199200 testRunner.addTest(new TestCase("Check reading past buffer asserts", function () {201 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");202 var result = fb.readByte(200);203 return true;204 }, "read beyond buffer length"));205 testRunner.addTest(new TestCase("Check writing past buffer asserts", function () {206 var fb = new FileManager.FileBuffer(TestFileDir + "\\UTF8BOM.txt");207 fb.writeByte(5, 200);208 return true;209 }, "write beyond buffer length"));210211 // Non-BMP unicode char tests212 testRunner.addTest(new TestCase("Read non-BMP utf16 chars", function () {213 var savedFile = new FileManager.FileBuffer(TestFileDir + "\\utf16leNonBmp.txt");214 if (savedFile.encoding !== 'utf16le') {215 throw Error("Incorrect encoding");216 }217218 var codePoints = [];219 for (var i = 0; i < 6; i++) {220 codePoints.push(savedFile.readUtf16CodePoint(false));221 }222 var expectedCodePoints = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];223 return TestRunner.arrayCompare(codePoints, expectedCodePoints);224 }));225226 testRunner.addTest(new TestCase("Read non-BMP utf8 chars", function () {227 var savedFile = new FileManager.FileBuffer(TestFileDir + "\\utf8NonBmp.txt");228 if (savedFile.encoding !== 'utf8') {229 throw Error("Incorrect encoding");230 }231232 var codePoints = [];233 for (var i = 0; i < 6; i++) {234 codePoints.push(savedFile.readUtf8CodePoint());235 }236 var expectedCodePoints = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];237 return TestRunner.arrayCompare(codePoints, expectedCodePoints);238 }));239240 testRunner.addTest(new TestCase("Write non-BMP utf8 chars", function () {241 var filename = TestFileDir + "\\tmpUTF8nonBmp.txt";242 var fb = new FileManager.FileBuffer(15);243 var chars = [0x10480, 0x10481, 0x10482, 0x54, 0x68, 0x69];244 chars.forEach(function (val) {245 fb.writeUtf8CodePoint(val);246 });247 fb.save(filename);248249 var savedFile = new FileManager.FileBuffer(filename);250 if (savedFile.encoding !== 'utf8') {251 throw Error("Incorrect encoding");252 }253 var expectedBytes = [0xF0, 0x90, 0x92, 0x80, 0xF0, 0x90, 0x92, 0x81, 0xF0, 0x90, 0x92, 0x82, 0x54, 0x68, 0x69];254 expectedBytes.forEach(function (val) {255 var byteVal = savedFile.readByte();256 if (byteVal !== val) {257 throw Error("Incorrect byte value");258 }259 });260 return true;261 }));262263 testRunner.addTest(new TestCase("Test invalid lead UTF8 byte", function () {264 var filename = TestFileDir + "\\utf8BadLeadByte.txt";265 var fb = new FileManager.FileBuffer(filename);266 return true;267 }, "Invalid UTF8 byte sequence at index: 4"));268269 testRunner.addTest(new TestCase("Test invalid tail UTF8 byte", function () {270 var filename = TestFileDir + "\\utf8InvalidTail.txt";271 var fb = new FileManager.FileBuffer(filename);272 return true;273 }, "Trailing byte invalid at index: 8"));274275 testRunner.addTest(new TestCase("Test ANSI fails validation", function () {276 var filename = TestFileDir + "\\ansi.txt";277 var fb = new FileManager.FileBuffer(filename);278 return true;279 }, "Trailing byte invalid at index: 6"));280281 testRunner.addTest(new TestCase("Test UTF-16LE with invalid surrogate trail fails", function () {282 var filename = TestFileDir + "\\utf16leInvalidSurrogate.txt";283 var fb = new FileManager.FileBuffer(filename);284 return true;285 }, "Trail surrogate has an invalid value"));286287 testRunner.addTest(new TestCase("Test UTF-16BE with invalid surrogate head fails", function () {288 var filename = TestFileDir + "\\UTF16BEInvalidSurrogate.txt";289 var fb = new FileManager.FileBuffer(filename);290 return true;291 }, "Byte sequence starts with a trail surrogate"));292293 testRunner.addTest(new TestCase("Test UTF-16LE with missing trail surrogate fails", function () {294 var filename = TestFileDir + "\\utf16leMissingTrailSurrogate.txt";295 var fb = new FileManager.FileBuffer(filename);296 return true;297 }, "Trail surrogate has an invalid value"));298299 // Count of CRs & LFs300 testRunner.addTest(new TestCase("Count character occurrences", function () {301 var filename = TestFileDir + "\\charCountASCII.txt";302 var fb = new FileManager.FileBuffer(filename);303 var result = (fb.countCR === 5 && fb.countLF === 4 && fb.countCRLF === 5 && fb.countHT === 3);304 return result;305 }));306307 // Control characters in text308 testRunner.addTest(new TestCase("Test file with control character", function () {309 var filename = TestFileDir + "\\controlChar.txt";310 var fb = new FileManager.FileBuffer(filename);311 return true;312 }, "Codepoint at index: 3 has control value: 8"));313314 return testRunner;315})(); ...

Full Screen

Full Screen

jest-lite.test.js

Source:jest-lite.test.js Github

copy

Full Screen

1import TestRunner, { messages } from './jest-lite';2jest.mock('sandbox-hooks/react-error-overlay/utils/mapper', () => ({3 map: jest.fn(),4}));5jest.mock('codesandbox-api');6const api = require('codesandbox-api');7api.dispatch = jest.fn();8describe('TestRunner class', () => {9 it('exports a module', () => {10 expect(TestRunner).toEqual(expect.any(Function));11 });12 describe('#constructor', () => {13 it('returns a TestRunner instance', () => {14 expect(new TestRunner()).toBeInstanceOf(TestRunner);15 });16 });17 describe('initialize', () => {18 let testRunner;19 beforeEach(() => {20 TestRunner.sendMessage = jest.fn();21 testRunner = new TestRunner();22 });23 it('should be created with 0 test ran', () => {24 expect(testRunner.ranTests.size).toBe(0);25 });26 it('should send message (dispatch) on initilaization', () => {27 expect(api.dispatch).toHaveBeenCalledWith({28 type: 'test',29 event: messages.INITIALIZE,30 });31 });32 });33 describe('getRuntimeGlobals', () => {34 it('returns an object', async () => {35 const testRunner = new TestRunner();36 window.fetch = jest.fn();37 window.localStorage = jest.fn();38 await testRunner.initJSDOM();39 const {40 it: _it,41 test: _test,42 expect: _expect,43 jest: _jest,44 } = testRunner.getRuntimeGlobals();45 expect(_it).toBeInstanceOf(Function);46 expect(_test).toBeInstanceOf(Function);47 expect(_expect).toBeInstanceOf(Function);48 expect(_jest).toBeInstanceOf(Object);49 });50 xdescribe('test', () => {51 let testRunner;52 let _test;53 let fnSpy;54 beforeEach(async () => {55 testRunner = new TestRunner();56 await testRunner.initJSDOM();57 _test = testRunner.getRuntimeGlobals().test;58 fnSpy = jest.fn();59 });60 it('calls the function block', () => {61 expect(fnSpy).toHaveBeenCalled();62 });63 it('adds pass test result', () => {64 _test('foo', () => {});65 expect(testRunner.aggregatedResults.passedTests).toBe(1);66 expect(testRunner.aggregatedResults.failedTests).toBe(0);67 });68 it('adds fail test result', () => {69 _test('foo', () => {70 throw Error();71 });72 expect(testRunner.aggregatedResults.passedTests).toBe(0);73 expect(testRunner.aggregatedResults.failedTests).toBe(1);74 });75 });76 });77 describe('findTests', () => {78 let testRunner;79 beforeEach(() => {80 testRunner = new TestRunner();81 });82 it('should be initialized with no tests', () => {83 expect(testRunner.ranTests.size).toBe(0);84 });85 it('should not find any tests when no modules are passed', () => {86 testRunner.findTests({});87 expect(testRunner.tests).toEqual([]);88 });89 it('should find 1 test when modules are passed', () => {90 testRunner.findTests({ 'Sum.test.js': { path: 'Sum.test.js' } });91 expect(testRunner.tests).toHaveLength(1);92 });93 it('should find 3 of 6 tests when modules are passed', () => {94 testRunner.findTests({95 'Sum.test.js': { path: 'Sum.test.js' },96 'Sum.spec.js': { path: 'Sum.spec.js' },97 '__tests__/Sum.js': { path: '__tests__/Sum.js' },98 'Sum.js': { path: 'Sum.js' },99 'src/Sum.js': { path: 'src/Sum.js' },100 'src/Sum.js1': { path: 'src/Sum.js1' },101 });102 expect(testRunner.tests).toHaveLength(3);103 });104 it('should find 3 of 5 tests when modules are passed', () => {105 testRunner.findTests({106 'Sum.test.ts': { path: 'Sum.test.ts' },107 'Sum.spec.ts': { path: 'Sum.spec.ts' },108 '__tests__/Sum.ts': { path: '__tests__/Sum.ts' },109 'Sum.ts': { path: 'Sum.ts' },110 'src/Sum.ts': { path: 'src/Sum.ts' },111 });112 expect(testRunner.tests).toHaveLength(3);113 });114 it('should find 3 of 5 (typescript) tests when modules are passed', () => {115 testRunner.findTests({116 'Sum.test.tsx': { path: 'Sum.test.tsx' },117 'Sum.spec.tsx': { path: 'Sum.spec.tsx' },118 '__tests__/Sum.tsx': { path: '__tests__/Sum.tsx' },119 'Sum.tsx': { path: 'Sum.tsx' },120 'src/Sum.tsx': { path: 'src/Sum.tsx' },121 });122 expect(testRunner.tests).toHaveLength(3);123 });124 it('should find 3 of 3 tests when modules are passed', () => {125 testRunner.findTests({126 'Sum.test.js': { path: 'Sum.test.js' },127 'Sum.test.ts': { path: 'Sum.test.ts' },128 'Sum.test.tsx': { path: 'Sum.test.tsx' },129 });130 expect(testRunner.tests).toHaveLength(3);131 });132 });133 describe('transpileTests', () => {134 // it('todo');135 });136 describe('runTests', () => {137 // it('todo');138 });139 // deprecated140 xdescribe('addResult', () => {141 let testRunner;142 beforeEach(() => {143 testRunner = new TestRunner();144 });145 it('should add pass test results', () => {146 testRunner.addResult({ status: 'pass', name: 'foo' });147 testRunner.addResult({ status: 'pass', name: 'bar' });148 expect(testRunner.aggregatedResults).toMatchObject({149 failedTestSuites: 0,150 passedTestSuites: 1,151 totalTestSuites: 1,152 failedTests: 0,153 passedTests: 2,154 totalTests: 2,155 });156 });157 it('should add fail test results', () => {158 testRunner.addResult({ status: 'fail', name: 'foo' });159 testRunner.addResult({ status: 'fail', name: 'bar' });160 expect(testRunner.aggregatedResults).toMatchObject({161 failedTestSuites: 1,162 passedTestSuites: 0,163 totalTestSuites: 1,164 failedTests: 2,165 passedTests: 0,166 totalTests: 2,167 });168 });169 it('should add pass & fail test results', () => {170 testRunner.addResult({ status: 'pass', name: 'foo' });171 testRunner.addResult({ status: 'pass', name: 'bar' });172 testRunner.addResult({ status: 'fail', name: 'baz' });173 expect(testRunner.aggregatedResults).toMatchObject({174 failedTestSuites: 1,175 passedTestSuites: 0,176 totalTestSuites: 1,177 failedTests: 1,178 passedTests: 2,179 totalTests: 3,180 });181 });182 it('should add pass & fail test results by suite', () => {183 testRunner.setCurrentPath('a.js');184 testRunner.addResult({ status: 'pass', name: 'foo' });185 testRunner.addResult({ status: 'pass', name: 'bar' });186 testRunner.setCurrentPath('b.js');187 testRunner.addResult({ status: 'fail', name: 'foo' });188 testRunner.addResult({ status: 'fail', name: 'bar' });189 testRunner.setCurrentPath('c.js');190 testRunner.addResult({ status: 'pass', name: 'foo' });191 testRunner.addResult({ status: 'fail', name: 'bar' });192 expect(testRunner.aggregatedResults).toMatchObject({193 failedTestSuites: 2,194 passedTestSuites: 1,195 totalTestSuites: 3,196 failedTests: 3,197 passedTests: 3,198 totalTests: 6,199 });200 });201 });202 // deprecated203 xdescribe('reportResults', () => {204 let testRunner;205 beforeEach(() => {206 testRunner = new TestRunner();207 });208 it('should start off with no tests to report', () => {209 expect(testRunner.reportResults()).toEqual(null);210 });211 it('should report pass tests', () => {212 testRunner.addResult({ status: 'pass', name: 'foo' });213 testRunner.addResult({ status: 'pass', name: 'bar' });214 const results = testRunner.reportResults();215 const { summaryMessage } = results;216 expect(results).not.toEqual(null);217 expect(summaryMessage).toMatch(/Test Summary: 😎/);218 expect(summaryMessage).toMatch(219 /Test Suites: 0 failed, 1 passed, 1 total/220 );221 expect(summaryMessage).toMatch(/Tests: 0 failed, 2 passed, 2 total/);222 });223 it('should report fail tests', () => {224 testRunner.addResult({ status: 'fail', name: 'foo' });225 testRunner.addResult({ status: 'fail', name: 'bar' });226 const results = testRunner.reportResults();227 const { summaryMessage, failedMessages } = results;228 expect(results).not.toEqual(null);229 expect(summaryMessage).toMatch(/Test Summary: 👻/);230 expect(summaryMessage).toMatch(231 /Test Suites: 1 failed, 0 passed, 1 total/232 );233 expect(summaryMessage).toMatch(/Tests: 2 failed, 0 passed, 2 total/);234 expect(failedMessages).toHaveLength(2);235 expect(failedMessages[0]).toMatch(/FAIL/);236 expect(failedMessages[0]).toMatch(/foo/);237 expect(failedMessages[1]).toMatch(/FAIL/);238 expect(failedMessages[1]).toMatch(/bar/);239 });240 it('should add pass & fail test results by suite', () => {241 testRunner.setCurrentPath('a.js');242 testRunner.addResult({ status: 'pass', name: 'foo' });243 testRunner.addResult({ status: 'pass', name: 'bar' });244 testRunner.setCurrentPath('b.js');245 testRunner.addResult({ status: 'fail', name: 'foo' });246 testRunner.addResult({ status: 'fail', name: 'bar' });247 testRunner.setCurrentPath('c.js');248 testRunner.addResult({ status: 'pass', name: 'foo' });249 testRunner.addResult({ status: 'fail', name: 'bar' });250 const results = testRunner.reportResults();251 const { summaryMessage } = results;252 expect(results).not.toEqual(null);253 expect(summaryMessage).toMatch(/Test Summary: 👻/);254 expect(summaryMessage).toMatch(255 /Test Suites: 2 failed, 1 passed, 3 total/256 );257 expect(summaryMessage).toMatch(/Tests: 3 failed, 3 passed, 6 total/);258 });259 it('should report fail tests by describe', () => {260 testRunner.setCurrentDescribe('foo');261 testRunner.addResult({ status: 'fail', name: 'bar' });262 const results = testRunner.reportResults();263 const { failedMessages } = results;264 expect(results).not.toEqual(null);265 expect(failedMessages[0]).toMatch(/FAIL/);266 expect(failedMessages[0]).toMatch(/foo > bar/);267 });268 it('should report fail tests by nested describe', () => {269 testRunner.setCurrentDescribe('foo');270 testRunner.setCurrentDescribe('bar');271 testRunner.addResult({ status: 'fail', name: 'baz' });272 const results = testRunner.reportResults();273 const { failedMessages } = results;274 expect(results).not.toEqual(null);275 expect(failedMessages[0]).toMatch(/FAIL/);276 expect(failedMessages[0]).toMatch(/foo > bar > baz/);277 });278 it('should report pass & fail tests', () => {279 testRunner.addResult({ status: 'pass', name: 'foo' });280 testRunner.addResult({ status: 'pass', name: 'bar' });281 testRunner.addResult({ status: 'fail', name: 'baz' });282 const results = testRunner.reportResults();283 const { summaryMessage } = results;284 expect(results).not.toEqual(null);285 expect(summaryMessage).toMatch(/Test Summary: 👻/);286 expect(summaryMessage).toMatch(287 /Test Suites: 1 failed, 0 passed, 1 total/288 );289 expect(summaryMessage).toMatch(/Tests: 1 failed, 2 passed, 3 total/);290 });291 it('should report pass & fail tests by suite', () => {292 testRunner.setCurrentPath('a.js');293 testRunner.addResult({ status: 'pass', name: 'foo' });294 testRunner.addResult({ status: 'pass', name: 'bar' });295 testRunner.setCurrentPath('b.js');296 testRunner.addResult({ status: 'fail', name: 'foo' });297 testRunner.addResult({ status: 'fail', name: 'bar' });298 testRunner.setCurrentPath('c.js');299 testRunner.addResult({ status: 'pass', name: 'foo' });300 testRunner.addResult({ status: 'fail', name: 'bar' });301 const results = testRunner.reportResults();302 const { summaryMessage } = results;303 expect(results).not.toEqual(null);304 expect(summaryMessage).toMatch(/Test Summary: 👻/);305 expect(summaryMessage).toMatch(306 /Test Suites: 2 failed, 1 passed, 3 total/307 );308 expect(summaryMessage).toMatch(/Tests: 3 failed, 3 passed, 6 total/);309 });310 });...

Full Screen

Full Screen

n1ql_sys_test.js

Source:n1ql_sys_test.js Github

copy

Full Screen

1{2 "name" : "n1ql_2i_test",3 "desc" : "test run for n1ql and 2i",4 "loop" : "",5 "phases" : {6 "0" :7 {8 "name" : "load_tpcc",9 "desc" : "insert data for tpcc buckets",10 "ssh" : {"hosts" : ["10.1.2.80"],11 "username" : "root",12 "password" : "couchbase",13 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 7200 --client 100 --warehouses 100 --client 100 --no-execute --debug n1ql >> /tmp/noload.output&"14 }15 },16 "1" :17 {18 "name" : "load_sabre",19 "desc" : "load data externally",20 "ssh" : {"hosts" : ["10.1.2.80"],21 "username" : "root",22 "password" : "couchbase",23 "command" : "cd /root/n1ql_sysTest/testrunner ; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/insert_query.py -doc 5000000 -q 10.6.2.164"24 }25 },26 "2" :27 {28 "name" : "access_phase",29 "desc" : "run access phase for 10",30 "ssh" : {"hosts" : ["10.1.2.80"],31 "username" : "root",32 "password" : "couchbase",33 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1200 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 1 -q 10.6.2.164&"34 },35 "runtime" : 120036 },37 "3" :38 {39 "name" : "rebalance_in_one",40 "desc" : "RB-1",41 "cluster" : {"add" : "1"},42 "ssh" : {"hosts" : ["10.1.2.80"],43 "username" : "root",44 "password" : "couchbase",45 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"46 }47 },48 "4" :49 {50 "name" : "drain_disks_for_reb",51 "desc" : "drain_disks",52 "workload" : [{"spec" : "g:100,coq:defaultph2keys,ops:1000",53 "conditions" : "post:ep_queue_size < 100000"}54 ]55 },56 "5" :57 {58 "name" : "access_phase",59 "desc" : "run access phase for 10",60 "ssh" : {"hosts" : ["10.1.2.80"],61 "username" : "root",62 "password" : "couchbase",63 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"64 },65 "runtime" : 120066 },67 "6" :68 {69 "name" : "swap_non-orchestrator",70 "desc" : "RB-2",71 "cluster" : {"add": "1", "rm": "1", "orchestrator": "False"}72 },73 "7" :74 {75 "name" : "access_phase",76 "desc" : "run access phase for 10",77 "ssh" : {"hosts" : ["10.1.2.80"],78 "username" : "root",79 "password" : "couchbase",80 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"81 },82 "runtime" : 120083 },84 "8" :85 {86 "name" : "rebalance_out_one",87 "desc" : "RB-1",88 "cluster" : {"rm" : "1", "orchestrator": "False"},89 "ssh" : {"hosts" : ["10.1.2.80"],90 "username" : "root",91 "password" : "couchbase",92 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1000 -c 100 -q 10.6.2.164&"93 }94 },95 "9" :96 {97 "name" : "access_phase",98 "desc" : "run access phase for 10",99 "ssh" : {"hosts" : ["10.1.2.80"],100 "username" : "root",101 "password" : "couchbase",102 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"103 },104 "runtime" : 1200105 },106 "10" :107 { 108 "name" : "failover_one",109 "desc" : "FL-1",110 "cluster" : {"auto_failover" : "1", "add_back": "1"}111 },112 "11" :113 {114 "name" : "access_phase",115 "desc" : "run access phase for 10",116 "ssh" : {"hosts" : ["10.1.2.80"],117 "username" : "root",118 "password" : "couchbase",119 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"120 },121 "runtime" : 1200122 },123 "12" :124 { 125 "name" : "restart_one_no_load",126 "desc" : "CR-1",127 "workload" : [{"spec" : "g:100,coq:defaultph2keys,ops:0",128 "conditions" : {"post": {"conditions": "ep_warmup_thread = complete", "cluster_check": "True"}}}129 ] ,130 "cluster" : {"soft_restart" : "1"}131 },132 "13" :133 {134 "name" : "access_phase",135 "desc" : "run access phase for 10",136 "ssh" : {"hosts" : ["10.1.2.80"],137 "username" : "root",138 "password" : "couchbase",139 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1000 -c 100 -q 10.6.2.164&"140 },141 "runtime" : 1200142 },143 "14" :144 {145 "name" : "restart_one_with_load",146 "desc" : "CR-2",147 "workload" : [{"spec": "s:3,u:22,g:70,d:3,e:2,m:5,ttl:3000,coq:defaultph1keys,ccq:defaultph2keys,ops:15000",148 "conditions" : {"post": {"conditions": "ep_warmup_thread = complete", "cluster_check": "True"}}}],149 "cluster" : {"soft_restart" : "1"}150 },151 "15" :152 {153 "name" : "access_phase",154 "desc" : "run access phase for 10",155 "ssh" : {"hosts" : ["10.1.2.80"],156 "username" : "root",157 "password" : "couchbase",158 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1200 -c 100 -q 10.6.2.164&"159 },160 "runtime" : 1200161 },162 "16" :163 {164 "name" : "restart_all",165 "desc" : "CR-3",166 "workload" : [{"spec" : "g:100,coq:defaultph2keys,ops:0",167 "conditions" : {"post": {"conditions": "ep_warmup_thread = complete", "cluster_check": "True"}}}],168 "cluster" : {"soft_restart" : "8"}169 },170 "17" :171 {172 "name" : "access_phase",173 "desc" : "run access phase for 10",174 "ssh" : {"hosts" : ["10.1.2.80"],175 "username" : "root",176 "password" : "couchbase",177 "command" : "cd ~/details/cwpy ; python ./tpcc.py --duration 1000 --warehouses 100 --client 100 --no-load --debug n1ql&;cd /root/n1ql_sysTest/testrunner; python /root/n1ql_sysTest/testrunner/pysystests/tests/n1ql/dml_sabre.py -t 1000 -c 100 -q 10.6.2.164&"178 },179 "runtime" : 60180 }181 }...

Full Screen

Full Screen

TestRunner.js

Source:TestRunner.js Github

copy

Full Screen

1/**2 * TestRunner: A test runner for SimpleTest3 * TODO:4 * 5 * * Avoid moving iframes: That causes reloads on mozilla and opera.6 *7 *8**/9var TestRunner = {};10TestRunner.logEnabled = false;11TestRunner._iframes = {};12TestRunner._iframeDocuments = {};13TestRunner._iframeRows = {};14TestRunner._currentTest = 0;15TestRunner._urls = [];16TestRunner._testsDiv = DIV();17TestRunner._progressDiv = DIV();18TestRunner._summaryDiv = DIV(null, 19 H1(null, "Tests Summary"),20 TABLE(null, 21 THEAD(null, 22 TR(null,23 TH(null, "Test"), 24 TH(null, "Passed"), 25 TH(null, "Failed")26 )27 ),28 TBODY()29 )30);31/**32 * This function is called after generating the summary.33**/34TestRunner.onComplete = null;35/**36 * If logEnabled is true, this is the logger that will be used.37**/38TestRunner.logger = MochiKit.Logging.logger;39/**40 * Toggle element visibility41**/42TestRunner._toggle = function(el) {43 if (el.className == "noshow") {44 el.className = "";45 el.style.cssText = "";46 } else {47 el.className = "noshow";48 el.style.cssText = "width:0px; height:0px; border:0px;";49 }50};51/**52 * Creates the iframe that contains a test53**/54TestRunner._makeIframe = function (url) {55 var iframe = document.createElement('iframe');56 iframe.src = url;57 iframe.name = url;58 iframe.width = "500";59 var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0];60 var tr = TR(null, TD({'colspan': '3'}, iframe));61 iframe._row = tr;62 tbody.appendChild(tr);63 return iframe;64};65/**66 * TestRunner entry point.67 *68 * The arguments are the URLs of the test to be ran.69 *70**/71TestRunner.runTests = function (/*url...*/) {72 if (TestRunner.logEnabled)73 TestRunner.logger.log("SimpleTest START");74 75 var body = document.getElementsByTagName("body")[0];76 appendChildNodes(body,77 TestRunner._testsDiv,78 TestRunner._progressDiv,79 TestRunner._summaryDiv80 );81 for (var i = 0; i < arguments.length; i++) {82 TestRunner._urls.push(arguments[i]); 83 }84 TestRunner.runNextTest();85};86/**87 * Run the next test. If no test remains, calls makeSummary88**/89TestRunner.runNextTest = function() {90 if (TestRunner._currentTest < TestRunner._urls.length) {91 var url = TestRunner._urls[TestRunner._currentTest];92 var progress = SPAN(null,93 "Running ", A({href:url}, url), "..."94 );95 96 if (TestRunner.logEnabled)97 TestRunner.logger.log(scrapeText(progress));98 99 TestRunner._progressDiv.appendChild(progress);100 TestRunner._iframes[url] = TestRunner._makeIframe(url);101 } else {102 TestRunner.makeSummary();103 if (TestRunner.onComplete)104 TestRunner.onComplete();105 }106};107/**108 * This stub is called by SimpleTest when a test is finished.109**/110TestRunner.testFinished = function (doc) {111 appendChildNodes(TestRunner._progressDiv, SPAN(null, "Done"), BR());112 var finishedURL = TestRunner._urls[TestRunner._currentTest];113 114 if (TestRunner.logEnabled)115 TestRunner.logger.debug("SimpleTest finished " + finishedURL);116 117 TestRunner._iframeDocuments[finishedURL] = doc;118 // TestRunner._iframes[finishedURL].style.display = "none";119 TestRunner._toggle(TestRunner._iframes[finishedURL]);120 TestRunner._currentTest++;121 TestRunner.runNextTest();122};123/**124 * Display the summary in the browser125**/126TestRunner.makeSummary = function() {127 if (TestRunner.logEnabled)128 TestRunner.logger.log("SimpleTest FINISHED");129 var rows = [];130 for (var url in TestRunner._iframeDocuments) {131 var doc = TestRunner._iframeDocuments[url];132 var nOK = withDocument(doc,133 partial(getElementsByTagAndClassName, 'div', 'test_ok')134 ).length;135 var nNotOK = withDocument(doc,136 partial(getElementsByTagAndClassName, 'div', 'test_not_ok')137 ).length;138 var toggle = partial(TestRunner._toggle, TestRunner._iframes[url]);139 var jsurl = "TestRunner._toggle(TestRunner._iframes['" + url + "'])";140 var row = TR(141 {'style': {'backgroundColor': nNotOK > 0 ? "#f00":"#0f0"}}, 142 TD(null, url),143 TD(null, nOK),144 TD(null, nNotOK)145 );146 row.onclick = toggle;147 var tbody = TestRunner._summaryDiv.getElementsByTagName("tbody")[0];148 tbody.insertBefore(row, TestRunner._iframes[url]._row)149 }150};151if ( parent.SimpleTest && parent.runAJAXTest ) {152 TestRunner.makeSummary = function() {153 for (var url in TestRunner._iframeDocuments) {154 var doc = TestRunner._iframeDocuments[url];155 var OK = withDocument(doc, partial(getElementsByTagAndClassName, 'div', 'test_ok'));156 for ( var i = 0; i < OK.length; i++ )157 parent.SimpleTest.ok( true, OK[i].innerHTML );158 var NotOK = withDocument(doc, partial(getElementsByTagAndClassName, 'div', 'test_not_ok'));159 for ( var i = 0; i < NotOK.length; i++ )160 parent.SimpleTest.ok( false, NotOK[i].innerHTML );161 }162 parent.runAJAXTest();163 };...

Full Screen

Full Screen

testrunner_test.js

Source:testrunner_test.js Github

copy

Full Screen

1// Copyright 2017 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.setTestOnly();15goog.require('goog.testing.TestCase');16goog.require('goog.testing.TestRunner');17goog.require('goog.testing.asserts');18goog.require('goog.testing.jsunit');19let testRunner;20let testCase;21function setUp() {22 testRunner = new goog.testing.TestRunner();23 testCase = new goog.testing.TestCase();24}25function testInitialize() {26 assert(!testRunner.isInitialized());27 testRunner.initialize(testCase);28 assert(testRunner.isInitialized());29}30function testIsFinished() {31 testRunner.initialize(testCase);32 // uuid is optional33 assert(!testRunner.isFinished());34 // If provided, uuid is remembered.35 assert(!testRunner.isFinished(1.0));36 // If provided, uuid is checked.37 assert(!testRunner.isFinished(1.0));38 assertThrows(function() {39 testRunner.isFinished(2.0);40 });41}42function testGetUuid() {43 testRunner.getSearchString = () => '?goop';44 assertEquals(testRunner.getUuid(), null);45 testRunner.getSearchString = () => '?uuid=1.0';46 assertEquals(testRunner.getUuid(), 1.0);47 testRunner.getSearchString = () => '?uuid=.1';48 assertEquals(testRunner.getUuid(), .1);49 testRunner.getSearchString = () => '?uuid=.1111';50 assertEquals(testRunner.getUuid(), .1111);51 testRunner.getSearchString = () => '?uuid=.1111&foo=bar';52 assertEquals(testRunner.getUuid(), .1111);53}54function testInitializeUuid() {55 assert(!testRunner.isInitialized());56 testRunner.getSearchString = () => '?uuid=.111';57 testRunner.initialize(testCase);58 // We can poll for isFinished multiple times if the uuid matches.59 assert(!testRunner.isFinished(.111));60 assert(!testRunner.isFinished(.111));61 assertThrows(function() {62 testRunner.isFinished(2.0);63 });...

Full Screen

Full Screen

duplicateLocalVariable2.amd.js

Source:duplicateLocalVariable2.amd.js Github

copy

Full Screen

1define(["require", "exports"], function(require, exports) {2 var TestCase = (function () {3 function TestCase(name, test, errorMessageRegEx) {4 this.name = name;5 this.test = test;6 this.errorMessageRegEx = errorMessageRegEx;7 }8 return TestCase;9 })();10 exports.TestCase = TestCase;11 var TestRunner = (function () {12 function TestRunner() {13 }14 TestRunner.arrayCompare = function (arg1, arg2) {15 return false;16 };1718 TestRunner.prototype.addTest = function (test) {19 };20 return TestRunner;21 })();22 exports.TestRunner = TestRunner;2324 exports.tests = (function () {25 var testRunner = new TestRunner();2627 testRunner.addTest(new TestCase("Check UTF8 encoding", function () {28 var fb;29 fb.writeUtf8Bom();30 var chars = [0x0054];31 for (var i in chars) {32 fb.writeUtf8CodePoint(chars[i]);33 }34 fb.index = 0;35 var bytes = [];36 for (var i = 0; i < 14; i++) {37 bytes.push(fb.readByte());38 }39 var expected = [0xEF];40 return TestRunner.arrayCompare(bytes, expected);41 }));4243 return testRunner;44 })(); ...

Full Screen

Full Screen

duplicateLocalVariable2.commonjs.js

Source:duplicateLocalVariable2.commonjs.js Github

copy

Full Screen

1var TestCase = (function () {2 function TestCase(name, test, errorMessageRegEx) {3 this.name = name;4 this.test = test;5 this.errorMessageRegEx = errorMessageRegEx;6 }7 return TestCase;8})();9exports.TestCase = TestCase;10var TestRunner = (function () {11 function TestRunner() {12 }13 TestRunner.arrayCompare = function (arg1, arg2) {14 return false;15 };1617 TestRunner.prototype.addTest = function (test) {18 };19 return TestRunner;20})();21exports.TestRunner = TestRunner;2223exports.tests = (function () {24 var testRunner = new TestRunner();2526 testRunner.addTest(new TestCase("Check UTF8 encoding", function () {27 var fb;28 fb.writeUtf8Bom();29 var chars = [0x0054];30 for (var i in chars) {31 fb.writeUtf8CodePoint(chars[i]);32 }33 fb.index = 0;34 var bytes = [];35 for (var i = 0; i < 14; i++) {36 bytes.push(fb.readByte());37 }38 var expected = [0xEF];39 return TestRunner.arrayCompare(bytes, expected);40 }));4142 return testRunner;43})(); ...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest 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