m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
811 stars 40 forks source link

s3 mock: You are trying to `import` a file after the Jest environment has been torn down. #220

Closed jcollum-nutrien closed 5 months ago

jcollum-nutrien commented 7 months ago

Checklist

Bug description

I can't give you a full repro of this, all I know is that I had a test:

    const stream = new Readable();
    stream.push(JSON.stringify(JSON.parse(sqsEventJson.event.Records[0].body)));
    stream.push(null); // end of stream
    const sdkStream = sdkStreamMixin(stream);
    s3Mock.on(GetObjectCommand).resolves({ Body: sdkStream });
    s3Mock
      .on(DeleteObjectCommand)
      .resolves({} as unknown as DeleteObjectCommandOutput);

    mockSQSEvent.Records = [
      {
        body: JSON.stringify({
          s3Reference: {
            bucket: 'bucket',
            key: 'key',
          },
        }),
      } as SQSRecord,
    ];

    await handler(mockSQSEvent, mockContext);

    expect(upsertDoc).toHaveBeenCalledTimes(1);
    expect(s3Mock).toHaveReceivedAnyCommand();
    expect(s3Mock).toHaveReceivedCommand(DeleteObjectCommand);
    expect(s3Mock).toHaveReceivedCommand(GetObjectCommand);

it was running fine. Now, after rebasing off master branch I'm getting

You are trying to `import` a file after the Jest environment has been torn down. From src/handler.spec.ts.

All the suggestions I found were jest.useFakeTimers (and similar), which did not work. Putting it here for the sake of others (and in case anyone knows how to fix).

Reproduction

see code above, yes I know it's not adequate

Environment

dude0001 commented 6 months ago

@jcollum-nutrien, have you found a workaround?

m-radzikowski commented 5 months ago

Without a proper reproduction code, I can't investigate, I don't even know to which project rebase you refer to.

I'm closing this issue, but if the problem persists feel free to reopen providing a code I can run to reproduce.