Skip to content

Commit f513619

Browse files
Copilotv-jiaodi
andcommitted
fix: make test helpers loading conditional to fix integration test failures
Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
1 parent f271277 commit f513619

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

packages/typespec-ts/src/framework/load-static-helpers.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface LoadStaticHelpersOptions extends Partial<ModularEmitterOptions>
4545
sourcesDir?: string;
4646
rootDir?: string;
4747
program?: Program;
48+
/** When true, also load test helpers from static/test-helpers/ into test/generated/util/ */
49+
loadTestHelpers?: boolean;
4850
}
4951

5052
interface FileMetadata {
@@ -68,19 +70,24 @@ export async function loadStaticHelpers(
6870
options.program
6971
);
7072
await loadFiles(filesInSources, options.sourcesDir ?? "");
71-
// Load static helpers used in testing code
72-
const defaultTestingHelpersPath = path.join(
73-
resolveProjectRoot(),
74-
DEFAULT_SOURCES_TESTING_HELPERS_PATH
75-
);
76-
const filesInTestings = await traverseDirectory(
77-
defaultTestingHelpersPath,
78-
options.program,
79-
[],
80-
"",
81-
"test/generated/util"
82-
);
83-
await loadFiles(filesInTestings, options.rootDir ?? "");
73+
// Load static helpers used in testing code (only when loadTestHelpers is enabled)
74+
if (
75+
options.loadTestHelpers ??
76+
(options.options?.generateTest && isAzurePackage({ options: options.options }))
77+
) {
78+
const defaultTestingHelpersPath = path.join(
79+
resolveProjectRoot(),
80+
DEFAULT_SOURCES_TESTING_HELPERS_PATH
81+
);
82+
const filesInTestings = await traverseDirectory(
83+
defaultTestingHelpersPath,
84+
options.program,
85+
[],
86+
"",
87+
"test/generated/util"
88+
);
89+
await loadFiles(filesInTestings, options.rootDir ?? "");
90+
}
8491
return assertAllHelpersLoadedPresent(helpersMap);
8592

8693
async function loadFiles(files: FileMetadata[], generateDir: string) {

packages/typespec-ts/test/util/testUtil.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ export async function provideBinderWithAzureDependencies(project: Project) {
285285
};
286286

287287
const staticHelperMap = await loadStaticHelpers(project, staticHelpers, {
288-
helpersAssetDirectory: helpersDirectory
288+
helpersAssetDirectory: helpersDirectory,
289+
loadTestHelpers: true
289290
});
290291

291292
const binder = provideBinder(project, {

0 commit comments

Comments
 (0)