@@ -7,6 +7,8 @@ import { hasCycle } from "./toFractalTree/hasCycle";
7
7
import { RootOption } from "../shared/RootOption" ;
8
8
import { isLinkedFile , linkedFileToOriginal } from "./shared/isLinkedFile" ;
9
9
import chalk from "chalk" ;
10
+ import { fileWithoutExtension } from "../shared/fileWithoutExtension" ;
11
+ import { isTestFile } from "./shared/isTestFile" ;
10
12
11
13
export function toFractalTree ( graph : Graph , entryPoints : string [ ] ) {
12
14
const tree : RootOption [ "tree" ] = { } ;
@@ -130,6 +132,8 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
130
132
} ) ;
131
133
}
132
134
135
+ const treeKeys = Object . keys ( tree ) ;
136
+
133
137
if ( linkedFiles . size > 0 ) {
134
138
// const globalTests = [];
135
139
@@ -141,7 +145,30 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
141
145
path . basename ( sourceFile )
142
146
) ;
143
147
// source file will either be in the current dir or one up
144
- const sourceFilePath = tree [ sourceFile ] || tree [ oneDirUp ] ;
148
+ let sourceFilePath = tree [ sourceFile ] || tree [ oneDirUp ] ;
149
+
150
+ // sometimes the test is add.test.jsx and the source is add.test.js
151
+ // so we have to do a linear search to find source key
152
+ // we could probably optimize this if needed by doing some work in the fn above
153
+ if ( ! sourceFilePath ) {
154
+ const sourceFileWithoutFileExtension = fileWithoutExtension ( sourceFile ) ;
155
+ for ( const key of treeKeys ) {
156
+ if ( path . basename ( key ) . startsWith ( sourceFileWithoutFileExtension ) ) {
157
+ sourceFilePath = tree [ key ] ;
158
+ break ;
159
+ }
160
+ }
161
+ }
162
+
163
+ if ( ! sourceFilePath && isTestFile ( linkedFile ) ) {
164
+ // could not link by filename
165
+ // so the backup is linking by first relative import
166
+ const [ firstRelativeImport ] = graph [ linkedFile ] ;
167
+ if ( firstRelativeImport ) {
168
+ sourceFilePath = tree [ firstRelativeImport ] ;
169
+ }
170
+ }
171
+
145
172
if ( ! sourceFilePath ) {
146
173
logger . warn (
147
174
`could not find source file that is linked to ${ chalk . blueBright (
0 commit comments