Best JavaScript code snippet using stryker-parent
utils.spec.js
Source:utils.spec.js
1import chai, {expect} from 'chai';2import sinon from 'sinon';3import sinonChai from 'sinon-chai';4import * as Utils from './utils';5chai.use(sinonChai);6import Promise from 'bluebird';7describe('API utils', () => {8 describe('normalize', () => {9 it('Should normalize response', () => {10 const arr = [ {id: 1}, {id: 2}, {id: 3}];11 const res = Utils.normalize('tests', arr);12 expect(res.testsById).to.be.defined;13 expect(res.testsById[1]).to.be.defined;14 expect(res.testsById[2]).to.be.defined;15 expect(res.testsById[3]).to.be.defined;16 expect(res.tests).to.eql([1, 2, 3]);17 });18 it('Should throw error if array is not porvided', (done) => {19 try {20 Utils.normalize('tests');21 } catch (e) {22 expect(true).to.be.truthy;23 return done();24 }25 expect(false).to.be.truthy;26 return done();27 });28 it('Should throw error if namespace is not porvided', (done) => {29 const arr = [ {id: 1}, {id: 2}, {id: 3}];30 try {31 Utils.normalize(undefined, arr);32 } catch (e) {33 expect(true).to.be.truthy;34 return done();35 }36 expect(false).to.be.truthy;37 return done();38 });39 it('Should throw error if namespace is not text', (done) => {40 const arr = [ {id: 1}, {id: 2}, {id: 3}];41 try {42 Utils.normalize(132, arr);43 } catch (e) {44 expect(true).to.be.truthy;45 return done();46 }47 expect(false).to.be.truthy;48 return done();49 });50 it('Should throw error if object array is is not array', (done) => {51 try {52 Utils.normalize('132', 'arr');53 } catch (e) {54 expect(true).to.be.truthy;55 return done();56 }57 expect(false).to.be.truthy;58 return done();59 });60 });61 describe('normalizePartially', () => {62 it('Should normalize response', () => {63 const arr = [ {id: 1}, {id: 2}, {id: 3}];64 const res = Utils.normalize('tests', arr);65 expect(res.testsById).to.be.defined;66 expect(res.testsById[1]).to.be.defined;67 expect(res.testsById[2]).to.be.defined;68 expect(res.testsById[3]).to.be.defined;69 expect(res.tests).not.to.defined;70 });71 it('Should throw error if array is not porvided', (done) => {72 try {73 Utils.normalize('tests');74 } catch (e) {75 expect(true).to.be.truthy;76 return done();77 }78 expect(false).to.be.truthy;79 return done();80 });81 it('Should throw error if namespace is not porvided', (done) => {82 const arr = [ {id: 1}, {id: 2}, {id: 3}];83 try {84 Utils.normalize(undefined, arr);85 } catch (e) {86 expect(true).to.be.truthy;87 return done();88 }89 expect(false).to.be.truthy;90 return done();91 });92 it('Should throw error if namespace is not text', (done) => {93 const arr = [ {id: 1}, {id: 2}, {id: 3}];94 try {95 Utils.normalize(132, arr);96 } catch (e) {97 expect(true).to.be.truthy;98 return done();99 }100 expect(false).to.be.truthy;101 return done();102 });103 it('Should throw error if object array is is not array', (done) => {104 try {105 Utils.normalize('132', 'arr');106 } catch (e) {107 expect(true).to.be.truthy;108 return done();109 }110 expect(false).to.be.truthy;111 return done();112 });113 });114 describe('denorm', () => {115 let accounts;116 let channels;117 let bananas;118 let models;119 beforeEach(() => {120 accounts = [121 {122 id: 1,123 name: 'acc1'124 }, {125 id: 2,126 name: 'acc2'127 }];128 channels = [129 {130 id: 3,131 name: 'Ch1'132 }, {133 id: 4,134 name: 'Ch2'135 }];136 bananas = [137 {138 id: 5,139 name: 'B1'140 }, {141 id: 6,142 name: 'B2'143 }];144 models = {145 accounts: {146 getByIds: sinon.spy(() => Promise.resolve(accounts))147 },148 channels: {149 getByIds: sinon.spy(() => Promise.resolve(channels))150 },151 bananas: {152 getByIds: sinon.spy(() => Promise.resolve(bananas))153 }154 };155 });156 it('Should return promise', () => {157 const arr = [{account_id: 1}, {account_id: 2}];158 const response = Utils.denorm(models, 'accounts', arr);159 expect(response.then).to.be.defined;160 expect(response.catch).to.be.defined;161 });162 it('Should denorm data', (done) => {163 const arr = [{account_id: 1}, {account_id: 2}];164 Utils.denorm(models, 'accounts', arr).then(denorm => {165 expect(denorm.length).to.eql(1);166 expect(denorm[0].accountsById).to.be.defined;167 expect(denorm[0].accountsById[1]).to.be.defined;168 expect(denorm[0].accountsById[2]).to.be.defined;169 expect(denorm[0].accounts).not.to.be.defined;170 done();171 }, () => {172 expect(false).to.be.truthy;173 done();174 });175 });176 it('Should denorm multiple data', (done) => {177 const arr = [{account_id: 1, channel_id: 3}, {account_id: 2, channel_id: 4}];178 Utils.denorm(models, 'accounts,channels', arr).then(denorm => {179 expect(denorm.length).to.eql(2);180 expect(denorm[0].accountsById).to.be.defined;181 expect(denorm[0].accountsById[1]).to.be.defined;182 expect(denorm[0].accountsById[2]).to.be.defined;183 expect(denorm[0].accounts).not.to.be.defined;184 expect(denorm[1].channelsById).to.be.defined;185 expect(denorm[1].channelsById[3]).to.be.defined;186 expect(denorm[1].channelsById[4]).to.be.defined;187 expect(denorm[1].channels).not.to.be.defined;188 done();189 }, () => {190 expect(false).to.be.truthy;191 done();192 });193 });194 it('Should denorm all allowed data', (done) => {195 const arr = [{account_id: 1, channel_id: 3, banana_id: 5}, {account_id: 2, channel_id: 4, banana_id: 6}];196 Utils.denorm(models, 'true', arr).then(denorm => {197 expect(denorm.length).to.eql(2);198 expect(denorm[0].accountsById).to.be.defined;199 expect(denorm[0].accountsById[1]).to.be.defined;200 expect(denorm[0].accountsById[2]).to.be.defined;201 expect(denorm[0].accounts).not.to.be.defined;202 expect(denorm[1].channelsById).to.be.defined;203 expect(denorm[1].channelsById[3]).to.be.defined;204 expect(denorm[1].channelsById[4]).to.be.defined;205 expect(denorm[1].channels).not.to.be.defined;206 done();207 }, () => {208 expect(false).to.be.truthy;209 });210 });211 it('Should not denorm data', (done) => {212 const arr = [{account_id: 1}, {account_id: 2}];213 Utils.denorm(models, 'false', arr).then(denorm => {214 expect(denorm.length).to.eql(0);215 done();216 }, () => {217 expect(false).to.be.truthy;218 done();219 });220 });221 it('Should throw error if model is missing', (done) => {222 const arr = [{apple_id: 1}, {apple_id: 2}];223 Utils.denorm(models, 'false', arr).then(() => {224 expect(false).to.be.truthy;225 done();226 }, () => {227 expect(false).to.be.truthy;228 done();229 }).catch(() => {230 expect(true).to.be.truthy;231 done();232 });233 });234 it('Should throw error if denorm string is missing', (done) => {235 const arr = [{apple_id: 1}, {apple_id: 2}];236 Utils.denorm(models, null, arr).then(() => {237 expect(false).to.be.truthy;238 done();239 }, () => {240 expect(false).to.be.truthy;241 done();242 }).catch(() => {243 expect(true).to.be.truthy;244 done();245 });246 });247 it('Should throw error if input array is missing', (done) => {248 Utils.denorm(models, 'true').then(() => {249 expect(false).to.be.truthy;250 done();251 }, () => {252 expect(false).to.be.truthy;253 done();254 }).catch(() => {255 expect(true).to.be.truthy;256 done();257 });258 });259 });...
test_service.js
Source:test_service.js
1angular.module('ph').factory('Test', ['$http', 'Question', 'Alert', 'API_PATH', 'localStorageService', 'Auth', function($http, Question, Alert, API_PATH, localStorageService, Auth){2 var currentTestId = null;3 var tests = [];4 var testsById = {};5 var changedCallbacks = [];6 function changedExecute() {7 for (var i in changedCallbacks) {8 changedCallbacks[i]();9 }10 }11 function handleRequestError(msg) {12 return function(request) {13 if (request.status === 401) {14 Auth.setLoginNeeded(request.data);15 throw 'Authentication needed';16 } else {17 Alert.add(msg, 'danger');18 }19 };20 }21 var methods = {22 getList: function() {23 return tests;24 },25 createTest: function(newTest, labels) {26 if (typeof labels == 'undefined') {27 labels = [];28 }29 var object = {30 object_: newTest,31 labels_: labels32 };33 return $http.post(API_PATH + 'test', object)34 .then(function() {35 return methods.load();36 })37 .catch(handleRequestError('Er trad een fout op bij het aanmaken van de toets.'));38 },39 getTestById: function(id) {40 return testsById[id];41 },42 getCurrentTest: function() {43 if (!currentTestId && tests.length) {44 currentTestId = localStorageService.get('currentTestId');45 methods.setCurrentTest(currentTestId);46 }47 if (currentTestId) {48 return methods.getTestById(currentTestId);49 }50 },51 setCurrentTest: function(testId) {52 currentTestId = testId;53 localStorageService.set('currentTestId', testId);54 changedExecute();55 },56 getCurrentTestElements: function() {57 var elements = [];58 if (testsById && currentTestId) { 59 for (var i in testsById[currentTestId].object.elements) {60 var element = testsById[currentTestId].object.elements[i];61 if (typeof element.testQuestion != 'undefined') {62 var questionId = element.testQuestion;63 var question = Question.getQuestionById(questionId);64 if (question) {65 elements.push({'testQuestion': question});66 }67 } else {68 elements.push(element);69 }70 }71 }72 return elements;73 },74 load: function() {75 return $http.get(API_PATH + 'test')76 .then(function(result){77 tests = result.data.items;78 for (var i in tests) {79 testsById[tests[i].id] = tests[i];80 }81 changedExecute();82 return tests;83 })84 .catch(handleRequestError('Er trad een fout op bij het ophalen van de toetsen.', 'danger'));85 },86 addQuestion: function(testId, questionId) {87 var test = testsById[testId];88 var questionIdList = test.object.elements;89 questionIdList.push({'testQuestion': questionId});90 return methods.saveElementIdList(testId, questionIdList);91 },92 saveElementIdList: function(testId, elementIdList) {93 var test = testsById[testId];94 var updatedTest = {95 object_: test.object,96 labels_: test.labels97 };98 updatedTest.object_.elements = elementIdList;99 return $http.put(API_PATH + 'test/id/' + testId, updatedTest)100 .then(function(){101 methods.load();102 })103 .catch(handleRequestError('Er trad een fout op bij het opslaan van de vragenlijst.'));104 },105 saveElementList: function(testId, elementList) {106 var elementIdList = [];107 for (var i in elementList) {108 var element = elementList[i];109 if (typeof element.testQuestion != 'undefined') {110 elementIdList.push({'testQuestion': element.testQuestion.id});111 } else {112 elementIdList.push(element);113 }114 }115 return methods.saveElementIdList(testId, elementIdList);116 },117 saveCurrentElementList: function(elementList) {118 return methods.saveElementList(currentTestId, elementList);119 },120 addQuestionToCurrentTest: function(questionId) {121 if (currentTestId) {122 return methods.addQuestion(currentTestId, questionId);123 }124 },125 isQuestionInCurrentTest: function(questionId) {126 if (currentTestId) {127 for (var i in testsById[currentTestId].object.elements) {128 var element = testsById[currentTestId].object.elements[i];129 if (element.testQuestion === questionId) {130 return true;131 }132 }133 }134 return false;135 },136 removeQuestionFromCurrentTest: function(questionId) {137 var elements = [];138 for (var i in testsById[currentTestId].object.elements) {139 var element = testsById[currentTestId].object.elements[i];140 if (element.testQuestion !== questionId) {141 elements.push(element);142 }143 }144 methods.saveElementIdList(currentTestId, elements);145 },146 removeTest: function(testId) {147 return $http.delete(API_PATH + 'test/id/' + testId)148 .then(function(){149 methods.load();150 })151 .catch(handleRequestError('Er trad een fout op bij het verwijderen van de toets.'));152 },153 changed: function(callback) {154 changedCallbacks.push(callback);155 },156 getCurrentTestExportUrl: function(type, showAnswers) {157 var parameters = '';158 if (showAnswers) {159 parameters = '?withAnswers';160 }161 return API_PATH + 'test/id/' + currentTestId + '/export/' + type + parameters;162 },163 updateTestName: function(testId, newName) {164 var test = testsById[testId];165 test.object.name = newName;166 var updatedTest = {167 object_: test.object,168 labels_: test.labels169 };170 return $http.put(API_PATH + 'test/id/' + testId, updatedTest)171 .then(function(){172 methods.load();173 })174 .catch(handleRequestError('Er trad een fout op bij het opslaan van de nieuwe toetsnaam.'));175 }176 };177 Question.setTestMethods(methods);178 return methods;...
manager.js
Source:manager.js
1'use strict';2const httpContext = require('express-http-context'),3 uuid = require('uuid');4const testGenerator = require('./testGenerator'),5 database = require('./database'),6 fileManager = require('../../files/models/fileManager'),7 downloadManager = require('./downloadManager'),8 { ERROR_MESSAGES } = require('../../common/consts'),9 { TEST_TYPE_DSL, CONTEXT_ID } = require('./../../common/consts');10module.exports = {11 upsertTest,12 getTest,13 getAllTestRevisions,14 getTests,15 deleteTest,16 getTestsByProcessorId,17 insertTestBenchmark,18 getBenchmark19};20async function upsertTest(testRawData, existingTestId) {21 const contextId = httpContext.get(CONTEXT_ID);22 if (existingTestId) {23 const test = await database.getTest(existingTestId, contextId);24 if (!test) {25 const error = new Error(ERROR_MESSAGES.NOT_FOUND);26 error.statusCode = 404;27 throw error;28 }29 }30 let testArtilleryJson = await testGenerator.createTest(testRawData);31 const id = existingTestId || uuid();32 let processorFileId;33 if (testRawData.processor_file_url) {34 const downloadedFile = await downloadManager.downloadFile(testRawData.processor_file_url);35 processorFileId = await fileManager.saveFile('processor.js', downloadedFile);36 }37 const revisionId = uuid.v4();38 if (testRawData.type === TEST_TYPE_DSL) {39 testArtilleryJson = undefined;40 }41 await database.insertTest(testRawData, testArtilleryJson, id, revisionId, processorFileId, contextId);42 return { id: id, revision_id: revisionId };43}44async function insertTestBenchmark(benchmarkRawData, testId) {45 const contextId = httpContext.get(CONTEXT_ID);46 const dataParse = JSON.stringify(benchmarkRawData);47 await database.insertTestBenchmark(testId, dataParse, contextId);48 return { benchmark_data: benchmarkRawData };49}50async function getBenchmark(testId) {51 const contextId = httpContext.get(CONTEXT_ID);52 const benchmark = await database.getTestBenchmark(testId, contextId);53 if (!benchmark) {54 const error = new Error(ERROR_MESSAGES.NOT_FOUND);55 error.statusCode = 404;56 throw error;57 }58 return JSON.parse(benchmark);59}60async function getTest(testId) {61 const contextId = httpContext.get(CONTEXT_ID);62 const test = await database.getTest(testId, contextId);63 if (!test) {64 const error = new Error(ERROR_MESSAGES.NOT_FOUND);65 error.statusCode = 404;66 throw error;67 }68 if (test.type === TEST_TYPE_DSL) {69 test.artillery_test = await testGenerator.createTest(test);70 } else {71 test.artillery_test = test.artillery_json;72 }73 delete test.artillery_json;74 return test;75}76async function getAllTestRevisions(testId) {77 const contextId = httpContext.get(CONTEXT_ID);78 const rows = await database.getAllTestRevisions(testId, contextId);79 const testRevisions = [];80 rows.forEach(function (row) {81 row.artillery_test = row.artillery_json;82 delete row.artillery_json;83 testRevisions.push(row);84 });85 if (testRevisions.length !== 0) {86 return testRevisions;87 } else {88 const error = new Error(ERROR_MESSAGES.NOT_FOUND);89 error.statusCode = 404;90 throw error;91 }92}93async function getTests(filter) {94 const contextId = httpContext.get(CONTEXT_ID);95 const rows = await database.getTests(contextId, filter);96 const testsById = {};97 rows.forEach(function (row) {98 if (!testsById[row.id] || row.updated_at > testsById[row.id].updated_at) {99 testsById[row.id] = row;100 }101 });102 const latestTestsRevisions = [];103 Object.keys(testsById).forEach((id) => {104 testsById[id].artillery_test = testsById[id].artillery_json;105 delete testsById[id].artillery_json;106 latestTestsRevisions.push(testsById[id]);107 });108 return latestTestsRevisions;109}110async function deleteTest(testId) {111 const contextId = httpContext.get(CONTEXT_ID);112 const test = await database.getTest(testId, contextId);113 if (!test) {114 const error = new Error(ERROR_MESSAGES.NOT_FOUND);115 error.statusCode = 404;116 throw error;117 }118 return database.deleteTest(testId);119}120async function getTestsByProcessorId(processorId) {121 const allCurrentTests = await getTests();122 const inUseTestsByProcessor = allCurrentTests.filter(test => test.processor_id && test.processor_id.toString() === processorId);123 return inUseTestsByProcessor;...
Using AI Code Generation
1const {testsById} = require('stryker-parent');2const {testsById} = require('stryker-child');3module.exports.testsById = function() {4 return "This is the parent method";5};6module.exports.testsById = function() {7 return "This is the child method";8};9const {testsById} = require(path.resolve(__dirname, '../stryker-parent'));
Using AI Code Generation
1var testsById = require('stryker-parent').testsById;2var tests = testsById('test.js');3console.log(tests);4var testsById = require('stryker-parent').testsById;5var tests = testsById('test2.js');6console.log(tests);7var testsById = require('stryker-parent').testsById;8var tests = testsById('test3.js');9console.log(tests);10var testsById = require('stryker-parent').testsById;11var tests = testsById('test4.js');12console.log(tests);13var testsById = require('stryker-parent').testsById;14var tests = testsById('test5.js');15console.log(tests);16var testsById = require('stryker-parent').testsById;17var tests = testsById('test6.js');18console.log(tests);19var testsById = require('stryker-parent').testsById;20var tests = testsById('test7.js');21console.log(tests);22var testsById = require('stryker-parent').testsById;23var tests = testsById('test8.js');24console.log(tests);25var testsById = require('stryker-parent').testsById;26var tests = testsById('test9.js');27console.log(tests);28var testsById = require('stryker-parent').testsById;29var tests = testsById('test10.js');30console.log(tests);31var testsById = require('stryker-parent').testsById;32var tests = testsById('test
Using AI Code Generation
1var stryker = require('stryker-parent');2var testsById = stryker.testsById;3var tests = testsById('test.js');4console.log(tests);5var stryker = require('stryker-parent');6var testsById = stryker.testsById;7var tests = testsById('test.js');8console.log(tests);9var stryker = require('stryker-parent');10var testsById = stryker.testsById;11var tests = testsById('test.js');12console.log(tests);13var stryker = require('stryker-parent');14var testsById = stryker.testsById;15var tests = testsById('test.js');16console.log(tests);17var stryker = require('stryker-parent');18var testsById = stryker.testsById;19var tests = testsById('test.js');20console.log(tests);21var stryker = require('stryker-parent');22var testsById = stryker.testsById;23var tests = testsById('test.js');24console.log(tests);25var stryker = require('stryker-parent');26var testsById = stryker.testsById;27var tests = testsById('test.js');28console.log(tests);29var stryker = require('stryker-parent');30var testsById = stryker.testsById;31var tests = testsById('test.js');32console.log(tests);33var stryker = require('stryker-parent');34var testsById = stryker.testsById;35var tests = testsById('test.js');36console.log(tests);37var stryker = require('stryker-parent');
Using AI Code Generation
1const Stryker = require('stryker-parent');2const stryker = new Stryker();3stryker.testsById(['1', '2', '3']).then((resp) => {4 console.log(resp);5});6{ '1': 'Passed', '2': 'Failed', '3': 'Skipped' }7const Stryker = require('stryker-parent');8const stryker = new Stryker();9stryker.testStatus('1').then((resp) => {10 console.log(resp);11});
Using AI Code Generation
1var testsById = require('stryker-parent').testsById;2var test = testsById('test1');3test('should do something', function () {4 expect(true).toBeTruthy();5});6module.exports = function (config) {7 config.set({8 mochaOptions: {9 }10 });11};12var testsById = require('stryker-parent').testsById;13var test = testsById('test1');14test.before(function () {15 console.log('before');16});17test.after(function () {18 console.log('after');19});
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!!