Using Cypress, how would I write a simple test to check that a logo image exists on a page

I figured out the solution on my own. cy.get(‘form’).find(‘img’).should(‘have.attr’, ‘src’).should(‘include’,’My-Logo’) I inspected the element and found the <img src… line was embedded within a <form>. I could do a cy.get(‘form’) and pass, but could not do a cy.get(‘img’) to pass. So then I chained them together and it passed. I am not sure why I … Read more

Mongoose – RangeError: Maximum Call Stack Size Exceeded

I was having this same issue and I started digging through the mongoose source code (version 3.8.14). Eventually it led me to this line within mongoose/node_modules/mongodb/lib/mongodb/collection/core.js -> insert(…) -> insertWithWriteCommands(…) -> mongoose/node_modules/mongodb/lib/mongodb/collection/batch/ordered.js -> bulk.insert(docs[i]) -> addToOperationsList(…) -> bson.calculateObjectSize(document, false); var bsonSize = bson.calculateObjectSize(document, false); Apparently, this calls BSON.calculateObjectSize, which calls calculateObjectSize which then infinitely recurses. … Read more

How do you edit existing text (and move the cursor around) in the terminal?

Finally found that “demo”: https://github.com/asyncly/cdir/blob/223fe0039fade4fad2bb08c2f7affac3bdcf2f89/cdir.js#L24 http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html http://ascii-table.com/ansi-escape-sequences-vt-100.php Position the Cursor: \u001b[<L>;<C>H or \u001b[<L>;<C>f (puts the cursor at line L and column C) Move the cursor up N lines: \u001b[<N>A Move the cursor down N lines: \u001b[<N>B Move the cursor forward N columns: \u001b[<N>C Move the cursor backward N columns: \u001b[<N>D Clear the screen, move to … Read more

What’s the best way to unit test an event being emitted in Nodejs?

If you can guarantee that the event should fire within a certain amount of time, then simply set a timeout. it(‘should emit an some_event’, function(done){ this.timeout(1000); //timeout with an error if done() isn’t called within one second myObj.on(‘some_event’,function(){ // perform any other assertions you want here done(); }); // execute some code which should trigger … Read more

Using nodejs’s spawn causes “unknown option — ” and “[Error: spawn ENOENT]” errors

After lots of trying different things, I finally had a look at what “npm” actually is on windows, and it turns out to be a bash script called npm, as well as a windows-native batch script called npm.cmd (no idea why it’s .cmd, that should be .bat, but there you have it). Windows’s command resolver … Read more

How to read csv file in node js

Use a library, CSV has lots of gotchas. I have come to enjoy the package csv. It is located here: https://www.npmjs.com/package/csv . Here is a very quick example using the async api. const fs = require(‘fs’) var parse = require(‘csv-parse’) fs.readFile(inputPath, function (err, fileData) { parse(fileData, {columns: false, trim: true}, function(err, rows) { // Your … Read more

Is Node.js Array.map() asynchronous?

JavaScript is also a functional programming language. What you have here is a «higher order function», a function which takes a function as a parameter. Higher order functions are synchronous (but see note below). Sources: Functional Programming Higher order functions in JavaScript map() is a typical example of a higher order function. It takes a … Read more