@@ -1479,3 +1479,113 @@ export function anotherFn() {
14791479 "proj2 should be affected via asset → constant → export chain"
14801480 ) ;
14811481}
1482+
1483+ /// Helper to get affected projects with custom include patterns
1484+ fn get_affected_with_include ( include : Vec < String > ) -> Vec < String > {
1485+ let config = TrueAffectedConfig {
1486+ cwd : fixture_path ( ) ,
1487+ base : "main" . to_string ( ) ,
1488+ root_ts_config : Some ( PathBuf :: from ( "tsconfig.json" ) ) ,
1489+ projects : vec ! [
1490+ Project {
1491+ name: "proj1" . to_string( ) ,
1492+ source_root: PathBuf :: from( "proj1" ) ,
1493+ ts_config: Some ( PathBuf :: from( "proj1/tsconfig.json" ) ) ,
1494+ implicit_dependencies: vec![ ] ,
1495+ targets: vec![ ] ,
1496+ } ,
1497+ Project {
1498+ name: "proj2" . to_string( ) ,
1499+ source_root: PathBuf :: from( "proj2" ) ,
1500+ ts_config: Some ( PathBuf :: from( "proj2/tsconfig.json" ) ) ,
1501+ implicit_dependencies: vec![ ] ,
1502+ targets: vec![ ] ,
1503+ } ,
1504+ Project {
1505+ name: "proj3" . to_string( ) ,
1506+ source_root: PathBuf :: from( "proj3" ) ,
1507+ ts_config: Some ( PathBuf :: from( "proj3/tsconfig.json" ) ) ,
1508+ implicit_dependencies: vec![ "proj1" . to_string( ) ] ,
1509+ targets: vec![ ] ,
1510+ } ,
1511+ ] ,
1512+ include,
1513+ ignored_paths : vec ! [ ] ,
1514+ } ;
1515+
1516+ let profiler = Arc :: new ( Profiler :: new ( false ) ) ;
1517+
1518+ find_affected ( config, profiler)
1519+ . expect ( "Failed to find affected projects" )
1520+ . affected_projects
1521+ }
1522+
1523+ #[ test]
1524+ fn test_included_test_file_marks_project_affected ( ) {
1525+ let branch = TestBranch :: new ( "test-include-spec-file" ) ;
1526+
1527+ // Create a .spec.ts file in proj1 (test file matching default include pattern)
1528+ branch. make_change (
1529+ "proj1/utils.spec.ts" ,
1530+ r#"import { proj1 } from './index';
1531+
1532+ describe('proj1', () => {
1533+ it('should work', () => {
1534+ expect(proj1()).toBe('proj1');
1535+ });
1536+ });
1537+ "# ,
1538+ ) ;
1539+
1540+ // Now modify only the test file
1541+ branch. make_change (
1542+ "proj1/utils.spec.ts" ,
1543+ r#"import { proj1 } from './index';
1544+
1545+ describe('proj1', () => {
1546+ it('should work correctly', () => {
1547+ expect(proj1()).toBe('proj1-modified');
1548+ });
1549+ });
1550+ "# ,
1551+ ) ;
1552+
1553+ // Use default include (empty vec triggers default test file pattern)
1554+ let affected = get_affected_with_include ( vec ! [ ] ) ;
1555+
1556+ // proj1 should be affected because the .spec.ts file matches the default include pattern
1557+ assert ! (
1558+ affected. contains( & "proj1" . to_string( ) ) ,
1559+ "proj1 should be affected when a .spec.ts file changes (default include pattern). Got: {:?}" ,
1560+ affected
1561+ ) ;
1562+ }
1563+
1564+ #[ test]
1565+ fn test_included_file_with_custom_pattern ( ) {
1566+ let branch = TestBranch :: new ( "test-include-custom" ) ;
1567+
1568+ // Create a .stories.ts file in proj2
1569+ branch. make_change (
1570+ "proj2/button.stories.ts" ,
1571+ r#"export const Primary = { args: { label: 'Click' } };
1572+ "# ,
1573+ ) ;
1574+
1575+ // Modify the stories file
1576+ branch. make_change (
1577+ "proj2/button.stories.ts" ,
1578+ r#"export const Primary = { args: { label: 'Click Me' } };
1579+ "# ,
1580+ ) ;
1581+
1582+ // Use a custom include pattern that matches .stories.ts files
1583+ let affected = get_affected_with_include ( vec ! [ r"\.stories\.(ts|js)x?$" . to_string( ) ] ) ;
1584+
1585+ // proj2 should be affected because the .stories.ts file matches the custom pattern
1586+ assert ! (
1587+ affected. contains( & "proj2" . to_string( ) ) ,
1588+ "proj2 should be affected when a .stories.ts file changes (custom include pattern). Got: {:?}" ,
1589+ affected
1590+ ) ;
1591+ }
0 commit comments