diff --git a/tests/local/importsScopedPackageClientS3.js b/tests/local/importsScopedPackageClientS3.js new file mode 100644 index 00000000..4c74a1bc --- /dev/null +++ b/tests/local/importsScopedPackageClientS3.js @@ -0,0 +1,11 @@ +import { + S3Client +} from '@aws-sdk/client-s3' + +export default new S3Client({ + region: 'us-west-2', + credentials: { + accessKeyId: 'AKIARJOS8FJWB773G55', + secretAccessKey: 'secreataccessalkjsjdfoiwhe/gowh' + } +}) diff --git a/tests/local/importsScopedPackageClientS3Deep.js b/tests/local/importsScopedPackageClientS3Deep.js new file mode 100644 index 00000000..4cb34189 --- /dev/null +++ b/tests/local/importsScopedPackageClientS3Deep.js @@ -0,0 +1,3 @@ +import s3 from './importsScopedPackageClientS3.js' + +export default s3 diff --git a/tests/package.json b/tests/package.json index fab261d1..ea111aa0 100644 --- a/tests/package.json +++ b/tests/package.json @@ -15,6 +15,7 @@ "#sub": "./local/subpath.js" }, "dependencies": { + "@aws-sdk/client-s3": "^3.408.0", "babelGeneratedDoubleDefault": "file:./local/babelGeneratedDoubleDefault", "eslint": "^8.12.0", "form-urlencoded": "^6.0.7", diff --git a/tests/tests-node/esmock.node.test.js b/tests/tests-node/esmock.node.test.js index 496a7e73..bd502ebb 100644 --- a/tests/tests-node/esmock.node.test.js +++ b/tests/tests-node/esmock.node.test.js @@ -506,3 +506,33 @@ test('should error when "strictest" mock tree module not mocked', async () => { .replace(':parent', 'importsCoreLocalAndPackage.js')) }) }) + +test('should mock scoped package, @aws-sdk/client-s3', async () => { + const scopedClientS3 = await esmock( + '../local/importsScopedPackageClientS3.js', { + '@aws-sdk/client-s3': { + S3Client: function () { + this.mocked = 'mock client' + + return this + } + } + }) + + assert.strictEqual(scopedClientS3.mocked, 'mock client') +}) + +test('should mock scoped package, @aws-sdk/client-s3 (deep)', async () => { + const scopedClientS3 = await esmock( + '../local/importsScopedPackageClientS3Deep.js', {}, { + '@aws-sdk/client-s3': { + S3Client: function () { + this.mocked = 'mock client' + + return this + } + } + }) + + assert.strictEqual(scopedClientS3.mocked, 'mock client') +})