11import * as fs from "fs" ;
22import * as path from "path" ;
33
4- import test , { ExecutionContext } from "ava" ;
4+ import test from "ava" ;
55
66import * as defaults from "./defaults.json" ;
77import { EnvVar } from "./environment" ;
88import {
99 Feature ,
1010 featureConfig ,
11- FeatureEnablement ,
1211 FEATURE_FLAGS_FILE_NAME ,
1312 FeatureConfig ,
14- FeatureWithoutCLI ,
15- initFeatures ,
1613} from "./feature-flags" ;
17- import { getRunnerLogger } from "./logging" ;
18- import { parseRepositoryNwo } from "./repository" ;
14+ import {
15+ setUpFeatureFlagTests ,
16+ getFeatureIncludingCodeQlIfRequired ,
17+ assertAllFeaturesUndefinedInApi ,
18+ } from "./feature-flags/testing-util" ;
1919import {
2020 getRecordingLogger ,
2121 initializeFeatures ,
2222 LoggedMessage ,
2323 mockCodeQLVersion ,
2424 mockFeatureFlagApiEndpoint ,
25- setupActionsVars ,
2625 setupTests ,
2726 stubFeatureFlagApiEndpoint ,
2827} from "./testing-utils" ;
29- import { ToolsFeature } from "./tools-features" ;
30- import * as util from "./util" ;
3128import { GitHubVariant , initializeEnvironment , withTmpDir } from "./util" ;
3229
3330setupTests ( test ) ;
@@ -36,8 +33,6 @@ test.beforeEach(() => {
3633 initializeEnvironment ( "1.2.3" ) ;
3734} ) ;
3835
39- const testRepositoryNwo = parseRepositoryNwo ( "github/example" ) ;
40-
4136test ( `All features are disabled if running against GHES` , async ( t ) => {
4237 await withTmpDir ( async ( tmpDir ) => {
4338 const loggedMessages = [ ] ;
@@ -558,56 +553,3 @@ test("initFeatures returns an `OfflineFeatures` instance in CCR", async (t) => {
558553 t . is ( "OfflineFeatures" , features . constructor . name ) ;
559554 } ) ;
560555} ) ;
561-
562- function assertAllFeaturesUndefinedInApi (
563- t : ExecutionContext < unknown > ,
564- loggedMessages : LoggedMessage [ ] ,
565- ) {
566- for ( const feature of Object . keys ( featureConfig ) ) {
567- t . assert (
568- loggedMessages . find (
569- ( v ) =>
570- v . type === "debug" &&
571- ( v . message as string ) . includes ( feature ) &&
572- ( v . message as string ) . includes ( "undefined in API response" ) ,
573- ) !== undefined ,
574- ) ;
575- }
576- }
577-
578- function setUpFeatureFlagTests (
579- tmpDir : string ,
580- logger = getRunnerLogger ( true ) ,
581- gitHubVersion = { type : GitHubVariant . DOTCOM } as util . GitHubVersion ,
582- ) : FeatureEnablement {
583- setupActionsVars ( tmpDir , tmpDir ) ;
584-
585- return initFeatures ( gitHubVersion , testRepositoryNwo , tmpDir , logger ) ;
586- }
587-
588- /**
589- * Returns an argument to pass to `getValue` that if required includes a CodeQL object meeting the
590- * minimum version or tool feature requirements specified by the feature.
591- */
592- function getFeatureIncludingCodeQlIfRequired (
593- features : FeatureEnablement ,
594- feature : Feature ,
595- ) {
596- const config = featureConfig [
597- feature
598- ] satisfies FeatureConfig as FeatureConfig ;
599- if (
600- config . minimumVersion === undefined &&
601- config . toolsFeature === undefined
602- ) {
603- return features . getValue ( feature as FeatureWithoutCLI ) ;
604- }
605-
606- return features . getValue (
607- feature ,
608- mockCodeQLVersion (
609- "9.9.9" ,
610- Object . fromEntries ( Object . values ( ToolsFeature ) . map ( ( v ) => [ v , true ] ) ) ,
611- ) ,
612- ) ;
613- }
0 commit comments