diff --git a/packages/relay/transform/tests/fixture.rs b/packages/relay/transform/tests/fixture.rs index 603b04eb2..9f13bd3d6 100644 --- a/packages/relay/transform/tests/fixture.rs +++ b/packages/relay/transform/tests/fixture.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use swc_common::FileName; use swc_ecma_transforms_testing::test_fixture; -use swc_relay::{relay, Config, RelayLanguageConfig}; +use swc_relay::{relay, Config, RelayLanguageConfig, OutputFileExtension}; #[testing::fixture("tests/fixture/simple/**/input.js")] fn fixture(input: PathBuf) { @@ -16,6 +16,7 @@ fn fixture(input: PathBuf) { artifact_directory: None, language: RelayLanguageConfig::TypeScript, eager_es_modules: false, + output_file_extension: OutputFileExtension::Undefined, }, FileName::Real("file.js".parse().unwrap()), Default::default(), @@ -41,6 +42,59 @@ fn fixture_es_modules(input: PathBuf) { artifact_directory: None, language: RelayLanguageConfig::TypeScript, eager_es_modules: true, + output_file_extension: OutputFileExtension::Undefined, + }, + FileName::Real("file.js".parse().unwrap()), + Default::default(), + None, + None, + ) + }, + &input, + &output, + Default::default(), + ); +} + +#[testing::fixture("tests/fixture/outputFileExtension/javascript/**/input.js")] +fn fixture_output_file_extension_javascript(input: PathBuf) { + let output = input.parent().unwrap().join("output.js"); + + test_fixture( + Default::default(), + &|_| { + relay( + &Config { + artifact_directory: None, + language: RelayLanguageConfig::TypeScript, + eager_es_modules: true, + output_file_extension: OutputFileExtension::JavaScript, + }, + FileName::Real("file.js".parse().unwrap()), + Default::default(), + None, + None, + ) + }, + &input, + &output, + Default::default(), + ); +} + +#[testing::fixture("tests/fixture/outputFileExtension/typescript/**/input.js")] +fn fixture_output_file_extension_typescript(input: PathBuf) { + let output = input.parent().unwrap().join("output.js"); + + test_fixture( + Default::default(), + &|_| { + relay( + &Config { + artifact_directory: None, + language: RelayLanguageConfig::JavaScript, + eager_es_modules: true, + output_file_extension: OutputFileExtension::TypeScript, }, FileName::Real("file.js".parse().unwrap()), Default::default(), diff --git a/packages/relay/transform/tests/fixture/outputFileExtension/javascript/input.js b/packages/relay/transform/tests/fixture/outputFileExtension/javascript/input.js new file mode 100644 index 000000000..7998bde80 --- /dev/null +++ b/packages/relay/transform/tests/fixture/outputFileExtension/javascript/input.js @@ -0,0 +1,10 @@ +const myFragment = graphql` + fragment FooFragment on Bar { + id + } +` +useQuery(graphql` + query FooQuery { + id + } +`) \ No newline at end of file diff --git a/packages/relay/transform/tests/fixture/outputFileExtension/javascript/output.js b/packages/relay/transform/tests/fixture/outputFileExtension/javascript/output.js new file mode 100644 index 000000000..8d1e17239 --- /dev/null +++ b/packages/relay/transform/tests/fixture/outputFileExtension/javascript/output.js @@ -0,0 +1,4 @@ +import __FooFragment from "__generated__/FooFragment.graphql.js"; +import __FooQuery from "__generated__/FooQuery.graphql.js"; +const myFragment = __FooFragment; +useQuery(__FooQuery); diff --git a/packages/relay/transform/tests/fixture/outputFileExtension/typescript/input.js b/packages/relay/transform/tests/fixture/outputFileExtension/typescript/input.js new file mode 100644 index 000000000..7998bde80 --- /dev/null +++ b/packages/relay/transform/tests/fixture/outputFileExtension/typescript/input.js @@ -0,0 +1,10 @@ +const myFragment = graphql` + fragment FooFragment on Bar { + id + } +` +useQuery(graphql` + query FooQuery { + id + } +`) \ No newline at end of file diff --git a/packages/relay/transform/tests/fixture/outputFileExtension/typescript/output.js b/packages/relay/transform/tests/fixture/outputFileExtension/typescript/output.js new file mode 100644 index 000000000..ab4df6280 --- /dev/null +++ b/packages/relay/transform/tests/fixture/outputFileExtension/typescript/output.js @@ -0,0 +1,4 @@ +import __FooFragment from "__generated__/FooFragment.graphql.ts"; +import __FooQuery from "__generated__/FooQuery.graphql.ts"; +const myFragment = __FooFragment; +useQuery(__FooQuery);