How to use testResults method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

codeRoutes.js

Source:codeRoutes.js Github

copy

Full Screen

1import express from "express";2import SandBox from "../DockerSandbox/DockerSandbox";3// Models4import User from "../models/User";5import Exercise from "../models/Exercise";6import Result from "../models/Result";7const router = express.Router();8let folder = "temp";9router.post("/run", async (req, res) => {10 let inputs = [];11 let outputs = [];12 const language = req.body.language;13 const compiler = req.body.compiler;14 const code = {15 codeContent: req.body.code,16 codeFileName: "code" + req.user.id,17 };18 const input = {19 inputContent: req.body.input,20 inputFileName: "input" + req.user.id,21 };22 inputs.push(input);23 const output = "output" + req.user.id;24 outputs.push(output);25 const sandBox = new SandBox(26 folder,27 code,28 inputs,29 outputs,30 language,31 compiler32 );33 sandBox.run((result) => {34 for (var i = 0; i < result.length; i++) {35 if (result[i].type === "error") {36 res.status(200).send(result);37 break;38 }39 if (i === result.length - 1) {40 res.status(200).send(result);41 }42 }43 });44});45router.post("/submit", async (req, res) => {46 let inputs = [];47 let outputs = [];48 let result;49 const exerciseId = req.body.exerciseId;50 const exercise = await Exercise.findById(exerciseId);51 const student = await User.findById(req.user.id);52 const language = req.body.language;53 const compiler = req.body.compiler;54 const code = {55 codeContent: req.body.code,56 codeFileName: "code" + req.user.id,57 };58 // This loop to create all input file of test cases59 for (const [i, testCase] of exercise.testCases.entries()) {60 const input = {61 inputContent: testCase.input,62 inputFileName: "input" + req.user.id + i,63 };64 inputs.push(input);65 // This output is require if the user want to compile C/C++66 const output = "output" + req.user.id;67 outputs.push(output);68 }69 const sandBox = new SandBox(70 folder,71 code,72 inputs,73 outputs,74 language,75 compiler76 );77 let testResults = [];78 async function getTestResults(next) {79 result = await Result.findOneAndUpdate(80 {81 student: student,82 exercise: exercise,83 },84 {85 student: student,86 exercise: exercise,87 testCases: exercise.testCases,88 studentCode: req.body.code,89 },90 { new: true, upsert: true, setDefaultsOnInsert: true }91 );92 const testCases = await Result.findOne({93 student: student,94 exercise: exercise,95 }).select("testCases");96 sandBox.run(async (data) => {97 testResults = data;98 for (var i = 0; i < testResults.length; i++) {99 // Break the loop if compile code error100 if (testResults[i].type === "error") {101 const diff =102 new Date(exercise.expiredTime) - new Date(result.submitTime);103 if (diff < 0) {104 await Result.updateOne(105 { exercise: exercise, student: student },106 { isLate: true },107 { new: true }108 );109 } else {110 await Result.updateOne(111 { exercise: exercise, student: student },112 { isLate: false },113 { new: true }114 );115 }116 const finalResult = await Result.findOne({117 exercise: exercise,118 student: student,119 });120 finalResult.score = finalResult.getTotalPoint();121 await finalResult.save();122 res.send(testResults[i].output);123 break;124 }125 // Continue to compare test case if compile code successfully126 testCases.testCases.forEach(async (testCase) => {127 // Pass test case128 if (129 testResults[i].input === testCase.input &&130 testResults[i].output === testCase.output &&131 testResults[i].runTime <= testCase.timeLimit132 ) {133 await Result.updateOne(134 {135 student: student,136 exercise: exercise,137 "testCases.input": testResults[i].input,138 "testCases.output": testResults[i].output,139 },140 {141 $set: {142 "testCases.$.message": "Pass",143 "testCases.$.actualOutput": testResults[i].output,144 "testCases.$.runTime": testResults[i].runTime,145 "testCases.$.pass": true,146 },147 }148 );149 }150 // Overtime test case151 else if (152 testResults[i].input === testCase.input &&153 testResults[i].output === testCase.output &&154 testResults[i].runTime > testCase.timeLimit155 ) {156 await Result.updateOne(157 {158 student: student,159 exercise: exercise,160 "testCases.input": testResults[i].input,161 "testCases.output": testResults[i].output,162 },163 {164 $set: {165 "testCases.$.message": "Over Time",166 "testCases.$.actualOutput": testResults[i].output,167 "testCases.$.runTime": testResults[i].runTime,168 "testCases.$.pass": false,169 },170 }171 );172 }173 // Fail test case174 else if (175 testResults[i].input === testCase.input &&176 testResults[i].output !== testCase.output177 ) {178 await Result.updateOne(179 {180 student: student,181 exercise: exercise,182 "testCases.input": testResults[i].input,183 },184 {185 $set: {186 "testCases.$.message": "Fail",187 "testCases.$.actualOutput": testResults[i].output,188 "testCases.$.runTime": testResults[i].runTime,189 "testCases.$.pass": false,190 },191 }192 );193 }194 });195 if (i === testResults.length - 1) next();196 }197 });198 }199 getTestResults(processSubmit);200 async function processSubmit() {201 // The duration expired date and submit date202 const diff = new Date(exercise.expiredTime) - new Date(result.submitTime);203 if (diff < 0) {204 await Result.updateOne(205 { exercise: exercise, student: student },206 { isLate: true },207 { new: true }208 );209 } else {210 await Result.updateOne(211 { exercise: exercise, student: student },212 { isLate: false },213 { new: true }214 );215 }216 const finalResult = await Result.findOne({217 exercise: exercise,218 student: student,219 });220 finalResult.score = finalResult.getTotalPoint();221 await finalResult.save();222 const context = {223 point: finalResult.getTotalPoint(),224 testCases: finalResult.testCases,225 };226 res.status(200).send(context);227 }228});...

Full Screen

Full Screen

sorting.ts

Source:sorting.ts Github

copy

Full Screen

1import { AggregatedResult, AssertionResult } from "@jest/test-result";2import { JestHTMLReporterSortType } from "src/types";3export default (4 testResults: AggregatedResult["testResults"],5 sortType?: JestHTMLReporterSortType6): AggregatedResult["testResults"] => {7 const sortTypeLowercase = sortType && sortType.toLowerCase();8 switch (sortTypeLowercase) {9 case "status":10 return sortByStatus(testResults);11 case "executiondesc":12 return sortByExecutionDesc(testResults);13 case "executionasc":14 return sortByExecutionAsc(testResults);15 case "titledesc":16 return sortByTitleDesc(testResults);17 case "titleasc":18 return sortByTitleAsc(testResults);19 default:20 return testResults;21 }22};23/**24 * Splits test suites apart based on individual test status and sorts by that status:25 * 1. Pending26 * 2. Failed27 * 3. Passed28 */29const sortByStatus = (testResults: AggregatedResult["testResults"]) => {30 const pendingSuites: AggregatedResult["testResults"] = [];31 const failingSuites: AggregatedResult["testResults"] = [];32 const passingSuites: AggregatedResult["testResults"] = [];33 testResults.forEach((result) => {34 const pending: AssertionResult[] = [];35 const failed: AssertionResult[] = [];36 const passed: AssertionResult[] = [];37 result.testResults.forEach((x) => {38 if (x.status === "pending") {39 pending.push(x);40 } else if (x.status === "failed") {41 failed.push(x);42 } else {43 passed.push(x);44 }45 });46 if (pending.length > 0) {47 pendingSuites.push({48 ...result,49 testResults: pending,50 });51 }52 if (failed.length > 0) {53 failingSuites.push({54 ...result,55 testResults: failed,56 });57 }58 if (passed.length > 0) {59 passingSuites.push({60 ...result,61 testResults: passed,62 });63 }64 });65 return [].concat(pendingSuites, failingSuites, passingSuites);66};67/**68 * Sorts by Execution Time | Descending69 */70const sortByExecutionDesc = (testResults: AggregatedResult["testResults"]) => {71 if (testResults) {72 testResults.sort(73 (a, b) =>74 b.perfStats.end -75 b.perfStats.start -76 (a.perfStats.end - a.perfStats.start)77 );78 }79 return testResults;80};81/**82 * Sorts by Execution Time | Ascending83 */84const sortByExecutionAsc = (testResults: AggregatedResult["testResults"]) => {85 if (testResults) {86 testResults.sort(87 (a, b) =>88 a.perfStats.end -89 a.perfStats.start -90 (b.perfStats.end - b.perfStats.start)91 );92 }93 return testResults;94};95/**96 * Sorts by Suite filename and Test name | Descending97 */98const sortByTitleDesc = (testResults: AggregatedResult["testResults"]) => {99 if (testResults) {100 // Sort Suites101 const sorted = testResults.sort((a, b) =>102 sortAlphabetically(a.testFilePath, b.testFilePath, true)103 );104 // Sort Suite testResults105 sorted.forEach((suite) => {106 // By Ancestor Titles107 suite.testResults.sort((a, b) =>108 sortAlphabetically(109 a.ancestorTitles.join(" "),110 b.ancestorTitles.join(" "),111 true112 )113 );114 // By Test Titles115 suite.testResults.sort((a, b) =>116 sortAlphabetically(a.title, b.title, true)117 );118 });119 return sorted;120 }121 return testResults;122};123/**124 * Sorts by Suite filename and Test name | Ascending125 */126const sortByTitleAsc = (testResults: AggregatedResult["testResults"]) => {127 if (testResults) {128 // Sort Suites129 const sorted = testResults.sort((a, b) =>130 sortAlphabetically(a.testFilePath, b.testFilePath)131 );132 // Sort Suite testResults133 sorted.forEach((suite) => {134 // By Ancestor Titles135 suite.testResults.sort((a, b) =>136 sortAlphabetically(137 a.ancestorTitles.join(" "),138 b.ancestorTitles.join(" ")139 )140 );141 // By Test Titles142 suite.testResults.sort((a, b) => sortAlphabetically(a.title, b.title));143 });144 return sorted;145 }146 return testResults;147};148/**149 * Helper sorting method150 */151const sortAlphabetically = (a: any, b: any, reversed: boolean = false) => {152 if ((!reversed && a < b) || (reversed && a > b)) {153 return -1;154 } else if ((!reversed && a > b) || (reversed && a < b)) {155 return 1;156 }157 return 0;...

Full Screen

Full Screen

testlogger.js

Source:testlogger.js Github

copy

Full Screen

1/****************************************************************************2**3** Copyright (C) 2015 The Qt Company Ltd.4** Contact: http://www.qt.io/licensing/5**6** This file is part of the test suite of the Qt Toolkit.7**8** $QT_BEGIN_LICENSE:LGPL21$9** Commercial License Usage10** Licensees holding valid commercial Qt licenses may use this file in11** accordance with the commercial license agreement provided with the12** Software or, alternatively, in accordance with the terms contained in13** a written agreement between you and The Qt Company. For licensing terms14** and conditions see http://www.qt.io/terms-conditions. For further15** information use the contact form at http://www.qt.io/contact-us.16**17** GNU Lesser General Public License Usage18** Alternatively, this file may be used under the terms of the GNU Lesser19** General Public License version 2.1 or version 3 as published by the Free20** Software Foundation and appearing in the file LICENSE.LGPLv21 and21** LICENSE.LGPLv3 included in the packaging of this file. Please review the22** following information to ensure the GNU Lesser General Public License23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.25**26** As a special exception, The Qt Company gives you certain additional27** rights. These rights are described in The Qt Company LGPL Exception28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.29**30** $QT_END_LICENSE$31**32****************************************************************************/33.pragma library34// We need a global place to store the results that can be35// shared between multiple TestCase instances. Because QML36// creates a separate scope for every inclusion of this file,37// we hijack the global "Qt" object to store our data.38function log_init_results()39{40 if (!Qt.testResults) {41 Qt.testResults = {42 reportedStart: false,43 nextId: 0,44 testCases: []45 }46 }47}48function log_register_test(name)49{50 log_init_results()51 var testId = Qt.testResults.nextId++52 Qt.testResults.testCases.push(testId)53 return testId54}55function log_optional_test(testId)56{57 log_init_results()58 var index = Qt.testResults.testCases.indexOf(testId)59 if (index >= 0)60 Qt.testResults.testCases.splice(index, 1)61}62function log_mandatory_test(testId)63{64 log_init_results()65 var index = Qt.testResults.testCases.indexOf(testId)66 if (index == -1)67 Qt.testResults.testCases.push(testId)68}69function log_start_test()70{71 log_init_results()72 if (Qt.testResults.reportedStart)73 return false74 Qt.testResults.reportedStart = true75 return true76}77function log_complete_test(testId)78{79 var index = Qt.testResults.testCases.indexOf(testId)80 if (index >= 0)81 Qt.testResults.testCases.splice(index, 1)82 return Qt.testResults.testCases.length > 0...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo 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