Giter VIP home page Giter VIP logo

Comments (8)

emfleisch avatar emfleisch commented on June 23, 2024 2

From what I have seen this is still an issue with aws-crt, however I was able to mitigate by updating my aws-sdk clients to version 3.56.0 (@aws-sdk/client-lambda, @aws-sdk/client-s3) which updated theirs dependency on signature-v4-crt, which has subsequently removed its dep of this library.
I got lucky with 3.56.0 getting released the day I encountered this problem, as I was not able to get around it in code or with jest settings.

from aws-crt-nodejs.

nponeccop avatar nponeccop commented on June 23, 2024 1

UPDATE: I was able to resolve it by switching jest spies I had for sns client with a mock client using aws-sdk-client-mock

aws-sdk-client-mock uses sinon for mocking. It works much better than the built-in Jest mocks unfortunately, and doesn't suffer from pseudo-calls, strange preprocessing and other Jest peculiarities that could be interpreted as design flaws. Unfortunately, Jest is the most popular testing framework out there. If you use the excellent JetBrains IDEs it's one of 3 testing framework choices, so people will keep hitting these issues no matter what, just because Jest mocking is inadequate.

from aws-crt-nodejs.

blesson3 avatar blesson3 commented on June 23, 2024

Can confirm that updating my @aws-sdk/client-s3 dependency resolved this issue. Couldn't find another way around it.

@aws-sdk/client-s3: 3.52.0 (broken) => 3.58.0 (fixed)

from aws-crt-nodejs.

mikelpr avatar mikelpr commented on June 23, 2024

this is still a problem on aws-crt

from aws-crt-nodejs.

oceanofmaya avatar oceanofmaya commented on June 23, 2024

the aws sdk clients I use are at version 3.118.0 and aws-crt version 1.12.5 which are the latest available when I'm commenting and I still see this issue.

UPDATE: I was able to resolve it by switching jest spies I had for sns client with a mock client using aws-sdk-client-mock

from aws-crt-nodejs.

nponeccop avatar nponeccop commented on June 23, 2024

I had a similar issue, and found a somewhat strange solution. It may not be the best solution but at least something that works.

I had global code in a module doing something like this:

import AWSXRay from 'aws-xray-sdk-core'
import { NodeHttpHandler } from '@aws-sdk/node-http-handler'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'

AWSXRay.setContextMissingStrategy('LOG_ERROR')
const client = new DynamoDBClient({
  maxAttempts: 10,
  requestHandler: new NodeHttpHandler({
    connectionTimeout: 50,
    socketTimeout: 50
  })
})
// throw new Error("Oh no!")

And if you uncomment the throw line there, it throws during tests. It means that a new DynamoDB client is created in tests, ultimately leading to the aws_logger problem in this issue. It also can be independently confirmed by running tests under a debugger and putting a breakpoint (debugging Jest this way works out of the box in JetBrains WebStorm).

So, is there a way to prevent the execution of this code in tests? It turns there is. You need to do 2 things:

  • create a mock using the __mocks__ folder
  • add this module to the mock list using jest.mock pseudo-call in your tests (it looks like a normal call but it isn't).

I hope it helps someone. I couldn't avoid the throwing until I used __mocks__, so it's essential.

from aws-crt-nodejs.

bretambrose avatar bretambrose commented on June 23, 2024

The logger handle is closed when the NAPI module is finalized by node. We don't have any control of when or if that happens; it seems to be a property of garbage collection. So on the surface, there's not much that can be done about the logger if we keep existing behavior.

However, there is a possibility that instead of enabling the logging router (takes native logging and writes to the Javascript console api) by default, we could instead make it opt-in (by environment and/or API call). This is potentially a disruptive change and I'm unsure of all of the consequences of it yet but I don't see any other way forward with this issue.

from aws-crt-nodejs.

Giovanni-Ilacqua avatar Giovanni-Ilacqua commented on June 23, 2024

I had a similar issue, and found a somewhat strange solution. It may not be the best solution but at least something that works.

I had global code in a module doing something like this:

import AWSXRay from 'aws-xray-sdk-core'
import { NodeHttpHandler } from '@aws-sdk/node-http-handler'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'

AWSXRay.setContextMissingStrategy('LOG_ERROR')
const client = new DynamoDBClient({
  maxAttempts: 10,
  requestHandler: new NodeHttpHandler({
    connectionTimeout: 50,
    socketTimeout: 50
  })
})
// throw new Error("Oh no!")

And if you uncomment the throw line there, it throws during tests. It means that a new DynamoDB client is created in tests, ultimately leading to the aws_logger problem in this issue. It also can be independently confirmed by running tests under a debugger and putting a breakpoint (debugging Jest this way works out of the box in JetBrains WebStorm).

So, is there a way to prevent the execution of this code in tests? It turns there is. You need to do 2 things:

  • create a mock using the __mocks__ folder
  • add this module to the mock list using jest.mock pseudo-call in your tests (it looks like a normal call but it isn't).

I hope it helps someone. I couldn't avoid the throwing until I used __mocks__, so it's essential.

I am struggling with this same issue. I tried creating a mocks directory and adding a file to it named aws_logger.ts which exports a jest function

export const aws_logger = jest.fn(() => 'Mocked aws_logger');

The in the test I call jest.mock()

jest.mock('../../../../__mocks__/aws_logger', () => ({
  aws_logger: jest.fn(),
}));

But the warning is persisting... so I must be doing something incorrectly. Could you share some more information about how you managed to get jest to use the mocked node module?

from aws-crt-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.