Best JavaScript code snippet using jest
step_log.js
Source:step_log.js
1import React, { Component } from "react";2import {Box, Collapse, Drawer, Tag, List, Avatar, Table, Shell} from '@alifd/next';3import { DonutChart } from 'bizcharts';4import ReactDOM from "react-dom";5import axios from "axios";6import qs from "qs";7import '../../static/css/iteration/pipeline/step_log.css'8import JavaPackage from '../../static/img/iteration/pipeline/java_package.png'9import Java from '../../static/img/iteration/pipeline/java.png'10import '../../static/js/iteration/pipeline/prettify'11const { Group: TagGroup } = Tag;12class StepLog extends Component {13 state = {14 visible: false,15 title: "",16 log: {},17 width : "80%",18 };19 constructor(props) {20 super(props);21 this.appName = this.props.appName;22 }23 onOpen = (t, l, actionId, stageId, stepId) => {24 this.setState({25 title: t,26 log: l,27 visible: true,28 actionId: actionId,29 stageId: stageId,30 stepId: stepId,31 });32 };33 onClose = (reason, e) => {34 this.setState({35 visible: false,36 title: "",37 log:{},38 });39 }40 componentDidMount() {41 this.props.onRef(this)42 }43 render() {44 return (45 <div>46 <Drawer47 title={this.state.title}48 placement="right"49 visible={this.state.visible}50 onClose={this.onClose}51 width={this.state.width}>52 {53 this.state.log["type"] === 1 && (54 <SimpleLog log={this.state.log["data"]}/>55 )56 }57 {58 this.state.log["type"] === 0 && (59 <LogCollapse log={this.state.log["data"]}/>60 )61 }62 {63 this.state.log["type"] === 2 && (64 <JacocoTestReport report={this.state.log["data"]} actionId={this.state.actionId} stageId={this.state.stageId} stepId={this.state.stepId}/>65 )66 }67 </Drawer>68 </div>69 );70 }71}72class JacocoTestReport extends Component {73 constructor(props) {74 super(props);75 this.report = new Map(Object.entries(this.props.report))76 this.packageMenu = [];77 this.actionId = this.props.actionId78 this.stageId = this.props.stageId79 this.stepId = this.props.stepId80 this.JacocoTestCodeCoveredAPI = "/api/v1/iteration/undefined/action/"+this.actionId+"/stage/"+this.stageId+"/step/"+this.stepId+"/test/codeCovered"81 }82 toPercent(point){83 let str=Number(point*100).toFixed(2);84 str+="%";85 return str;86 }87 queryCoveredFile = (record, index ,e) => {88 const _this = this89 let data = {90 appName: record.group,91 package: record.package,92 fileName: record.fileName93 }94 axios.post(_this.JacocoTestCodeCoveredAPI, qs.stringify(data))95 .then(function (data){96 let fileData = <CodeCoveredPane fileData={data.data} appName={record.appName} package={record.package} fileName={record.fileName}/>97 let fileDataDiv = document.getElementById("packageDetail")98 ReactDOM.unmountComponentAtNode(fileDataDiv)99 ReactDOM.render(fileData, fileDataDiv)100 })101 .catch(function (error){})102 }103 packageDetail = (pkg) => {104 debugger105 let packageData = this.report.get(pkg)106 let dataSource = []107 for (let i=0; i < packageData.length; i++) {108 dataSource.push({109 group: packageData[i].group,110 package: packageData[i].package,111 fileName: packageData[i].class,112 branchMissed: packageData[i].branchMissed,113 branchCovered: packageData[i].branchCovered,114 branchRatio: this.toPercent(packageData[i].branchCovered/(packageData[i].branchCovered + packageData[i].branchMissed)),115 lineMissed: packageData[i].lineMissed,116 lineCovered: packageData[i].lineCovered,117 lineRatio: this.toPercent(packageData[i].lineCovered/(packageData[i].lineCovered + packageData[i].lineMissed)),118 methodMissed: packageData[i].methodMissed,119 methodCovered: packageData[i].methodCovered,120 methodRatio: this.toPercent(packageData[i].methodCovered/(packageData[i].methodMissed + packageData[i].methodCovered)),121 })122 }123 let pkgTable = <Table dataSource={dataSource} onRowClick={this.queryCoveredFile}>124 <Table.Column title="fileName" dataIndex="fileName"/>125 <Table.Column title="branchMissed" dataIndex="branchMissed"/>126 <Table.Column title="branchCovered" dataIndex="branchCovered"/>127 <Table.Column title="branchRatio" dataIndex="branchRatio"/>128 <Table.Column title="lineMissed" dataIndex="lineMissed"/>129 <Table.Column title="lineCovered" dataIndex="lineCovered"/>130 <Table.Column title="lineRatio" dataIndex="lineRatio"/>131 <Table.Column title="methodMissed" dataIndex="methodMissed"/>132 <Table.Column title="methodCovered" dataIndex="methodCovered"/>133 <Table.Column title="methodRatio" dataIndex="methodRatio"/>134 </Table>135 let packageDetailDiv = document.getElementById("packageDetail")136 ReactDOM.unmountComponentAtNode(packageDetailDiv)137 ReactDOM.render(pkgTable, packageDetailDiv)138 }139 componentDidMount() {140 if (this.packageMenu.length > 0) {141 this.packageDetail(this.packageMenu[0].title)142 }143 let totalBranchMissed = 0;144 let totalBranchCovered = 0;145 let totalLineMissed = 0;146 let totalLineCovered = 0;147 let totalMethodMissed = 0;148 let totalMethodCovered = 0;149 this.report.forEach(function (value, key) {150 for (let i = 0; i<value.length; i++) {151 totalBranchCovered += value[i].branchCovered152 totalBranchMissed += value[i].branchMissed153 totalLineCovered += value[i].lineCovered154 totalLineMissed += value[i].lineMissed155 totalMethodCovered += value[i].methodCovered156 totalMethodMissed += value[i].methodMissed157 }158 })159 let totalBranchRatio = this.toPercent(totalBranchCovered/(totalBranchMissed + totalBranchCovered))160 let totalLineRatio = this.toPercent(totalLineCovered/(totalLineMissed + totalLineCovered))161 let totalMethodRatio = this.toPercent(totalMethodCovered/(totalMethodMissed + totalMethodCovered))162 let testReport = <TestReport totalBranchMissed={totalBranchMissed} totalBranchCovered={totalBranchCovered} totalBranchRatio={totalBranchRatio}163 totalLineMissed={totalLineMissed} totalLineCovered={totalLineCovered} totalLineRatio={totalLineRatio}164 totalMethodMissed={totalMethodMissed} totalMethodCovered={totalMethodCovered} totalMethodRatio={totalMethodRatio}165 />166 let testReportDiv = document.getElementById("testReport")167 ReactDOM.unmountComponentAtNode(testReportDiv)168 ReactDOM.render(testReport, testReportDiv)169 }170 render() {171 const _this = this172 this.report.forEach(function (value, key) {173 _this.packageMenu.push({174 title: key,175 img: JavaPackage,176 })177 })178 return (179 <Box style={{width: "100%", height: "100%"}} direction='column'>180 <Box style={{height:200, overflow:"auto"}}>181 <div id="testReport"/>182 </Box>183 <Box style={{height:"80%"}} direction='row'>184 <Box style={{width:"25%", overflow:"auto"}}>185 <List size="small" header={<div>Package</div>} dataSource={this.packageMenu} renderItem={(item, i) => (186 <List.Item key={i} title={item.title} media={<Avatar src={item.img}/>} onClick={() => {187 this.packageDetail(item.title)188 }}>189 </List.Item>190 )}>191 </List>192 </Box>193 <Box style={{width:"75%", overflow:"auto"}}>194 <div id="packageDetail"/>195 </Box>196 </Box>197 </Box>198 )199 }200}201class CodeCoveredPane extends Component {202 constructor(props) {203 super(props);204 this.fileData = this.props.fileData205 this.appName = this.props.appName206 this.package = this.props.package207 this.fileName = this.props.fileName208 }209 render() {210 return (211 <div>212 <Shell className={"iframe-hack"} style={{ border: "1px solid #eee" }}>213 <Shell.Branding>214 <img215 src={JavaPackage}216 className="avatar"217 alt="java_package"218 />219 <span style={{ marginLeft: 10 }}>package: {this.package}</span>220 </Shell.Branding>221 <Shell.Action>222 <img223 src={Java}224 className="avatar"225 alt="java"226 />227 <span style={{ marginLeft: 10 }}>{this.fileName}.java</span>228 </Shell.Action>229 <Shell.Content>230 <div style={{ minHeight: 1200, background: "#fff" }}>231 <pre className="source lang-java linenums">232 {233 this.fileData.length >0 && (this.fileData.map((value, index) => {234 return (235 <div key={index} dangerouslySetInnerHTML={{__html:value.content}}/>236 )237 })238 )239 }240 </pre>241 </div>242 </Shell.Content>243 <Shell.Footer>244 <span>{this.appName}</span>245 <span>{this.package}</span>246 <span>{this.fileName}</span>247 </Shell.Footer>248 </Shell>249 </div>250 );251 }252}253class LogCollapse extends Component {254 constructor(props) {255 super(props);256 // this.log = this.props.log257 this.log = new Map(Object.entries(this.props.log))258 this.dataSource = new Map([]);259 this.colorMap=new Map([["warning","orange"],["error","red"]]);260 }261 changePmd = (key) => {262 let pmdDiv = document.getElementById("pmd")263 ReactDOM.unmountComponentAtNode(pmdDiv)264 ReactDOM.render(this.dataSource.get(key), pmdDiv)265 }266 render() {267 let typeMap = [];268 const _this = this;269 this.log.forEach(function(value, key){270 typeMap.push(<Tag key={key} color={_this.colorMap.get(value[0].type)} type="normal" onClick={_this.changePmd.bind(this, key)}>{key}</Tag>)271 let list = [];272 for(let i=0; i<value.length; i++) {273 list.push({title:value[i].file+":"+value[i].line+"("+value[i].info+")",content:value[i].code})274 }275 _this.dataSource.set(key, <Collapse dataSource={list}/>)276 })277 return (278 <div>279 <div id="tags">280 <TagGroup>281 {typeMap}282 </TagGroup>283 </div>284 <div id="pmd"/>285 </div>286 )287 }288}289class TestReport extends Component {290 constructor(props) {291 super(props);292 this.totalBranchMissed = this.props.totalBranchMissed293 this.totalBranchCovered = this.props.totalBranchCovered294 this.totalBranchRatio = this.props.totalBranchRatio295 this.totalLineMissed = this.props.totalLineMissed296 this.totalLineCovered = this.props.totalLineCovered297 this.totalLineRatio = this.props.totalLineRatio298 this.totalMethodMissed = this.props.totalMethodMissed299 this.totalMethodCovered = this.props.totalMethodCovered300 this.totalMethodRatio = this.props.totalMethodRatio301 }302 render () {303 let branchData = [{type: "è¦ç", value: this.totalBranchCovered},{type: "æªè¦ç", value: this.totalBranchMissed}]304 let lineData = [{type: "è¦ç", value: this.totalLineCovered},{type: "æªè¦ç", value: this.totalLineMissed}]305 let methodData = [{type: "è¦ç", value: this.totalMethodCovered},{type: "æªè¦ç", value: this.totalMethodMissed}]306 return (307 <Box direction="row">308 <Box style={{width:"33%"}}>309 <DonutChart310 data={branchData}311 autoFit312 height={200}313 radius={0.8}314 padding='auto'315 angleField='value'316 colorField='type'317 color={['greenyellow','tomato']}318 legend={{visible: false}}319 statistic={{320 title:{321 customHtml:()=>{322 let all = this.totalBranchMissed+this.totalBranchCovered;323 let allRatio = this.totalBranchRatio324 return '<div style="font-size:16px; font-family: Georgia, serif"><div>åæ¯æ°:'+all+'</div>'+'<div>è¦çç:'+allRatio +'</div>' + '</div>'325 }326 },327 content:false328 }}329 />330 </Box>331 <Box style={{width:"33%"}}>332 <DonutChart333 data={lineData}334 autoFit335 height={200}336 radius={0.8}337 padding='auto'338 angleField='value'339 colorField='type'340 color={['greenyellow','tomato']}341 legend={{visible: false}}342 statistic={{343 title:{344 customHtml:()=> {345 let all = this.totalLineMissed+this.totalLineCovered;346 let allRatio = this.totalLineRatio347 return '<div style="font-size:16px; font-family: Georgia, serif"><div>代ç è¡:'+all+'</div>'+'<div>è¦çç:'+allRatio +'</div>' + '</div>'348 }349 },350 content: false351 }}352 />353 </Box>354 <Box style={{width:"33%"}}>355 <DonutChart356 data={methodData}357 autoFit358 height={200}359 radius={0.8}360 padding='auto'361 angleField='value'362 colorField='type'363 color={['greenyellow','tomato']}364 legend={{visible: false}}365 statistic={{366 title:{367 customHtml:()=>{368 let all = this.totalMethodMissed+this.totalMethodCovered;369 let allRatio = this.totalMethodRatio370 return '<div style="font-size:16px; font-family: Georgia, serif"><div>æ¹æ³æ°:'+all+'</div>'+'<div>è¦çç:'+allRatio +'</div>' + '</div>'371 }372 },373 content: false374 }}375 />376 </Box>377 </Box>378 );379 }380}381class SimpleLog extends Component {382 constructor(props) {383 super(props);384 this.log = this.props.log385 }386 render() {387 return (388 <div>389 <Shell className={"iframe-hack"} style={{ border: "1px solid #eee" }}>390 <Shell.Content>391 <div style={{ minHeight: 1200, background: "#fff" }}>392 <pre>393 {394 this.log !== null && this.log.length > 0 && (395 this.log.map((value, index) => {396 return (<div key={index}><span>{value.line}</span><br/></div>)397 })398 )399 }400 </pre>401 </div>402 </Shell.Content>403 </Shell>404 </div>405 );406 }407}...
object-utils.js
Source:object-utils.js
1/*2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.4 */5/**6 * utility methods to process coverage objects. A coverage object has the following7 * format.8 *9 * {10 * "/path/to/file1.js": { file1 coverage },11 * "/path/to/file2.js": { file2 coverage }12 * }13 *14 * The internals of the file coverage object are intentionally not documented since15 * it is not a public interface.16 *17 * *Note:* When a method of this module has the word `File` in it, it will accept18 * one of the sub-objects of the main coverage object as an argument. Other19 * methods accept the higher level coverage object with multiple keys.20 *21 * Works on `node` as well as the browser.22 *23 * Usage on nodejs24 * ---------------25 *26 * var objectUtils = require('istanbul').utils;27 *28 * Usage in a browser29 * ------------------30 *31 * Load this file using a `script` tag or other means. This will set `window.coverageUtils`32 * to this module's exports.33 *34 * @class ObjectUtils35 * @module main36 * @static37 */38(function (isNode) {39 /**40 * adds line coverage information to a file coverage object, reverse-engineering41 * it from statement coverage. The object passed in is updated in place.42 *43 * Note that if line coverage information is already present in the object,44 * it is not recomputed.45 *46 * @method addDerivedInfoForFile47 * @static48 * @param {Object} fileCoverage the coverage object for a single file49 */50 function addDerivedInfoForFile(fileCoverage) {51 var statementMap = fileCoverage.statementMap,52 statements = fileCoverage.s,53 lineMap;54 if (!fileCoverage.l) {55 fileCoverage.l = lineMap = {};56 Object.keys(statements).forEach(function (st) {57 var line = statementMap[st].start.line,58 count = statements[st],59 prevVal = lineMap[line];60 if (count === 0 && statementMap[st].skip) { count = 1; }61 if (typeof prevVal === 'undefined' || prevVal < count) {62 lineMap[line] = count;63 }64 });65 }66 }67 /**68 * adds line coverage information to all file coverage objects.69 *70 * @method addDerivedInfo71 * @static72 * @param {Object} coverage the coverage object73 */74 function addDerivedInfo(coverage) {75 Object.keys(coverage).forEach(function (k) {76 addDerivedInfoForFile(coverage[k]);77 });78 }79 /**80 * removes line coverage information from all file coverage objects81 * @method removeDerivedInfo82 * @static83 * @param {Object} coverage the coverage object84 */85 function removeDerivedInfo(coverage) {86 Object.keys(coverage).forEach(function (k) {87 delete coverage[k].l;88 });89 }90 function percent(covered, total) {91 var tmp;92 if (total > 0) {93 tmp = 1000 * 100 * covered / total + 5;94 return Math.floor(tmp / 10) / 100;95 } else {96 return 100.00;97 }98 }99 function computeSimpleTotals(fileCoverage, property, mapProperty) {100 var stats = fileCoverage[property],101 map = mapProperty ? fileCoverage[mapProperty] : null,102 ret = { total: 0, covered: 0, skipped: 0 };103 Object.keys(stats).forEach(function (key) {104 var covered = !!stats[key],105 skipped = map && map[key].skip;106 ret.total += 1;107 if (covered || skipped) {108 ret.covered += 1;109 }110 if (!covered && skipped) {111 ret.skipped += 1;112 }113 });114 ret.pct = percent(ret.covered, ret.total);115 return ret;116 }117 function computeBranchTotals(fileCoverage) {118 var stats = fileCoverage.b,119 branchMap = fileCoverage.branchMap,120 ret = { total: 0, covered: 0, skipped: 0 };121 Object.keys(stats).forEach(function (key) {122 var branches = stats[key],123 map = branchMap[key],124 covered,125 skipped,126 i;127 for (i = 0; i < branches.length; i += 1) {128 covered = branches[i] > 0;129 skipped = map.locations && map.locations[i] && map.locations[i].skip;130 if (covered || skipped) {131 ret.covered += 1;132 }133 if (!covered && skipped) {134 ret.skipped += 1;135 }136 }137 ret.total += branches.length;138 });139 ret.pct = percent(ret.covered, ret.total);140 return ret;141 }142 /**143 * returns a blank summary metrics object. A metrics object has the following144 * format.145 *146 * {147 * lines: lineMetrics,148 * statements: statementMetrics,149 * functions: functionMetrics,150 * branches: branchMetrics151 * linesCovered: lineCoveredCount152 * }153 *154 * Each individual metric object looks as follows:155 *156 * {157 * total: n,158 * covered: m,159 * pct: percent160 * }161 *162 * @method blankSummary163 * @static164 * @return {Object} a blank metrics object165 */166 function blankSummary() {167 return {168 lines: {169 total: 0,170 covered: 0,171 skipped: 0,172 pct: 'Unknown'173 },174 statements: {175 total: 0,176 covered: 0,177 skipped: 0,178 pct: 'Unknown'179 },180 functions: {181 total: 0,182 covered: 0,183 skipped: 0,184 pct: 'Unknown'185 },186 branches: {187 total: 0,188 covered: 0,189 skipped: 0,190 pct: 'Unknown'191 },192 linesCovered: {}193 };194 }195 /**196 * returns the summary metrics given the coverage object for a single file. See `blankSummary()`197 * to understand the format of the returned object.198 *199 * @method summarizeFileCoverage200 * @static201 * @param {Object} fileCoverage the coverage object for a single file.202 * @return {Object} the summary metrics for the file203 */204 function summarizeFileCoverage(fileCoverage) {205 var ret = blankSummary();206 addDerivedInfoForFile(fileCoverage);207 ret.lines = computeSimpleTotals(fileCoverage, 'l');208 ret.functions = computeSimpleTotals(fileCoverage, 'f', 'fnMap');209 ret.statements = computeSimpleTotals(fileCoverage, 's', 'statementMap');210 ret.branches = computeBranchTotals(fileCoverage);211 ret.linesCovered = fileCoverage.l;212 return ret;213 }214 /**215 * merges two instances of file coverage objects *for the same file*216 * such that the execution counts are correct.217 *218 * @method mergeFileCoverage219 * @static220 * @param {Object} first the first file coverage object for a given file221 * @param {Object} second the second file coverage object for the same file222 * @return {Object} an object that is a result of merging the two. Note that223 * the input objects are not changed in any way.224 */225 function mergeFileCoverage(first, second) {226 var ret = JSON.parse(JSON.stringify(first)),227 i;228 delete ret.l; //remove derived info229 Object.keys(second.s).forEach(function (k) {230 ret.s[k] += second.s[k];231 });232 Object.keys(second.f).forEach(function (k) {233 ret.f[k] += second.f[k];234 });235 Object.keys(second.b).forEach(function (k) {236 var retArray = ret.b[k],237 secondArray = second.b[k];238 for (i = 0; i < retArray.length; i += 1) {239 retArray[i] += secondArray[i];240 }241 });242 return ret;243 }244 /**245 * merges multiple summary metrics objects by summing up the `totals` and246 * `covered` fields and recomputing the percentages. This function is generic247 * and can accept any number of arguments.248 *249 * @method mergeSummaryObjects250 * @static251 * @param {Object} summary... multiple summary metrics objects252 * @return {Object} the merged summary metrics253 */254 function mergeSummaryObjects() {255 var ret = blankSummary(),256 args = Array.prototype.slice.call(arguments),257 keys = ['lines', 'statements', 'branches', 'functions'],258 increment = function (obj) {259 if (obj) {260 keys.forEach(function (key) {261 ret[key].total += obj[key].total;262 ret[key].covered += obj[key].covered;263 ret[key].skipped += obj[key].skipped;264 });265 // keep track of all lines we have coverage for.266 Object.keys(obj.linesCovered).forEach(function (key) {267 if (!ret.linesCovered[key]) {268 ret.linesCovered[key] = obj.linesCovered[key];269 } else {270 ret.linesCovered[key] += obj.linesCovered[key];271 }272 });273 }274 };275 args.forEach(function (arg) {276 increment(arg);277 });278 keys.forEach(function (key) {279 ret[key].pct = percent(ret[key].covered, ret[key].total);280 });281 return ret;282 }283 /**284 * returns the coverage summary for a single coverage object. This is285 * wrapper over `summarizeFileCoverage` and `mergeSummaryObjects` for286 * the common case of a single coverage object287 * @method summarizeCoverage288 * @static289 * @param {Object} coverage the coverage object290 * @return {Object} summary coverage metrics across all files in the coverage object291 */292 function summarizeCoverage(coverage) {293 var fileSummary = [];294 Object.keys(coverage).forEach(function (key) {295 fileSummary.push(summarizeFileCoverage(coverage[key]));296 });297 return mergeSummaryObjects.apply(null, fileSummary);298 }299 /**300 * makes the coverage object generated by this library yuitest_coverage compatible.301 * Note that this transformation is lossy since the returned object will not have302 * statement and branch coverage.303 *304 * @method toYUICoverage305 * @static306 * @param {Object} coverage The `istanbul` coverage object307 * @return {Object} a coverage object in `yuitest_coverage` format.308 */309 function toYUICoverage(coverage) {310 var ret = {};311 addDerivedInfo(coverage);312 Object.keys(coverage).forEach(function (k) {313 var fileCoverage = coverage[k],314 lines = fileCoverage.l,315 functions = fileCoverage.f,316 fnMap = fileCoverage.fnMap,317 o;318 o = ret[k] = {319 lines: {},320 calledLines: 0,321 coveredLines: 0,322 functions: {},323 calledFunctions: 0,324 coveredFunctions: 0325 };326 Object.keys(lines).forEach(function (k) {327 o.lines[k] = lines[k];328 o.coveredLines += 1;329 if (lines[k] > 0) {330 o.calledLines += 1;331 }332 });333 Object.keys(functions).forEach(function (k) {334 var name = fnMap[k].name + ':' + fnMap[k].line;335 o.functions[name] = functions[k];336 o.coveredFunctions += 1;337 if (functions[k] > 0) {338 o.calledFunctions += 1;339 }340 });341 });342 return ret;343 }344 /**345 * Creates new file coverage object with incremented hits count346 * on skipped statements, branches and functions347 *348 * @method incrementIgnoredTotals349 * @static350 * @param {Object} cov File coverage object351 * @return {Object} New file coverage object352 */353 function incrementIgnoredTotals(cov) {354 //TODO: This may be slow in the browser and may break in older browsers355 // Look into using a library that works in Node and the browser356 var fileCoverage = JSON.parse(JSON.stringify(cov));357 [358 {mapKey: 'statementMap', hitsKey: 's'},359 {mapKey: 'branchMap', hitsKey: 'b'},360 {mapKey: 'fnMap', hitsKey: 'f'}361 ].forEach(function (keys) {362 Object.keys(fileCoverage[keys.mapKey])363 .forEach(function (key) {364 var map = fileCoverage[keys.mapKey][key];365 var hits = fileCoverage[keys.hitsKey];366 if (keys.mapKey === 'branchMap') {367 var locations = map.locations;368 locations.forEach(function (location, index) {369 if (hits[key][index] === 0 && location.skip) {370 hits[key][index] = 1;371 }372 });373 return;374 }375 if (hits[key] === 0 && map.skip) {376 hits[key] = 1;377 }378 });379 });380 return fileCoverage;381 }382 var exportables = {383 addDerivedInfo: addDerivedInfo,384 addDerivedInfoForFile: addDerivedInfoForFile,385 removeDerivedInfo: removeDerivedInfo,386 blankSummary: blankSummary,387 summarizeFileCoverage: summarizeFileCoverage,388 summarizeCoverage: summarizeCoverage,389 mergeFileCoverage: mergeFileCoverage,390 mergeSummaryObjects: mergeSummaryObjects,391 toYUICoverage: toYUICoverage,392 incrementIgnoredTotals: incrementIgnoredTotals393 };394 /* istanbul ignore else: windows */395 if (isNode) {396 module.exports = exportables;397 } else {398 window.coverageUtils = exportables;399 }...
test-object-utils.js
Source:test-object-utils.js
1/*jslint nomen: true */2var utils = require('../../lib/object-utils'),3 it,4 it2,5 it3;6module.exports = {7 "with some coverage info": {8 setUp: function (cb) {9 it = {10 foo: {11 s: {12 1: 1,13 2: 2,14 3: 3,15 4: 416 },17 statementMap: {18 1: { start: { line: 1, column: 1}, end: { line: 1, column: 10 }},19 2: { start: { line: 2, column: 1}, end: { line: 1, column: 9 }},20 3: { start: { line: 2, column: 10 }, end: { line: 2, column: 20 }},21 4: { start: { line: 7, column: 0 }, end: { line: 40, column: 10 }}22 }23 }24 };25 cb();26 },27 "should add/ remove derived coverage correctly": function (test) {28 utils.addDerivedInfo(it);29 var l = it.foo.l;30 test.ok(l);31 test.equals(3, Object.keys(l).length);32 test.equals(1, l[1]);33 test.equals(3, l[2]);34 test.equals(4, l[7]);35 l[7] = 0;36 utils.addDerivedInfo(it);37 test.equals(0, it.foo.l[7]); //does not change38 utils.removeDerivedInfo(it);39 test.ok(!it.foo.l);40 test.done();41 }42 },43 "with full coverage info": {44 setUp: function (cb) {45 it = {46 foo: {47 s: {48 1: 1,49 2: 2,50 3: 3,51 4: 4,52 5: 053 },54 statementMap: {55 1: { start: { line: 1, column: 1}, end: { line: 1, column: 10 }},56 2: { start: { line: 2, column: 1}, end: { line: 1, column: 9 }},57 3: { start: { line: 2, column: 10 }, end: { line: 2, column: 20 }},58 4: { start: { line: 7, column: 0 }, end: { line: 40, column: 10 }},59 5: { start: { line: 41, column: 0 }, end: { line: 42, column: 10 }}60 },61 f: {62 1: 10,63 2: 064 },65 fnMap: {66 1: { name: 'foo', line: 1 },67 2: { name: 'anonymous_1', line: 7 }68 },69 b: {70 1: [ 10, 0, 2],71 2: [ 0, 0]72 },73 branchMap: {74 1: { line: 2, type: 'switch', locations: [ ] },75 2: { line: 3, type: 'if', locations: [ ] }76 }77 }78 };79 it2 = it;80 it3 = {81 foo: {82 s: {83 1: 2,84 2: 1,85 3: 78,86 4: 99,87 5: 088 },89 statementMap: {90 1: { start: { line: 1, column: 1}, end: { line: 1, column: 10 }},91 2: { start: { line: 2, column: 1}, end: { line: 1, column: 9 }},92 3: { start: { line: 2, column: 10 }, end: { line: 2, column: 20 }},93 4: { start: { line: 7, column: 0 }, end: { line: 40, column: 10 }},94 5: { start: { line: 41, column: 0 }, end: { line: 42, column: 10 }}95 },96 f: {97 1: 9,98 2: 199 },100 fnMap: {101 1: { name: 'foo', line: 1 },102 2: { name: 'anonymous_1', line: 7 }103 },104 b: {105 1: [ 0, 1, 1],106 2: [ 3, 0]107 },108 branchMap: {109 1: { line: 2, type: 'switch', locations: [ ] },110 2: { line: 3, type: 'if', locations: [ ] }111 }112 }113 };114 cb();115 },116 "should calculate correct summary": function (test) {117 var ret = utils.summarizeFileCoverage(it.foo);118 test.deepEqual({ total: 4, covered: 3, pct: 75, skipped: 0 }, ret.lines);119 test.deepEqual({ total: 5, covered: 4, pct: 80, skipped: 0 }, ret.statements);120 test.deepEqual({ total: 2, covered: 1, pct: 50, skipped: 0 }, ret.functions);121 test.deepEqual({ total: 5, covered: 2, pct: 40, skipped: 0 }, ret.branches);122 test.done();123 },124 "should return a pct of 100 when nothing is available": function (test) {125 it.foo.b = {};126 var ret = utils.summarizeFileCoverage(it.foo);127 test.deepEqual({ total: 4, covered: 3, pct: 75, skipped: 0 }, ret.lines);128 test.deepEqual({ total: 5, covered: 4, pct: 80, skipped: 0 }, ret.statements);129 test.deepEqual({ total: 2, covered: 1, pct: 50, skipped: 0 }, ret.functions);130 test.deepEqual({ total: 0, covered: 0, pct: 100, skipped: 0 }, ret.branches);131 test.done();132 },133 "should merge summary correctly": function (test) {134 var s1 = utils.summarizeFileCoverage(it.foo),135 s2 = utils.summarizeFileCoverage(it2.foo),136 ret = utils.mergeSummaryObjects(s1, s2);137 test.deepEqual({ total: 8, covered: 6, pct: 75, skipped: 0 }, ret.lines);138 test.deepEqual({ total: 10, covered: 8, pct: 80, skipped: 0 }, ret.statements);139 test.deepEqual({ total: 4, covered: 2, pct: 50, skipped: 0 }, ret.functions);140 test.deepEqual({ total: 10, covered: 4, pct: 40, skipped: 0 }, ret.branches);141 test.done();142 },143 "should merge summary correctly in one call": function (test) {144 var coverage = { foo: it.foo, 'bar': it2.foo },145 ret = utils.summarizeCoverage(coverage);146 test.deepEqual({ total: 8, covered: 6, pct: 75, skipped: 0 }, ret.lines);147 test.deepEqual({ total: 10, covered: 8, pct: 80, skipped: 0 }, ret.statements);148 test.deepEqual({ total: 4, covered: 2, pct: 50, skipped: 0 }, ret.functions);149 test.deepEqual({ total: 10, covered: 4, pct: 40, skipped: 0 }, ret.branches);150 test.done();151 },152 "can merge with a blank object in first position": function (test) {153 var s1 = null,154 s2 = utils.summarizeFileCoverage(it2.foo),155 ret = utils.mergeSummaryObjects(s1, s2);156 test.deepEqual({ total: 4, covered: 3, pct: 75, skipped: 0 }, ret.lines);157 test.deepEqual({ total: 5, covered: 4, pct: 80, skipped: 0 }, ret.statements);158 test.deepEqual({ total: 2, covered: 1, pct: 50, skipped: 0 }, ret.functions);159 test.deepEqual({ total: 5, covered: 2, pct: 40, skipped: 0 }, ret.branches);160 test.done();161 },162 "can merge with a blank object in second position": function (test) {163 var s1 = utils.summarizeFileCoverage(it2.foo),164 s2 = null,165 ret = utils.mergeSummaryObjects(s1, s2);166 test.deepEqual({ total: 4, covered: 3, pct: 75, skipped: 0 }, ret.lines);167 test.deepEqual({ total: 5, covered: 4, pct: 80, skipped: 0 }, ret.statements);168 test.deepEqual({ total: 2, covered: 1, pct: 50, skipped: 0 }, ret.functions);169 test.deepEqual({ total: 5, covered: 2, pct: 40, skipped: 0 }, ret.branches);170 test.done();171 },172 "can turn it into a YUI coverage object": function (test) {173 var ret = utils.toYUICoverage(it);174 test.deepEqual({ '1': 1, '2': 3, '7': 4, '41': 0 }, ret.foo.lines);175 test.deepEqual({ 'foo:1': 10, 'anonymous_1:7': 0 }, ret.foo.functions);176 test.equal(3, ret.foo.calledLines);177 test.equal(4, ret.foo.coveredLines);178 test.equal(1, ret.foo.calledFunctions);179 test.equal(2, ret.foo.coveredFunctions);180 test.done();181 },182 "merge two like coverage objects for the same file correctly": function (test) {183 var base = JSON.parse(JSON.stringify(it.foo)),184 ret = utils.mergeFileCoverage(base, it3.foo),185 foo = it.foo;186 foo.s[1] += 2;187 foo.s[2] += 1;188 foo.s[3] += 78;189 foo.s[4] += 99;190 foo.f[1] += 9;191 foo.f[2] += 1;192 foo.b[1][1] += 1;193 foo.b[1][2] += 1;194 foo.b[2][0] += 3;195 test.deepEqual(ret, foo);196 test.done();197 }198 }...
covered_index_negative_1.js
Source:covered_index_negative_1.js
1// Miscellaneous covered query tests. Mostly negative tests2// These are tests where we do not expect the query to be a3// covered index query. Hence we expect indexOnly=false and4// nscannedObjects > 05var coll = db.getCollection("covered_negative_1")6coll.drop()7for (i=0;i<100;i++) {8 coll.insert({a:i, b:"strvar_"+(i%13), c:NumberInt(i%10), d: i*10, e: [i, i%10],9 f:i})10}11coll.ensureIndex({a:1,b:-1,c:1})12coll.ensureIndex({e:1})13coll.ensureIndex({d:1})14coll.ensureIndex({f:"hashed"})15// Test no projection16var plan = coll.find({a:10, b:"strvar_10", c:0}).hint({a:1, b:-1, c:1}).explain()17assert.eq(false, plan.indexOnly, "negative.1.1 - indexOnly should be false on a non covered query")18assert.neq(0, plan.nscannedObjects, "negative.1.1 - nscannedObjects should not be 0 for a non covered query")19// Test projection and not excluding _id20var plan = coll.find({a:10, b:"strvar_10", c:0},{a:1, b:1, c:1}).hint({a:1, b:-1, c:1}).explain()21assert.eq(false, plan.indexOnly, "negative.1.2 - indexOnly should be false on a non covered query")22assert.neq(0, plan.nscannedObjects, "negative.1.2 - nscannedObjects should not be 0 for a non covered query")23// Test projection of non-indexed field24var plan = coll.find({d:100},{d:1, c:1, _id:0}).hint({d:1}).explain()25assert.eq(false, plan.indexOnly, "negative.1.3 - indexOnly should be false on a non covered query")26assert.neq(0, plan.nscannedObjects, "negative.1.3 - nscannedObjects should not be 0 for a non covered query")27// Test query and projection on a multi-key index28var plan = coll.find({e:99},{e:1, _id:0}).hint({e:1}).explain()29assert.eq(false, plan.indexOnly, "negative.1.4 - indexOnly should be false on a non covered query")30assert.neq(0, plan.nscannedObjects, "negative.1.4 - nscannedObjects should not be 0 for a non covered query")31// Commenting out negative.1.5 and 1.6 pending fix in SERVER-865032// // Test projection and $natural sort33// var plan = coll.find({a:{$gt:70}},{a:1, b:1, c:1, _id:0}).sort({$natural:1}).hint({a:1, b:-1, c:1}).explain()34// // indexOnly should be false but is not due to bug https://jira.mongodb.org/browse/SERVER-856135// assert.eq(true, plan.indexOnly, "negative.1.5 - indexOnly should be false on a non covered query")36// assert.neq(0, plan.nscannedObjects, "negative.1.5 - nscannedObjects should not be 0 for a non covered query")37// // Test sort on non-indexed field38// var plan = coll.find({d:{$lt:1000}},{d:1, _id:0}).sort({c:1}).hint({d:1}).explain()39// //indexOnly should be false but is not due to bug https://jira.mongodb.org/browse/SERVER-856240// assert.eq(true, plan.indexOnly, "negative.1.6 - indexOnly should be false on a non covered query")41// assert.neq(0, plan.nscannedObjects, "negative.1.6 - nscannedObjects should not be 0 for a non covered query")42// Test query on non-indexed field43var plan = coll.find({d:{$lt:1000}},{a:1, b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()44//indexOnly should be false but is not due to bug https://jira.mongodb.org/browse/SERVER-856245assert.eq(true, plan.indexOnly, "negative.1.7 - indexOnly should be false on a non covered query")46assert.neq(0, plan.nscannedObjects, "negative.1.7 - nscannedObjects should not be 0 for a non covered query")47// Test query on hashed indexed field48var plan = coll.find({f:10},{f:1, _id:0}).hint({f:"hashed"}).explain()49assert.eq(false, plan.indexOnly, "negative.1.8 - indexOnly should be false on a non covered query")50assert.neq(0, plan.nscannedObjects, "negative.1.8 - nscannedObjects should not be 0 for a non covered query")...
covered_index_simple_3.js
Source:covered_index_simple_3.js
1// Simple covered index query test with a unique sparse index2var coll = db.getCollection("covered_simple_3")3coll.drop()4for (i=0;i<10;i++) {5 coll.insert({foo:i})6}7for (i=0;i<5;i++) {8 coll.insert({bar:i})9}10coll.insert({foo:"string"})11coll.insert({foo:{bar:1}})12coll.insert({foo:null})13coll.ensureIndex({foo:1}, {sparse:true, unique:true})14// Test equality with int value15var plan = coll.find({foo:1}, {foo:1, _id:0}).hint({foo:1}).explain()16assert.eq(true, plan.indexOnly, "simple.3.1 - indexOnly should be true on covered query")17assert.eq(0, plan.nscannedObjects, "simple.3.1 - nscannedObjects should be 0 for covered query")18// Test equality with string value19var plan = coll.find({foo:"string"}, {foo:1, _id:0}).hint({foo:1}).explain()20assert.eq(true, plan.indexOnly, "simple.3.2 - indexOnly should be true on covered query")21assert.eq(0, plan.nscannedObjects, "simple.3.2 - nscannedObjects should be 0 for covered query")22// Test equality with int value on a dotted field23var plan = coll.find({foo:{bar:1}}, {foo:1, _id:0}).hint({foo:1}).explain()24assert.eq(true, plan.indexOnly, "simple.3.3 - indexOnly should be true on covered query")25assert.eq(0, plan.nscannedObjects, "simple.3.3 - nscannedObjects should be 0 for covered query")26// Test no query27var plan = coll.find({}, {foo:1, _id:0}).hint({foo:1}).explain()28assert.eq(true, plan.indexOnly, "simple.3.4 - indexOnly should be true on covered query")29assert.eq(0, plan.nscannedObjects, "simple.3.4 - nscannedObjects should be 0 for covered query")30// Test range query31var plan = coll.find({foo:{$gt:2,$lt:6}}, {foo:1, _id:0}).hint({foo:1}).explain()32assert.eq(true, plan.indexOnly, "simple.3.5 - indexOnly should be true on covered query")33assert.eq(0, plan.nscannedObjects, "simple.3.5 - nscannedObjects should be 0 for covered query")34// Test in query35var plan = coll.find({foo:{$in:[5,8]}}, {foo:1, _id:0}).hint({foo:1}).explain()36assert.eq(true, plan.indexOnly, "simple.3.6 - indexOnly should be true on covered query")37assert.eq(0, plan.nscannedObjects, "simple.3.6 - nscannedObjects should be 0 for covered query")38// Test exists query39var plan = coll.find({foo:{$exists:true}}, {foo:1, _id:0}).hint({foo:1}).explain()40assert.eq(true, plan.indexOnly, "simple.3.7 - indexOnly should be true on covered query")41// this should be 0 but is not due to bug https://jira.mongodb.org/browse/SERVER-318742assert.eq(13, plan.nscannedObjects, "simple.3.7 - nscannedObjects should be 0 for covered query")43// Test not in query44var plan = coll.find({foo:{$nin:[5,8]}}, {foo:1, _id:0}).hint({foo:1}).explain()45assert.eq(true, plan.indexOnly, "simple.3.8 - indexOnly should be true on covered query")46// this should be 0 but is not due to bug https://jira.mongodb.org/browse/SERVER-318747assert.eq(13, plan.nscannedObjects, "simple.3.8 - nscannedObjects should be 0 for covered query")...
covered_index_simple_1.js
Source:covered_index_simple_1.js
1// Simple covered index query test2var coll = db.getCollection("covered_simple_1")3coll.drop()4for (i=0;i<10;i++) {5 coll.insert({foo:i})6}7for (i=0;i<10;i++) {8 coll.insert({foo:i})9}10for (i=0;i<5;i++) {11 coll.insert({bar:i})12}13coll.insert({foo:"string"})14coll.insert({foo:{bar:1}})15coll.insert({foo:null})16coll.ensureIndex({foo:1})17// Test equality with int value18var plan = coll.find({foo:1}, {foo:1, _id:0}).hint({foo:1}).explain()19assert.eq(true, plan.indexOnly, "simple.1.1 - indexOnly should be true on covered query")20assert.eq(0, plan.nscannedObjects, "simple.1.1 - nscannedObjects should be 0 for covered query")21// Test equality with string value22var plan = coll.find({foo:"string"}, {foo:1, _id:0}).hint({foo:1}).explain()23assert.eq(true, plan.indexOnly, "simple.1.2 - indexOnly should be true on covered query")24assert.eq(0, plan.nscannedObjects, "simple.1.2 - nscannedObjects should be 0 for covered query")25// Test equality with doc value26var plan = coll.find({foo:{bar:1}}, {foo:1, _id:0}).hint({foo:1}).explain()27assert.eq(true, plan.indexOnly, "simple.1.3 - indexOnly should be true on covered query")28assert.eq(0, plan.nscannedObjects, "simple.1.3 - nscannedObjects should be 0 for covered query")29// Test no query30var plan = coll.find({}, {foo:1, _id:0}).hint({foo:1}).explain()31assert.eq(true, plan.indexOnly, "simple.1.4 - indexOnly should be true on covered query")32assert.eq(0, plan.nscannedObjects, "simple.1.4 - nscannedObjects should be 0 for covered query")33// Test range query34var plan = coll.find({foo:{$gt:2,$lt:6}}, {foo:1, _id:0}).hint({foo:1}).explain()35assert.eq(true, plan.indexOnly, "simple.1.5 - indexOnly should be true on covered query")36assert.eq(0, plan.nscannedObjects, "simple.1.5 - nscannedObjects should be 0 for covered query")37// Test in query38var plan = coll.find({foo:{$in:[5,8]}}, {foo:1, _id:0}).hint({foo:1}).explain()39assert.eq(true, plan.indexOnly, "simple.1.6 - indexOnly should be true on covered query")40assert.eq(0, plan.nscannedObjects, "simple.1.6 - nscannedObjects should be 0 for covered query")41// Test no return42var plan = coll.find({foo:"2"}, {foo:1, _id:0}).hint({foo:1}).explain()43assert.eq(true, plan.indexOnly, "simple.1.7 - indexOnly should be true on covered query")44assert.eq(0, plan.nscannedObjects, "simple.1.7 - nscannedObjects should be 0 for covered query")45// Test not in query46var plan = coll.find({foo:{$nin:[5,8]}}, {foo:1, _id:0}).hint({foo:1}).explain()47assert.eq(true, plan.indexOnly, "simple.1.8 - indexOnly should be true on covered query")48// This should be 0 but is not due to be bug https://jira.mongodb.org/browse/SERVER-318749assert.eq(28, plan.nscannedObjects, "simple.1.8 - nscannedObjects should be 0 for covered query")...
covered_index_compound_1.js
Source:covered_index_compound_1.js
1// Compound index covered query tests2var coll = db.getCollection("covered_compound_1")3coll.drop()4for (i=0;i<100;i++) {5 coll.insert({a:i, b:"strvar_"+(i%13), c:NumberInt(i%10)})6}7coll.ensureIndex({a:1,b:-1,c:1})8// Test equality - all indexed fields queried and projected9var plan = coll.find({a:10, b:"strvar_10", c:0}, {a:1, b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()10assert.eq(true, plan.indexOnly, "compound.1.1 - indexOnly should be true on covered query")11assert.eq(0, plan.nscannedObjects, "compound.1.1 - nscannedObjects should be 0 for covered query")12// Test query on subset of fields queried and project all13var plan = coll.find({a:26, b:"strvar_0"}, {a:1, b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()14assert.eq(true, plan.indexOnly, "compound.1.2 - indexOnly should be true on covered query")15assert.eq(0, plan.nscannedObjects, "compound.1.2 - nscannedObjects should be 0 for covered query")16// Test query on all fields queried and project subset17var plan = coll.find({a:38, b:"strvar_12", c: 8}, {b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()18assert.eq(true, plan.indexOnly, "compound.1.3 - indexOnly should be true on covered query")19assert.eq(0, plan.nscannedObjects, "compound.1.3 - nscannedObjects should be 0 for covered query")20// Test no query21var plan = coll.find({}, {b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()22assert.eq(true, plan.indexOnly, "compound.1.4 - indexOnly should be true on covered query")23assert.eq(0, plan.nscannedObjects, "compound.1.4 - nscannedObjects should be 0 for covered query")24// Test range query25var plan = coll.find({a:{$gt:25,$lt:43}}, {b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()26assert.eq(true, plan.indexOnly, "compound.1.5 - indexOnly should be true on covered query")27assert.eq(0, plan.nscannedObjects, "compound.1.5 - nscannedObjects should be 0 for covered query")28// Test in query29var plan = coll.find({a:38, b:"strvar_12", c:{$in:[5,8]}}, {b:1, c:1, _id:0}).hint({a:1, b:-1, c:1}).explain()30assert.eq(true, plan.indexOnly, "compound.1.6 - indexOnly should be true on covered query")31assert.eq(0, plan.nscannedObjects, "compound.1.6 - nscannedObjects should be 0 for covered query")32// Test no result33var plan = coll.find({a:38, b:"strvar_12", c:55},{a:1, b:1, c:1}).hint({a:1, b:-1, c:1}).explain()34// This should be a covered query but has indexOnly=false due to https://jira.mongodb.org/browse/SERVER-856035assert.eq(false, plan.indexOnly, "compound.1.7 - indexOnly should be true on covered query")36assert.eq(0, plan.nscannedObjects, "compound.1.7 - nscannedObjects should be 0 for covered query")...
covered_index_simple_id.js
Source:covered_index_simple_id.js
1// Simple covered index query test2var coll = db.getCollection("covered_simple_id")3coll.drop()4for (i=0;i<10;i++) {5 coll.insert({_id:i})6}7coll.insert({_id:"string"})8coll.insert({_id:{bar:1}})9coll.insert({_id:null})10// Test equality with int value11var plan = coll.find({_id:1}, {_id:1}).hint({_id:1}).explain()12assert.eq(true, plan.indexOnly, "simple.id.1 - indexOnly should be true on covered query")13assert.eq(0, plan.nscannedObjects, "simple.id.1 - nscannedObjects should be 0 for covered query")14// Test equality with string value15var plan = coll.find({_id:"string"}, {_id:1}).hint({_id:1}).explain()16assert.eq(true, plan.indexOnly, "simple.id.2 - indexOnly should be true on covered query")17assert.eq(0, plan.nscannedObjects, "simple.id.2 - nscannedObjects should be 0 for covered query")18// Test equality with int value on a dotted field19var plan = coll.find({_id:{bar:1}}, {_id:1}).hint({_id:1}).explain()20assert.eq(true, plan.indexOnly, "simple.id.3 - indexOnly should be true on covered query")21assert.eq(0, plan.nscannedObjects, "simple.id.3 - nscannedObjects should be 0 for covered query")22// Test no query23var plan = coll.find({}, {_id:1}).hint({_id:1}).explain()24assert.eq(true, plan.indexOnly, "simple.id.4 - indexOnly should be true on covered query")25assert.eq(0, plan.nscannedObjects, "simple.id.4 - nscannedObjects should be 0 for covered query")26// Test range query27var plan = coll.find({_id:{$gt:2,$lt:6}}, {_id:1}).hint({_id:1}).explain()28assert.eq(true, plan.indexOnly, "simple.id.5 - indexOnly should be true on covered query")29assert.eq(0, plan.nscannedObjects, "simple.id.5 - nscannedObjects should be 0 for covered query")30// Test in query31var plan = coll.find({_id:{$in:[5,8]}}, {_id:1}).hint({_id:1}).explain()32assert.eq(true, plan.indexOnly, "simple.id.6 - indexOnly should be true on covered query")33assert.eq(0, plan.nscannedObjects, "simple.id.6 - nscannedObjects should be 0 for covered query")34// Test not in query35var plan = coll.find({_id:{$nin:[5,8]}}, {_id:1}).hint({_id:1}).explain()36assert.eq(true, plan.indexOnly, "simple.id.7 - indexOnly should be true on covered query")37// this should be 0 but is not due to bug https://jira.mongodb.org/browse/SERVER-318738assert.eq(13, plan.nscannedObjects, "simple.id.7 - nscannedObjects should be 0 for covered query")...
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.
|<p>it('check_object_of_Car', () => {</p><p>
expect(newCar()).toBeInstanceOf(Car);</p><p>
});</p>|
| :- |
Get 100 minutes of automation test minutes FREE!!