@@ -26,6 +26,49 @@ fn tsconfig_discovery_virtual_file_importer() {
2626 assert_eq ! ( resolved_path, Err ( ResolveError :: NotFound ( "random-import" . into( ) ) ) ) ;
2727}
2828
29+ /// When the importer path has query parameters (e.g. `file.tsx?custom=foo`),
30+ /// auto-discovery should strip them before walking parent directories
31+ /// and discover the correct tsconfig.json.
32+ ///
33+ /// Uses a fixture with project references where the root tsconfig has `include: []`
34+ /// and a referenced tsconfig.app.json has `include: ["src/**/*"]` with path aliases.
35+ /// Without stripping query params, `resolve_tsconfig_solution` fails to match the
36+ /// file against the reference's include pattern, returning the wrong tsconfig.
37+ #[ test]
38+ fn tsconfig_discovery_query_params ( ) {
39+ let f = super :: fixture_root ( ) . join ( "tsconfig/cases/query-params" ) ;
40+ let expected_tsconfig = f. join ( "tsconfig.app.json" ) ;
41+
42+ let resolver = Resolver :: new ( ResolveOptions {
43+ tsconfig : Some ( TsconfigDiscovery :: Auto ) ,
44+ ..ResolveOptions :: default ( )
45+ } ) ;
46+
47+ let clean_path = f. join ( "src/index.ts" ) ;
48+
49+ // Baseline — clean path discovers tsconfig.app.json (via project references)
50+ let tsconfig = resolver. find_tsconfig ( & clean_path) . unwrap ( ) . unwrap ( ) ;
51+ assert_eq ! ( tsconfig. path, expected_tsconfig, "baseline: should select referenced tsconfig" ) ;
52+
53+ // With query parameter — should discover the same referenced tsconfig
54+ let path_with_query = format ! ( "{}?custom=foo" , clean_path. display( ) ) ;
55+ let tsconfig = resolver. find_tsconfig ( & path_with_query) . unwrap ( ) . unwrap ( ) ;
56+ assert_eq ! ( tsconfig. path, expected_tsconfig, "query param: should select referenced tsconfig" ) ;
57+
58+ // With fragment — should discover the same referenced tsconfig
59+ let path_with_fragment = format ! ( "{}#fragment" , clean_path. display( ) ) ;
60+ let tsconfig = resolver. find_tsconfig ( & path_with_fragment) . unwrap ( ) . unwrap ( ) ;
61+ assert_eq ! ( tsconfig. path, expected_tsconfig, "fragment: should select referenced tsconfig" ) ;
62+
63+ // With both query and fragment — should discover the same referenced tsconfig
64+ let path_with_both = format ! ( "{}?custom=foo#fragment" , clean_path. display( ) ) ;
65+ let tsconfig = resolver. find_tsconfig ( & path_with_both) . unwrap ( ) . unwrap ( ) ;
66+ assert_eq ! (
67+ tsconfig. path, expected_tsconfig,
68+ "query+fragment: should select referenced tsconfig"
69+ ) ;
70+ }
71+
2972/// When a tsconfig.json exists but is not readable (e.g. permission denied),
3073/// auto-discovery should skip it and return `Ok(None)` instead of erroring.
3174#[ test]
0 commit comments