Comments (8)
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.
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.
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.
this is still a problem on aws-crt
from aws-crt-nodejs.
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.
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.
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.
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 theaws_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)
- Unsubscribing from MQTT topic quickly may cause SEGV HOT 32
- Lambda@Edge SigV4Asymmetric signing issue in Typescript for S3 Multi Region Access point MRAP HOT 4
- MqttConnection should refresh STS credentials for WSS connections on reconnect
- aws-crt mqtt library not working with Webpack 5 HOT 1
- Node and Browser versions of the `iot.AwsIotMqttConnectionConfigBuilder` do not provide the same API HOT 8
- Buffer constructor is deprecated (node) HOT 1
- Migrate browser samples to use aws-sdk v3
- Webpack build warning HOT 4
- Segmentation Fault immediately on require inside Worker threads on Linux HOT 6
- Improve error messages that are returned when an exception is thrown while attempting to subscribe in JS HOT 1
- upgrade axios to 1.x HOT 6
- Add Esbuild support HOT 13
- 'AWS Signer SigV4A Headers' unit test failing HOT 9
- yarn install for aws-crt-nodejs: CMake Error: CMAKE_C_COMPILER not set HOT 11
- Node binaries not loading from binding.js when hoisted to root of node_modules HOT 6
- IoT unsigned custom authentication builder broken HOT 10
- Support `aws-c-s3` HOT 1
- Default provider chain does not support SSO profile-defined credentials HOT 2
- upgrade axios to ^1.6.4 HOT 1
- IoT MQTT5 MqttConnectCustomAuthConfig has invalid typing for custom authorizer + browser HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-crt-nodejs.