Skip to content

Commit

Permalink
Test client generated from released codegenerator (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase authored Dec 4, 2023
1 parent 599e95a commit b182975
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 9 deletions.
32 changes: 25 additions & 7 deletions scripts/build-generated-test-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const { spawnProcess } = require("./utils/spawn-process");

const root = path.join(__dirname, "..");

const codegenTestDir = path.join(
const testProjectDir = path.join(
root,
"smithy-typescript-codegen-test",
);

const codegenTestDir = path.join(
testProjectDir,
"build",
"smithyprojections",
"smithy-typescript-codegen-test",
Expand All @@ -23,6 +27,16 @@ const weatherClientDir = path.join(
"typescript-client-codegen"
);

const releasedClientDir = path.join(
testProjectDir,
"released-version-test",
"build",
"smithyprojections",
"released-version-test",
"source",
"typescript-codegen"
);

// TODO(experimentalIdentityAndAuth): build generic client for integration tests
const weatherExperimentalIdentityAndAuthClientDir = path.join(
codegenTestDir,
Expand Down Expand Up @@ -61,13 +75,15 @@ const buildAndCopyToNodeModules = async (packageName, codegenDir, nodeModulesDir
await spawnProcess("touch", ["yarn.lock"], { cwd: codegenDir });
await spawnProcess("yarn", { cwd: codegenDir });
await spawnProcess("yarn", ["build"], { cwd: codegenDir });
// After building the package, it's packed and copied to node_modules so that
// Optionally, after building the package, it's packed and copied to node_modules so that
// it can be used in integration tests by other packages within the monorepo.
await spawnProcess("yarn", ["pack"], { cwd: codegenDir });
await spawnProcess("rm", ["-rf", packageName], { cwd: nodeModulesDir });
await spawnProcess("mkdir", ["-p", packageName], { cwd: nodeModulesDir });
const targetPackageDir = path.join(nodeModulesDir, packageName);
await spawnProcess("tar", ["-xf", "package.tgz", "-C", targetPackageDir, "--strip-components", "1"], { cwd: codegenDir });
if (nodeModulesDir != undefined) {
await spawnProcess("yarn", ["pack"], { cwd: codegenDir });
await spawnProcess("rm", ["-rf", packageName], { cwd: nodeModulesDir });
await spawnProcess("mkdir", ["-p", packageName], { cwd: nodeModulesDir });
const targetPackageDir = path.join(nodeModulesDir, packageName);
await spawnProcess("tar", ["-xf", "package.tgz", "-C", targetPackageDir, "--strip-components", "1"], { cwd: codegenDir });
}
} catch (e) {
console.log(`Building and copying package \`${packageName}\` in \`${codegenDir}\` to \`${nodeModulesDir}\` failed:`)
console.log(e);
Expand All @@ -84,4 +100,6 @@ const buildAndCopyToNodeModules = async (packageName, codegenDir, nodeModulesDir
await buildAndCopyToNodeModules("@smithy/identity-and-auth-http-api-key-auth-service", httpApiKeyAuthClientDir, nodeModulesDir);
// TODO(experimentalIdentityAndAuth): add `@httpBearerAuth` client for integration tests
await buildAndCopyToNodeModules("@smithy/identity-and-auth-http-bearer-auth-service", httpBearerAuthClientDir, nodeModulesDir);
// Test released version of smithy-typescript codegenerators, but
await buildAndCopyToNodeModules("released", releasedClientDir, undefined);
})();
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rootProject.name = "smithy-typescript"
include(":smithy-typescript-codegen")
include(":smithy-typescript-codegen-test")
include(":smithy-typescript-codegen-test:example-weather-customizations")
include(":smithy-typescript-codegen-test:released-version-test")
include(":smithy-typescript-ssdk-codegen-test-utils")

file(
Expand Down
2 changes: 0 additions & 2 deletions smithy-typescript-codegen-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
extra["displayName"] = "Smithy :: Typescript :: Codegen :: Test"
extra["moduleName"] = "software.amazon.smithy.typescript.codegen.test"

tasks["jar"].enabled = false

val smithyVersion: String by project

buildscript {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

tasks["jar"].enabled = false

val smithyVersion: String by project
val version: String by project

buildscript {
val smithyVersion: String by project

repositories {
mavenCentral()
}
dependencies {
"classpath"("software.amazon.smithy:smithy-cli:$smithyVersion")
}
}

plugins {
id("software.amazon.smithy")
}

repositories {
mavenCentral()
}

dependencies {
implementation("software.amazon.smithy.typescript:smithy-typescript-codegen:$version!!")
implementation("software.amazon.smithy.typescript:smithy-aws-typescript-codegen:$version!!")
implementation(project(":smithy-typescript-codegen-test"))
implementation(project(":smithy-typescript-codegen-test:example-weather-customizations"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "1.0",
"plugins": {
"typescript-codegen": {
"service": "example.weather#Weather",
"package": "weather",
"packageVersion": "0.0.1",
"packageJson": {
"license": "Apache-2.0",
"private": true
}
}
}
}

0 comments on commit b182975

Please sign in to comment.