Skip to content

Remove unnecessary src folder prepend in useShapeWriter #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ void useShapeWriter(Shape shape, Consumer<TypeScriptWriter> writerConsumer) {
// Checkout/create the appropriate writer for the shape.
Symbol symbol = symbolProvider.toSymbol(shape);
String fileName = symbol.getDefinitionFile();
if (!fileName.startsWith(Paths.get(".", CodegenUtils.SOURCE_FOLDER).toString())) {
fileName = Paths.get(".", CodegenUtils.SOURCE_FOLDER, fileName).toString();
}
TypeScriptWriter writer = checkoutWriter(fileName);

// Add any needed DECLARE symbols.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Optional;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
Expand All @@ -36,10 +35,10 @@ public void generatesRuntimeConfigFiles() {

// Did we generate the runtime config files?
// note that asserting the contents of runtime config files is handled in its own unit tests.
Assertions.assertTrue(manifest.hasFile("package.json"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/index.ts"));
assertTrue(manifest.hasFile("package.json"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/index.ts"));

// Does the package.json file point to the runtime config?
String packageJsonContents = manifest.getFileString("package.json").get();
Expand Down Expand Up @@ -69,8 +68,8 @@ public void decoratesSymbolProvider() {

new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Foo.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.ts").get(), containsString("export class Foo"));
assertTrue(manifest.hasFile("Foo.ts"));
assertThat(manifest.getFileString("Foo.ts").get(), containsString("export class Foo"));
}

@Test
Expand All @@ -91,11 +90,11 @@ public void generatesServiceClients() {
.build();
new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Example.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Example.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Example.ts").get(),
containsString("export class Example extends ExampleClient"));

Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts"));
assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts").get(), containsString("export class ExampleClient"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package software.amazon.smithy.typescript.codegen;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.build.MockManifest;
import software.amazon.smithy.codegen.core.Symbol;
Expand All @@ -11,13 +17,6 @@
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.Pair;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

public class TypeScriptDelegatorTest {
@Test
public void vendsWritersForShapes() {
Expand All @@ -32,7 +31,7 @@ public void vendsWritersForShapes() {
delegator.useShapeWriter(fooShape, writer -> writer.write("Hello!"));
delegator.flushWriters();

assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.txt").get(), equalTo("Hello!\n"));
assertThat(manifest.getFileString("Foo.txt").get(), equalTo("Hello!\n"));
}

@Test
Expand Down Expand Up @@ -61,7 +60,7 @@ public void appendsToOpenedWriterWithNewline() {
delegator.useShapeWriter(fooShape, writer -> writer.write("Goodbye!"));
delegator.flushWriters();

assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.txt").get(), equalTo("Hello!\n\nGoodbye!\n"));
assertThat(manifest.getFileString("Foo.txt").get(), equalTo("Hello!\n\nGoodbye!\n"));
}

@Test
Expand Down