@@ -9,6 +9,7 @@ import * as fs from "fs";
99import * as path from "path" ;
1010import * as vscode from "vscode" ;
1111import * as sinon from "sinon" ;
12+ import * as sqldbproj from "sqldbproj" ;
1213import {
1314 NetCoreTool ,
1415 DBProjectConfigurationKey ,
@@ -22,6 +23,18 @@ import { createContext, TestContext } from "./testContext";
2223let testContext : TestContext ;
2324let sandbox : sinon . SinonSandbox ;
2425
26+ /**
27+ * Helper to read the default Microsoft.Build.Sql version from package.json
28+ */
29+ function getExpectedDefaultVersion ( key : string ) : string {
30+ const extension = vscode . extensions . getExtension ( sqldbproj . extension . vsCodeName ) ;
31+ const configKey = `${ DBProjectConfigurationKey } .${ key } ` ;
32+ return (
33+ extension ?. packageJSON ?. contributes ?. configuration ?. [ 0 ] ?. properties ?. [ configKey ] ?. default ||
34+ ""
35+ ) ;
36+ }
37+
2538suite ( "NetCoreTool: Net core tests" , function ( ) : void {
2639 teardown ( function ( ) : void {
2740 sandbox . restore ( ) ;
@@ -128,19 +141,22 @@ suite("NetCoreTool: Net core tests", function (): void {
128141 } ) ;
129142
130143 test ( "Should fall back to package.json default when configured value is invalid or empty" , async function ( ) : Promise < void > {
144+ // Get expected default from package.json
145+ const expectedDefault = getExpectedDefaultVersion ( testKey ) ;
146+
131147 // Test with invalid semver
132148 await vscode . workspace
133149 . getConfiguration ( DBProjectConfigurationKey )
134150 . update ( testKey , "not-a-valid-version" , vscode . ConfigurationTarget . Global ) ;
135151 let result = getMicrosoftBuildSqlVersion ( testKey ) ;
136- expect ( result ) . to . equal ( "2.1.0" ) ;
152+ expect ( result ) . to . equal ( expectedDefault ) ;
137153
138154 // Test with empty config
139155 await vscode . workspace
140156 . getConfiguration ( DBProjectConfigurationKey )
141157 . update ( testKey , undefined , vscode . ConfigurationTarget . Global ) ;
142158 result = getMicrosoftBuildSqlVersion ( testKey ) ;
143- expect ( result ) . to . equal ( "2.1.0" ) ;
159+ expect ( result ) . to . equal ( expectedDefault ) ;
144160 } ) ;
145161 } ) ;
146162} ) ;
0 commit comments