@@ -38,26 +38,47 @@ interface TestUtilsConfig {
3838 dockerImageName : string ;
3939
4040 /**
41- * The command-line argument name used to specify the Redis version .
41+ * The command-line argument name used to specify the Docker image tag .
4242 * This argument can be passed when running tests / GH actions.
4343 *
4444 * @example
45+ * If set to 'redis-tag', you can run tests with:
46+ * ```bash
47+ * npm test -- --redis-tag="8.4"
48+ * ```
49+ */
50+ dockerImageTagArgument : string ;
51+
52+ /**
53+ * The command-line argument name used to specify the Redis version.
54+ * This is optional and used when the Docker tag doesn't contain a parseable version.
55+ * If not provided, the version will be parsed from the tag.
56+ *
57+ * @example
4558 * If set to 'redis-version', you can run tests with:
4659 * ```bash
47- * npm test -- --redis-version="6.2 "
60+ * npm test -- --redis-tag="custom-build" --redis- version="8.6 "
4861 * ```
62+ * @optional
4963 */
50- dockerImageVersionArgument : string ;
64+ dockerImageVersionArgument ? : string ;
5165
5266 /**
53- * The default Redis version to use if no version is specified via command-line arguments.
54- * Can be a specific version number (e.g., '6.2'), 'latest', or 'edge'.
55- * If not provided, defaults to 'latest'.
67+ * The default Docker version to use if no version is specified via command-line arguments.
68+ * Can be a string (e.g., '6.2', 'latest', 'edge') or an object with tag and version
69+ * for cases where the tag doesn't contain a parseable version.
70+ *
71+ * @example
72+ * // Simple string format
73+ * defaultDockerVersion: '8.4'
74+ *
75+ * // Object format for custom tags
76+ * defaultDockerVersion: { tag: 'custom-build-123', version: '8.6' }
5677 *
5778 * @optional
5879 * @default 'latest'
5980 */
60- defaultDockerVersion ?: string ;
81+ defaultDockerVersion ?: string | { tag : string ; version : string } ;
6182}
6283interface CommonTestOptions {
6384 serverArguments : Array < string > ;
@@ -132,7 +153,7 @@ interface AllTestOptions<
132153}
133154
134155interface Version {
135- string : string ;
156+ tag : string ;
136157 numbers : Array < number > ;
137158}
138159
@@ -158,30 +179,55 @@ export default class TestUtils {
158179 return value ;
159180 } ) ;
160181 }
161- static #getVersion( argumentName : string , defaultVersion = 'latest' ) : Version {
162- return yargs ( hideBin ( process . argv ) )
163- . option ( argumentName , {
182+ static #getVersion(
183+ tagArgumentName : string ,
184+ versionArgumentName : string | undefined ,
185+ defaultVersion : string | { tag : string ; version : string } = 'latest'
186+ ) : Version {
187+ const isObjectFormat = typeof defaultVersion !== 'string' ;
188+ const defaultTag = isObjectFormat ? defaultVersion . tag : defaultVersion ;
189+ const defaultVersionString = isObjectFormat ? defaultVersion . version : undefined ;
190+
191+ const args = yargs ( hideBin ( process . argv ) )
192+ . option ( tagArgumentName , {
164193 type : 'string' ,
165- default : defaultVersion
194+ default : defaultTag ,
195+ description : 'Docker image tag to use'
166196 } )
167- . coerce ( argumentName , ( version : string ) => {
168- return {
169- string : version ,
170- numbers : TestUtils . parseVersionNumber ( version )
171- } ;
197+ . option ( versionArgumentName ?? 'redis-version' , {
198+ type : 'string' ,
199+ description : 'Redis version (if not parseable from tag)'
172200 } )
173- . demandOption ( argumentName )
174- . parseSync ( ) [ argumentName ] ;
201+ . parseSync ( ) ;
202+
203+ const tag = args [ tagArgumentName ] as string ;
204+ const explicitVersion = versionArgumentName ? args [ versionArgumentName ] as string | undefined : undefined ;
205+
206+ // Priority: 1) CLI --redis-version, 2) default version from object format, 3) parse from tag
207+ let versionToParse : string ;
208+ if ( explicitVersion ) {
209+ versionToParse = explicitVersion ;
210+ } else if ( tag === defaultTag && defaultVersionString ) {
211+ // Using default tag and we have an explicit version for it
212+ versionToParse = defaultVersionString ;
213+ } else {
214+ versionToParse = tag ;
215+ }
216+
217+ return {
218+ tag,
219+ numbers : TestUtils . parseVersionNumber ( versionToParse )
220+ } ;
175221 }
176222
177223 readonly #VERSION_NUMBERS: Array < number > ;
178224 readonly #DOCKER_IMAGE: RedisServerDockerOptions ;
179225
180- constructor ( { string , numbers } : Version , dockerImageName : string ) {
226+ constructor ( { tag , numbers } : Version , dockerImageName : string ) {
181227 this . #VERSION_NUMBERS = numbers ;
182228 this . #DOCKER_IMAGE = {
183229 image : dockerImageName ,
184- version : string ,
230+ version : tag ,
185231 mode : "server"
186232 } ;
187233 }
@@ -191,14 +237,20 @@ export default class TestUtils {
191237 *
192238 * @param config - Configuration object containing Docker image and version settings
193239 * @param config.dockerImageName - The name of the Docker image to use for tests
194- * @param config.dockerImageVersionArgument - The command-line argument name for specifying Redis version
195- * @param config.defaultDockerVersion - Optional default Redis version if not specified via arguments
240+ * @param config.dockerImageTagArgument - The command-line argument name for specifying Docker image tag
241+ * @param config.dockerImageVersionArgument - Optional command-line argument name for specifying Redis version
242+ * @param config.defaultDockerVersion - Optional default Docker version if not specified via arguments
196243 * @returns A new TestUtils instance configured with the provided settings
197244 */
198245 public static createFromConfig ( config : TestUtilsConfig ) {
199246 return new TestUtils (
200- TestUtils . #getVersion( config . dockerImageVersionArgument ,
201- config . defaultDockerVersion ) , config . dockerImageName ) ;
247+ TestUtils . #getVersion(
248+ config . dockerImageTagArgument ,
249+ config . dockerImageVersionArgument ,
250+ config . defaultDockerVersion
251+ ) ,
252+ config . dockerImageName
253+ ) ;
202254 }
203255
204256 isVersionGreaterThan ( minimumVersion : Array < number > | undefined ) : boolean {
0 commit comments