From 6dc877c9c40bf43b7f4b4e0f485e8c60752b34ba Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Tue, 22 Nov 2022 07:52:16 -0800 Subject: [PATCH] Fix broken reference to `fail()` after jest-upgrade Jest versions >= 27 replace jest-jasmine2 with jest-circus, which does not have an implementation for the `fail()` method, but still has the method stub defined in the Jest type-defs. This change implements the `fail()` method in protocol test suites, and adjusts the thrown message to actually state the error, instead of just `err`. --- .../typescript/codegen/HttpProtocolTestGenerator.java | 2 +- .../smithy/typescript/codegen/protocol-test-stub.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java index def9d9907b5..378c1dd9576 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java @@ -643,7 +643,7 @@ private void generateResponseTest(OperationShape operation, HttpResponseTestCase writer.write("try {\n" + " r = await client.send(command);\n" + "} catch (err) {\n" - + " fail('Expected a valid response to be returned, got err.');\n" + + " fail('Expected a valid response to be returned, got:\n\n `${err}`');\n" + " return;\n" + "}"); writeResponseAssertions(operation, testCase); diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-stub.ts b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-stub.ts index 7ffbfff1895..e9b41d419d7 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-stub.ts +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/protocol-test-stub.ts @@ -139,3 +139,11 @@ const clientParams = { region: "us-west-2", credentials: { accessKeyId: "key", secretAccessKey: "secret" } } + +/** + * A wrapper function that shadows `fail` from jest-jasmine2 + * (jasmine2 was replaced with circus in > v27 as the default test runner) + */ +const fail = (error?: any): never => { + throw new Error(error); +}