Cypress: cyTask promise resolved successfully then throws TypeError: Converting circular structure to JSON

Created on 21 Feb 2020  路  2Comments  路  Source: cypress-io/cypress

Current behavior:

Attempting to seed my dynamodb table in a cy.task() using aws node sdk. The putItem promise resolves successfully and my database is updated but Cypress throws an error as finds a circular structure in the response ...

> TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'TLSSocket'
    |     property 'parser' -> object with constructor 'HTTPParser'
    --- property 'socket' closes the circle
    at JSON.stringify (<anonymous>)
    at process.target._send (internal/child_process.js:778:25)
    at process.target.send (internal/child_process.js:676:19)
    at Object.send (/Users/redacted/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:34:27)
    at /Users/redacted/Library/Caches/Cypress/4.0.2/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:53:20

Desired behavior:

If the promise resolves then cypress should allow the test to crack on and not error :)

Test code to reproduce

here is my plugins/index.js

var AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
var credentials = new AWS.SharedIniFileCredentials({profile: 'myprofile'});
AWS.config.credentials = credentials;

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  on('task', {
    'seed:db' (data) {
      var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
      promises = data.map(x=>{

        var params = {
          TableName: 'my-table',
          Item: x
         };

         return docClient.put(params, function(err, response){
          if (err) {
            console.log("Put Item error");
          } else {
            console.log(`Put Item Success - ${x.name}`);  
          }
        })
      })

    return promises

    },
  })
}

and the beforeEach in my test file....

beforeEach(function () {
  cy.fixture('seed').then((seed)=>{
    cy.task('seed:db', seed)
  })

})

Versions

cypress 4.0.1
Node 12.16.1
osx Catalina 10.15.3

Most helpful comment

@ed-sparkes can you share what the solution was? I'm seeing the same behavior

All 2 comments

was being silly sorry

@ed-sparkes can you share what the solution was? I'm seeing the same behavior

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brian-mann picture brian-mann  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

scottcrowe picture scottcrowe  路  3Comments

brian-mann picture brian-mann  路  3Comments

igorpavlov picture igorpavlov  路  3Comments