Skip to content

Commit

Permalink
test: add outputFileExtension to specify which output extension to use
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienKode committed Oct 24, 2023
1 parent 9bc221e commit 3d788f2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
56 changes: 55 additions & 1 deletion packages/relay/transform/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const myFragment = graphql`
fragment FooFragment on Bar {
id
}
`
useQuery(graphql`
query FooQuery {
id
}
`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import __FooFragment from "__generated__/FooFragment.graphql.js";
import __FooQuery from "__generated__/FooQuery.graphql.js";
const myFragment = __FooFragment;
useQuery(__FooQuery);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const myFragment = graphql`
fragment FooFragment on Bar {
id
}
`
useQuery(graphql`
query FooQuery {
id
}
`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import __FooFragment from "__generated__/FooFragment.graphql.ts";
import __FooQuery from "__generated__/FooQuery.graphql.ts";
const myFragment = __FooFragment;
useQuery(__FooQuery);

0 comments on commit 3d788f2

Please sign in to comment.