Best JavaScript code snippet using stryker-parent
options.spec.js
Source:options.spec.js
1const fs = require('fs');2const path = require('path');3const request = require('supertest');4const server = require('./server');5const clearUploadsDir = server.clearUploadsDir;6const fileDir = server.fileDir;7const uploadDir = server.uploadDir;8describe('File Upload Options Tests', function() {9 afterEach(function(done) {10 clearUploadsDir();11 done();12 });13 /**14 * Upload the file for testing and verify the expected filename.15 * @param {object} options The expressFileUpload options.16 * @param {string} actualFileNameToUpload The name of the file to upload.17 * @param {string} expectedFileNameOnFileSystem The name of the file after upload.18 * @param {function} done The mocha continuation function.19 */20 function executeFileUploadTestWalk(options,21 actualFileNameToUpload,22 expectedFileNameOnFileSystem,23 done) {24 request(server.setup(options))25 .post('/upload/single')26 .attach('testFile', path.join(fileDir, actualFileNameToUpload))27 .expect(200)28 .end(function(err) {29 if (err) {30 return done(err);31 }32 const uploadedFilePath = path.join(uploadDir, expectedFileNameOnFileSystem);33 fs.stat(uploadedFilePath, done);34 });35 }36 describe('Testing [safeFileNames] option to ensure:', function() {37 it('Does nothing to your filename when disabled.',38 function(done) {39 const fileUploadOptions = {safeFileNames: false};40 const actualFileName = 'my$Invalid#fileName.png123';41 const expectedFileName = 'my$Invalid#fileName.png123';42 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);43 });44 it('Is disabled by default.',45 function(done) {46 const fileUploadOptions = null;47 const actualFileName = 'my$Invalid#fileName.png123';48 const expectedFileName = 'my$Invalid#fileName.png123';49 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);50 });51 it('Strips away all non-alphanumeric characters (excluding hyphens/underscores) when enabled.',52 function(done) {53 const fileUploadOptions = {safeFileNames: true};54 const actualFileName = 'my$Invalid#fileName.png123';55 const expectedFileName = 'myInvalidfileNamepng123';56 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);57 });58 it('Accepts a regex for stripping (decidedly) "invalid" characters from filename.',59 function(done) {60 const fileUploadOptions = {safeFileNames: /[$#]/g};61 const actualFileName = 'my$Invalid#fileName.png123';62 const expectedFileName = 'myInvalidfileName.png123';63 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);64 });65 });66 describe('Testing [preserveExtension] option to ensure:', function() {67 it('Does not preserve the extension of your filename when disabled.',68 function(done) {69 const fileUploadOptions = {safeFileNames: true, preserveExtension: false};70 const actualFileName = 'my$Invalid#fileName.png123';71 const expectedFileName = 'myInvalidfileNamepng123';72 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);73 });74 it('Is disabled by default.',75 function(done) {76 const fileUploadOptions = {safeFileNames: true};77 const actualFileName = 'my$Invalid#fileName.png123';78 const expectedFileName = 'myInvalidfileNamepng123';79 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);80 });81 it('Shortens your extension to the default(3) when enabled, if the extension found is larger.',82 function(done) {83 const fileUploadOptions = {safeFileNames: true, preserveExtension: true};84 const actualFileName = 'my$Invalid#fileName.png123';85 const expectedFileName = 'myInvalidfileNamepng.123';86 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);87 });88 it('Leaves your extension alone when enabled, if the extension found is <= default(3) length',89 function(done) {90 const fileUploadOptions = {safeFileNames: true, preserveExtension: true};91 const actualFileName = 'car.png';92 const expectedFileName = 'car.png';93 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);94 });95 it('Can be configured for an extension length > default(3).',96 function(done) {97 const fileUploadOptions = {safeFileNames: true, preserveExtension: 7};98 const actualFileName = 'my$Invalid#fileName.png123';99 const expectedFileName = 'myInvalidfileName.png123';100 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);101 });102 it('Can be configured for an extension length < default(3).',103 function(done) {104 const fileUploadOptions = {safeFileNames: true, preserveExtension: 2};105 const actualFileName = 'my$Invalid#fileName.png123';106 const expectedFileName = 'myInvalidfileNamepng1.23';107 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);108 });109 it('Will use the absolute value of your extension length when negative.',110 function(done) {111 const fileUploadOptions = {safeFileNames: true, preserveExtension: -5};112 const actualFileName = 'my$Invalid#fileName.png123';113 const expectedFileName = 'myInvalidfileNamep.ng123';114 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);115 });116 it('Will leave no extension when the extension length == 0.',117 function(done) {118 const fileUploadOptions = {safeFileNames: true, preserveExtension: 0};119 const actualFileName = 'car.png';120 const expectedFileName = 'car';121 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);122 });123 it('Will accept numbers as strings, if they can be resolved with parseInt.',124 function(done) {125 const fileUploadOptions = {safeFileNames: true, preserveExtension: '3'};126 const actualFileName = 'my$Invalid#fileName.png123';127 const expectedFileName = 'myInvalidfileNamepng.123';128 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);129 });130 it('Will be evaluated for truthy-ness if it cannot be parsed as an int.',131 function(done) {132 const fileUploadOptions = {safeFileNames: true, preserveExtension: 'not-a-#-but-truthy'};133 const actualFileName = 'my$Invalid#fileName.png123';134 const expectedFileName = 'myInvalidfileNamepng.123';135 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);136 });137 it('Will ignore any decimal amount when evaluating for extension length.',138 function(done) {139 const fileUploadOptions = {safeFileNames: true, preserveExtension: 4.98};140 const actualFileName = 'my$Invalid#fileName.png123';141 const expectedFileName = 'myInvalidfileNamepn.g123';142 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);143 });144 it('Only considers the last dotted part as the extension.',145 function(done) {146 const fileUploadOptions = {safeFileNames: true, preserveExtension: true};147 const actualFileName = 'basket.ball.bp';148 const expectedFileName = 'basketball.bp';149 executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done);150 });151 });152 describe('Testing [parseNested] option to ensure:', function() {153 it('When [parseNested] is enabled result are nested', function(done){154 const app = server.setup({parseNested: true});155 request(app)156 .post('/fields/nested')157 .field('name', 'John')158 .field('hobbies[0]', 'Cinema')159 .field('hobbies[1]', 'Bike')160 .expect('Content-Type', /json/)161 .expect(200, {162 name: 'John',163 hobbies: ['Cinema', 'Bike']164 }, done);165 });166 it('When [parseNested] is disabled are flattened', function(done){167 const app = server.setup({parseNested: false});168 request(app)169 .post('/fields/flattened')170 .field('name', 'John')171 .field('hobbies[0]', 'Cinema')172 .field('hobbies[1]', 'Bike')173 .expect('Content-Type', /json/)174 .expect(200, {175 name: 'John',176 'hobbies[0]': 'Cinema',177 'hobbies[1]': 'Bike'178 }, done);179 });180 });...
regress-50447-1.js
Source:regress-50447-1.js
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-2 *3 * ***** BEGIN LICENSE BLOCK *****4 * Version: MPL 1.1/GPL 2.0/LGPL 2.15 *6 * The contents of this file are subject to the Mozilla Public License Version7 * 1.1 (the "License"); you may not use this file except in compliance with8 * the License. You may obtain a copy of the License at9 * http://www.mozilla.org/MPL/10 *11 * Software distributed under the License is distributed on an "AS IS" basis,12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License13 * for the specific language governing rights and limitations under the14 * License.15 *16 * The Original Code is Mozilla Communicator client code, released17 * March 31, 1998.18 *19 * The Initial Developer of the Original Code is20 * Netscape Communications Corporation.21 * Portions created by the Initial Developer are Copyright (C) 199822 * the Initial Developer. All Rights Reserved.23 *24 * Contributor(s):25 * Rob Ginda rginda@netscape.com26 *27 * Alternatively, the contents of this file may be used under the terms of28 * either the GNU General Public License Version 2 or later (the "GPL"), or29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),30 * in which case the provisions of the GPL or the LGPL are applicable instead31 * of those above. If you wish to allow use of your version of this file only32 * under the terms of either the GPL or the LGPL, and not to allow others to33 * use your version of this file under the terms of the MPL, indicate your34 * decision by deleting the provisions above and replace them with the notice35 * and other provisions required by the GPL or the LGPL. If you do not delete36 * the provisions above, a recipient may use your version of this file under37 * the terms of any one of the MPL, the GPL or the LGPL.38 *39 * ***** END LICENSE BLOCK ***** */40/*41 * SUMMARY: New properties fileName, lineNumber have been added to Error objects42 * in SpiderMonkey. These are non-ECMA extensions and do not exist in Rhino.43 *44 * See http://bugzilla.mozilla.org/show_bug.cgi?id=5044745 *46 * 2005-04-05 Modified by bclary to support changes to error reporting47 * which set default values for the error's fileName and48 * lineNumber properties.49 */50//-----------------------------------------------------------------------------51var BUGNUMBER = 50447;52var summary = 'Test (non-ECMA) Error object properties fileName, lineNumber';53//-----------------------------------------------------------------------------54test();55//-----------------------------------------------------------------------------56function test()57{58 enterFunc ('test');59 printBugNumber(BUGNUMBER);60 printStatus (summary);61 testRealError();62 test1();63 test2();64 test3();65 test4();66 exitFunc('test');67}68// Normalize filenames so this test can work on Windows. This 69// function is also used on strings that contain filenames.70function normalize(filename)71{72 // Also convert double-backslash to single-slash to handle73 // escaped filenames in string literals.74 return filename.replace(/\\{1,2}/g, '/');75}76function testRealError()77{78 /* throw a real error, and see what it looks like */79 enterFunc ("testRealError");80 try81 {82 blabla;83 }84 catch (e)85 {86 if (e.fileName.search (/-50447-1\.js$/i) == -1)87 reportCompare('PASS', 'FAIL', "expected fileName to end with '-50447-1.js'");88 reportCompare(94, e.lineNumber,89 "lineNumber property returned unexpected value.");90 }91 exitFunc ("testRealError");92}93function test1()94{95 /* generate an error with msg, file, and lineno properties */96 enterFunc ("test1");97 var e = new InternalError ("msg", "file", 2);98 reportCompare ("(new InternalError(\"msg\", \"file\", 2))",99 e.toSource(),100 "toSource() returned unexpected result.");101 reportCompare ("file", e.fileName,102 "fileName property returned unexpected value.");103 reportCompare (2, e.lineNumber,104 "lineNumber property returned unexpected value.");105 exitFunc ("test1");106}107function test2()108{109 /* generate an error with only msg property */110 enterFunc ("test2");111 /* note this test incorporates the path to the112 test file and assumes the path to the test case113 is a subdirectory of the directory containing jsDriver.pl114 */115 var expectedLine = 148;116 var expectedFileName = 'js1_5/extensions/regress-50447-1.js';117 if (typeof document == "undefined")118 {119 expectedFileName = './' + expectedFileName;120 }121 else122 {123 expectedFileName = document.location.href.124 replace(/[^\/]*(\?.*)$/, '') +125 expectedFileName;126 }127 var e = new InternalError ("msg");128 reportCompare ("(new InternalError(\"msg\", \"" +129 expectedFileName + "\", " + expectedLine + "))",130 normalize(e.toSource()),131 "toSource() returned unexpected result.");132 reportCompare (expectedFileName, normalize(e.fileName),133 "fileName property returned unexpected value.");134 reportCompare (expectedLine, e.lineNumber,135 "lineNumber property returned unexpected value.");136 exitFunc ("test2");137}138function test3()139{140 /* generate an error with only msg and lineNo properties */141 /* note this test incorporates the path to the142 test file and assumes the path to the test case143 is a subdirectory of the directory containing jsDriver.pl144 */145 enterFunc ("test3");146 var expectedFileName = 'js1_5/extensions/regress-50447-1.js';147 if (typeof document == "undefined")148 {149 expectedFileName = './' + expectedFileName;150 }151 else152 {153 expectedFileName = document.location.href.154 replace(/[^\/]*(\?.*)$/, '') +155 expectedFileName;156 }157 var e = new InternalError ("msg");158 e.lineNumber = 10;159 reportCompare ("(new InternalError(\"msg\", \"" +160 expectedFileName + "\", 10))",161 normalize(e.toSource()),162 "toSource() returned unexpected result.");163 reportCompare (expectedFileName, normalize(e.fileName),164 "fileName property returned unexpected value.");165 reportCompare (10, e.lineNumber,166 "lineNumber property returned unexpected value.");167 exitFunc ("test3");168}169function test4()170{171 /* generate an error with only msg and filename properties */172 enterFunc ("test4");173 var expectedLine = 207;174 var e = new InternalError ("msg", "file");175 reportCompare ("(new InternalError(\"msg\", \"file\", " + expectedLine + "))",176 e.toSource(),177 "toSource() returned unexpected result.");178 reportCompare ("file", e.fileName,179 "fileName property returned unexpected value.");180 reportCompare (expectedLine, e.lineNumber,181 "lineNumber property returned unexpected value.");182 exitFunc ("test4");...
Using AI Code Generation
1var expectedFileName = require('stryker-parent').expectedFileName;2var expectedFileName = require('stryker-parent').expectedFileName;3var expectedFileName = require('stryker-parent').expectedFileName;4var expectedFileName = require('stryker-parent').expectedFileName;5var expectedFileName = require('stryker-parent').expectedFileName;6var expectedFileName = require('stryker-parent').expectedFileName;7var expectedFileName = require('stryker-parent').expectedFileName;8var expectedFileName = require('stryker-parent').expectedFileName;9var expectedFileName = require('stryker-parent').expectedFileName;10var expectedFileName = require('stryker-parent').expectedFileName;11var expectedFileName = require('stryker-parent').expectedFileName;12var expectedFileName = require('stryker-parent').expectedFileName;13var expectedFileName = require('stryker-parent').expectedFileName;14var expectedFileName = require('stryker-parent').expectedFileName;15var expectedFileName = require('stryker-parent').expectedFileName;16var expectedFileName = require('stryker-parent').expectedFileName;17var expectedFileName = require('stryker-parent').expectedFileName;18var expectedFileName = require('stryker-parent').expectedFileName;
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const strykerParent = require('stryker-parent');3const strykerParent = require('stryker-parent');4const strykerParent = require('stryker-parent');5const strykerParent = require('stryker-parent');6const strykerParent = require('stryker-parent');7const strykerParent = require('stryker-parent');8const strykerParent = require('stryker-parent');9const strykerParent = require('stryker-parent');10const strykerParent = require('stryker-parent');11console.log(str
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var expectedFileName = strykerParent.expectedFileName;3var strykerParent = require('stryker-parent');4var expectedFileName = strykerParent.expectedFileName;5var strykerParent = require('stryker-parent');6var expectedFileName = strykerParent.expectedFileName;7var strykerParent = require('stryker-parent');8var expectedFileName = strykerParent.expectedFileName;9var strykerParent = require('stryker-parent');10var expectedFileName = strykerParent.expectedFileName;11var strykerParent = require('stryker-parent');12var expectedFileName = strykerParent.expectedFileName;13var strykerParent = require('stryker-parent');14var expectedFileName = strykerParent.expectedFileName;15var strykerParent = require('stryker-parent');16var expectedFileName = strykerParent.expectedFileName;17var strykerParent = require('stryker-parent');18var expectedFileName = strykerParent.expectedFileName;
Using AI Code Generation
1var expectedFileName = require('stryker-parent').expectedFileName;2describe('test', function () {3 it('should do something', function () {4 var fileName = expectedFileName('test.js');5 assert.equal(fileName, 'test.js');6 });7});8var expectedFileName = require('stryker-parent').expectedFileName;9describe('test2', function () {10 it('should do something', function () {11 var fileName = expectedFileName('test2.js');12 assert.equal(fileName, 'test2.js');13 });14});15module.exports = function (config) {16 config.set({17 });18};
Using AI Code Generation
1const expectedFileName = require('stryker-parent').expectedFileName;2const path = require('path');3console.log(expectedFileName(path.join('src', 'test.js')));4const expectedFileName = require('stryker-parent').expectedFileName;5const path = require('path');6console.log(expectedFileName(path.join('src', 'test.js')));
Using AI Code Generation
1const path = require('path');2const expectedFileName = require('stryker-parent').expectedFileName;3const file = path.join(__dirname, 'test.js');4const expectedFile = path.join(__dirname, 'test.js');5module.exports = function (config) {6 config.set({7 expectedFileName(file, expectedFile)8 });9};10const path = require('path');11const expectedFileName = require('stryker-parent').expectedFileName;12const file = path.join(__dirname, 'test2.js');13const expectedFile = path.join(__dirname, 'test2.js');14module.exports = function (config) {15 config.set({16 expectedFileName(file, expectedFile)17 });18};19const path = require('path');20const expectedFileName = require('stryker-parent').expectedFileName;21const file = path.join(__dirname, 'test3.js');22const expectedFile = path.join(__dirname, 'test3.js');23module.exports = function (config) {24 config.set({25 expectedFileName(file, expectedFile)26 });27};28const path = require('path');29const expectedFileName = require('stryker-parent').expectedFileName;30const file = path.join(__dirname, 'test4.js');31const expectedFile = path.join(__dirname, 'test4.js');32module.exports = function (config) {33 config.set({34 expectedFileName(file, expectedFile)35 });36};37const path = require('path');38const expectedFileName = require('stryker-parent').expectedFileName;39const file = path.join(__dirname, 'test5.js');40const expectedFile = path.join(__dirname, 'test5.js');41module.exports = function (config) {42 config.set({43 expectedFileName(file, expectedFile)44 });45};46const path = require('path
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!!