You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-find-visualstudio.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. 'use strict'
  2. const { describe, it } = require('mocha')
  3. const assert = require('assert')
  4. const fs = require('fs')
  5. const path = require('path')
  6. const findVisualStudio = require('../lib/find-visualstudio')
  7. const VisualStudioFinder = findVisualStudio.test.VisualStudioFinder
  8. const semverV1 = { major: 1, minor: 0, patch: 0 }
  9. delete process.env.VCINSTALLDIR
  10. function poison (object, property) {
  11. function fail () {
  12. console.error(Error(`Property ${property} should not have been accessed.`))
  13. process.abort()
  14. }
  15. var descriptor = {
  16. configurable: false,
  17. enumerable: false,
  18. get: fail,
  19. set: fail
  20. }
  21. Object.defineProperty(object, property, descriptor)
  22. }
  23. function TestVisualStudioFinder () { VisualStudioFinder.apply(this, arguments) }
  24. TestVisualStudioFinder.prototype = Object.create(VisualStudioFinder.prototype)
  25. // Silence npmlog - remove for debugging
  26. TestVisualStudioFinder.prototype.log = {
  27. silly: () => {},
  28. verbose: () => {},
  29. info: () => {},
  30. warn: () => {},
  31. error: () => {}
  32. }
  33. describe('find-visualstudio', function () {
  34. it('VS2013', function () {
  35. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  36. assert.strictEqual(err, null)
  37. assert.deepStrictEqual(info, {
  38. msBuild: 'C:\\MSBuild12\\MSBuild.exe',
  39. path: 'C:\\VS2013',
  40. sdk: null,
  41. toolset: 'v120',
  42. version: '12.0',
  43. versionMajor: 12,
  44. versionMinor: 0,
  45. versionYear: 2013
  46. })
  47. })
  48. finder.findVisualStudio2017OrNewer = (cb) => {
  49. finder.parseData(new Error(), '', '', cb)
  50. }
  51. finder.regSearchKeys = (keys, value, addOpts, cb) => {
  52. for (var i = 0; i < keys.length; ++i) {
  53. const fullName = `${keys[i]}\\${value}`
  54. switch (fullName) {
  55. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  56. case 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  57. continue
  58. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\12.0':
  59. assert.ok(true, `expected search for registry value ${fullName}`)
  60. return cb(null, 'C:\\VS2013\\VC\\')
  61. case 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions\\12.0\\MSBuildToolsPath':
  62. assert.ok(true, `expected search for registry value ${fullName}`)
  63. return cb(null, 'C:\\MSBuild12\\')
  64. default:
  65. assert.fail(`unexpected search for registry value ${fullName}`)
  66. }
  67. }
  68. return cb(new Error())
  69. }
  70. finder.findVisualStudio()
  71. })
  72. it('VS2013 should not be found on new node versions', function () {
  73. const finder = new TestVisualStudioFinder({
  74. major: 10,
  75. minor: 0,
  76. patch: 0
  77. }, null, (err, info) => {
  78. assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
  79. assert.ok(!info, 'no data')
  80. })
  81. finder.findVisualStudio2017OrNewer = (cb) => {
  82. const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
  83. const data = fs.readFileSync(file)
  84. finder.parseData(null, data, '', cb)
  85. }
  86. finder.regSearchKeys = (keys, value, addOpts, cb) => {
  87. for (var i = 0; i < keys.length; ++i) {
  88. const fullName = `${keys[i]}\\${value}`
  89. switch (fullName) {
  90. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  91. case 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  92. continue
  93. default:
  94. assert.fail(`unexpected search for registry value ${fullName}`)
  95. }
  96. }
  97. return cb(new Error())
  98. }
  99. finder.findVisualStudio()
  100. })
  101. it('VS2015', function () {
  102. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  103. assert.strictEqual(err, null)
  104. assert.deepStrictEqual(info, {
  105. msBuild: 'C:\\MSBuild14\\MSBuild.exe',
  106. path: 'C:\\VS2015',
  107. sdk: null,
  108. toolset: 'v140',
  109. version: '14.0',
  110. versionMajor: 14,
  111. versionMinor: 0,
  112. versionYear: 2015
  113. })
  114. })
  115. finder.findVisualStudio2017OrNewer = (cb) => {
  116. finder.parseData(new Error(), '', '', cb)
  117. }
  118. finder.regSearchKeys = (keys, value, addOpts, cb) => {
  119. for (var i = 0; i < keys.length; ++i) {
  120. const fullName = `${keys[i]}\\${value}`
  121. switch (fullName) {
  122. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  123. assert.ok(true, `expected search for registry value ${fullName}`)
  124. return cb(null, 'C:\\VS2015\\VC\\')
  125. case 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions\\14.0\\MSBuildToolsPath':
  126. assert.ok(true, `expected search for registry value ${fullName}`)
  127. return cb(null, 'C:\\MSBuild14\\')
  128. default:
  129. assert.fail(`unexpected search for registry value ${fullName}`)
  130. }
  131. }
  132. return cb(new Error())
  133. }
  134. finder.findVisualStudio()
  135. })
  136. it('error from PowerShell', function () {
  137. const finder = new TestVisualStudioFinder(semverV1, null, null)
  138. finder.parseData(new Error(), '', '', (info) => {
  139. assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
  140. assert.ok(!info, 'no data')
  141. })
  142. })
  143. it('empty output from PowerShell', function () {
  144. const finder = new TestVisualStudioFinder(semverV1, null, null)
  145. finder.parseData(null, '', '', (info) => {
  146. assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
  147. assert.ok(!info, 'no data')
  148. })
  149. })
  150. it('output from PowerShell not JSON', function () {
  151. const finder = new TestVisualStudioFinder(semverV1, null, null)
  152. finder.parseData(null, 'AAAABBBB', '', (info) => {
  153. assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
  154. assert.ok(!info, 'no data')
  155. })
  156. })
  157. it('wrong JSON from PowerShell', function () {
  158. const finder = new TestVisualStudioFinder(semverV1, null, null)
  159. finder.parseData(null, '{}', '', (info) => {
  160. assert.ok(/use PowerShell/i.test(finder.errorLog[0]), 'expect error')
  161. assert.ok(!info, 'no data')
  162. })
  163. })
  164. it('empty JSON from PowerShell', function () {
  165. const finder = new TestVisualStudioFinder(semverV1, null, null)
  166. finder.parseData(null, '[]', '', (info) => {
  167. assert.ok(/find .* Visual Studio/i.test(finder.errorLog[0]), 'expect error')
  168. assert.ok(!info, 'no data')
  169. })
  170. })
  171. it('future version', function () {
  172. const finder = new TestVisualStudioFinder(semverV1, null, null)
  173. finder.parseData(null, JSON.stringify([{
  174. packages: [
  175. 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64',
  176. 'Microsoft.VisualStudio.Component.Windows10SDK.17763',
  177. 'Microsoft.VisualStudio.VC.MSBuild.Base'
  178. ],
  179. path: 'C:\\VS',
  180. version: '9999.9999.9999.9999'
  181. }]), '', (info) => {
  182. assert.ok(/unknown version/i.test(finder.errorLog[0]), 'expect error')
  183. assert.ok(/find .* Visual Studio/i.test(finder.errorLog[1]), 'expect error')
  184. assert.ok(!info, 'no data')
  185. })
  186. })
  187. it('single unusable VS2017', function () {
  188. const finder = new TestVisualStudioFinder(semverV1, null, null)
  189. const file = path.join(__dirname, 'fixtures', 'VS_2017_Unusable.txt')
  190. const data = fs.readFileSync(file)
  191. finder.parseData(null, data, '', (info) => {
  192. assert.ok(/checking/i.test(finder.errorLog[0]), 'expect error')
  193. assert.ok(/find .* Visual Studio/i.test(finder.errorLog[2]), 'expect error')
  194. assert.ok(!info, 'no data')
  195. })
  196. })
  197. it('minimal VS2017 Build Tools', function () {
  198. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  199. assert.strictEqual(err, null)
  200. assert.deepStrictEqual(info, {
  201. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
  202. 'BuildTools\\MSBuild\\15.0\\Bin\\MSBuild.exe',
  203. path:
  204. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools',
  205. sdk: '10.0.17134.0',
  206. toolset: 'v141',
  207. version: '15.9.28307.665',
  208. versionMajor: 15,
  209. versionMinor: 9,
  210. versionYear: 2017
  211. })
  212. })
  213. poison(finder, 'regSearchKeys')
  214. finder.findVisualStudio2017OrNewer = (cb) => {
  215. const file = path.join(__dirname, 'fixtures',
  216. 'VS_2017_BuildTools_minimal.txt')
  217. const data = fs.readFileSync(file)
  218. finder.parseData(null, data, '', cb)
  219. }
  220. finder.findVisualStudio()
  221. })
  222. it('VS2017 Community with C++ workload', function () {
  223. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  224. assert.strictEqual(err, null)
  225. assert.deepStrictEqual(info, {
  226. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
  227. 'Community\\MSBuild\\15.0\\Bin\\MSBuild.exe',
  228. path:
  229. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community',
  230. sdk: '10.0.17763.0',
  231. toolset: 'v141',
  232. version: '15.9.28307.665',
  233. versionMajor: 15,
  234. versionMinor: 9,
  235. versionYear: 2017
  236. })
  237. })
  238. poison(finder, 'regSearchKeys')
  239. finder.findVisualStudio2017OrNewer = (cb) => {
  240. const file = path.join(__dirname, 'fixtures',
  241. 'VS_2017_Community_workload.txt')
  242. const data = fs.readFileSync(file)
  243. finder.parseData(null, data, '', cb)
  244. }
  245. finder.findVisualStudio()
  246. })
  247. it('VS2017 Express', function () {
  248. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  249. assert.strictEqual(err, null)
  250. assert.deepStrictEqual(info, {
  251. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\' +
  252. 'WDExpress\\MSBuild\\15.0\\Bin\\MSBuild.exe',
  253. path:
  254. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\WDExpress',
  255. sdk: '10.0.17763.0',
  256. toolset: 'v141',
  257. version: '15.9.28307.858',
  258. versionMajor: 15,
  259. versionMinor: 9,
  260. versionYear: 2017
  261. })
  262. })
  263. poison(finder, 'regSearchKeys')
  264. finder.findVisualStudio2017OrNewer = (cb) => {
  265. const file = path.join(__dirname, 'fixtures', 'VS_2017_Express.txt')
  266. const data = fs.readFileSync(file)
  267. finder.parseData(null, data, '', cb)
  268. }
  269. finder.findVisualStudio()
  270. })
  271. it('VS2019 Preview with C++ workload', function () {
  272. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  273. assert.strictEqual(err, null)
  274. assert.deepStrictEqual(info, {
  275. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
  276. 'Preview\\MSBuild\\Current\\Bin\\MSBuild.exe',
  277. path:
  278. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview',
  279. sdk: '10.0.17763.0',
  280. toolset: 'v142',
  281. version: '16.0.28608.199',
  282. versionMajor: 16,
  283. versionMinor: 0,
  284. versionYear: 2019
  285. })
  286. })
  287. poison(finder, 'regSearchKeys')
  288. finder.findVisualStudio2017OrNewer = (cb) => {
  289. const file = path.join(__dirname, 'fixtures',
  290. 'VS_2019_Preview.txt')
  291. const data = fs.readFileSync(file)
  292. finder.parseData(null, data, '', cb)
  293. }
  294. finder.findVisualStudio()
  295. })
  296. it('minimal VS2019 Build Tools', function () {
  297. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  298. assert.strictEqual(err, null)
  299. assert.deepStrictEqual(info, {
  300. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
  301. 'BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe',
  302. path:
  303. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools',
  304. sdk: '10.0.17134.0',
  305. toolset: 'v142',
  306. version: '16.1.28922.388',
  307. versionMajor: 16,
  308. versionMinor: 1,
  309. versionYear: 2019
  310. })
  311. })
  312. poison(finder, 'regSearchKeys')
  313. finder.findVisualStudio2017OrNewer = (cb) => {
  314. const file = path.join(__dirname, 'fixtures',
  315. 'VS_2019_BuildTools_minimal.txt')
  316. const data = fs.readFileSync(file)
  317. finder.parseData(null, data, '', cb)
  318. }
  319. finder.findVisualStudio()
  320. })
  321. it('VS2019 Community with C++ workload', function () {
  322. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  323. assert.strictEqual(err, null)
  324. assert.deepStrictEqual(info, {
  325. msBuild: 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\' +
  326. 'Community\\MSBuild\\Current\\Bin\\MSBuild.exe',
  327. path:
  328. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community',
  329. sdk: '10.0.17763.0',
  330. toolset: 'v142',
  331. version: '16.1.28922.388',
  332. versionMajor: 16,
  333. versionMinor: 1,
  334. versionYear: 2019
  335. })
  336. })
  337. poison(finder, 'regSearchKeys')
  338. finder.findVisualStudio2017OrNewer = (cb) => {
  339. const file = path.join(__dirname, 'fixtures',
  340. 'VS_2019_Community_workload.txt')
  341. const data = fs.readFileSync(file)
  342. finder.parseData(null, data, '', cb)
  343. }
  344. finder.findVisualStudio()
  345. })
  346. it('VS2022 Preview with C++ workload', function () {
  347. const msBuildPath = process.arch === 'arm64'
  348. ? 'C:\\Program Files\\Microsoft Visual Studio\\2022\\' +
  349. 'Community\\MSBuild\\Current\\Bin\\arm64\\MSBuild.exe'
  350. : 'C:\\Program Files\\Microsoft Visual Studio\\2022\\' +
  351. 'Community\\MSBuild\\Current\\Bin\\MSBuild.exe'
  352. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  353. assert.strictEqual(err, null)
  354. assert.deepStrictEqual(info, {
  355. msBuild: msBuildPath,
  356. path:
  357. 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community',
  358. sdk: '10.0.22621.0',
  359. toolset: 'v143',
  360. version: '17.4.33213.308',
  361. versionMajor: 17,
  362. versionMinor: 4,
  363. versionYear: 2022
  364. })
  365. })
  366. poison(finder, 'regSearchKeys')
  367. finder.msBuildPathExists = (path) => {
  368. return true
  369. }
  370. finder.findVisualStudio2017OrNewer = (cb) => {
  371. const file = path.join(__dirname, 'fixtures',
  372. 'VS_2022_Community_workload.txt')
  373. const data = fs.readFileSync(file)
  374. finder.parseData(null, data, '', cb)
  375. }
  376. finder.findVisualStudio()
  377. })
  378. function allVsVersions (finder) {
  379. finder.findVisualStudio2017OrNewer = (cb) => {
  380. const data0 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  381. 'VS_2017_Unusable.txt')))
  382. const data1 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  383. 'VS_2017_BuildTools_minimal.txt')))
  384. const data2 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  385. 'VS_2017_Community_workload.txt')))
  386. const data3 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  387. 'VS_2017_Express.txt')))
  388. const data4 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  389. 'VS_2019_Preview.txt')))
  390. const data5 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  391. 'VS_2019_BuildTools_minimal.txt')))
  392. const data6 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  393. 'VS_2019_Community_workload.txt')))
  394. const data7 = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures',
  395. 'VS_2022_Community_workload.txt')))
  396. const data = JSON.stringify(data0.concat(data1, data2, data3, data4,
  397. data5, data6, data7))
  398. finder.parseData(null, data, '', cb)
  399. }
  400. finder.regSearchKeys = (keys, value, addOpts, cb) => {
  401. for (var i = 0; i < keys.length; ++i) {
  402. const fullName = `${keys[i]}\\${value}`
  403. switch (fullName) {
  404. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  405. case 'HKLM\\Software\\Microsoft\\VisualStudio\\SxS\\VC7\\12.0':
  406. continue
  407. case 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7\\12.0':
  408. return cb(null, 'C:\\VS2013\\VC\\')
  409. case 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions\\12.0\\MSBuildToolsPath':
  410. return cb(null, 'C:\\MSBuild12\\')
  411. case 'HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VC7\\14.0':
  412. return cb(null, 'C:\\VS2015\\VC\\')
  413. case 'HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions\\14.0\\MSBuildToolsPath':
  414. return cb(null, 'C:\\MSBuild14\\')
  415. default:
  416. assert.fail(`unexpected search for registry value ${fullName}`)
  417. }
  418. }
  419. return cb(new Error())
  420. }
  421. }
  422. it('fail when looking for invalid path', function () {
  423. const finder = new TestVisualStudioFinder(semverV1, 'AABB', (err, info) => {
  424. assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
  425. assert.ok(!info, 'no data')
  426. })
  427. allVsVersions(finder)
  428. finder.findVisualStudio()
  429. })
  430. it('look for VS2013 by version number', function () {
  431. const finder = new TestVisualStudioFinder(semverV1, '2013', (err, info) => {
  432. assert.strictEqual(err, null)
  433. assert.deepStrictEqual(info.versionYear, 2013)
  434. })
  435. allVsVersions(finder)
  436. finder.findVisualStudio()
  437. })
  438. it('look for VS2013 by installation path', function () {
  439. const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2013',
  440. (err, info) => {
  441. assert.strictEqual(err, null)
  442. assert.deepStrictEqual(info.path, 'C:\\VS2013')
  443. })
  444. allVsVersions(finder)
  445. finder.findVisualStudio()
  446. })
  447. it('look for VS2015 by version number', function () {
  448. const finder = new TestVisualStudioFinder(semverV1, '2015', (err, info) => {
  449. assert.strictEqual(err, null)
  450. assert.deepStrictEqual(info.versionYear, 2015)
  451. })
  452. allVsVersions(finder)
  453. finder.findVisualStudio()
  454. })
  455. it('look for VS2015 by installation path', function () {
  456. const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015',
  457. (err, info) => {
  458. assert.strictEqual(err, null)
  459. assert.deepStrictEqual(info.path, 'C:\\VS2015')
  460. })
  461. allVsVersions(finder)
  462. finder.findVisualStudio()
  463. })
  464. it('look for VS2017 by version number', function () {
  465. const finder = new TestVisualStudioFinder(semverV1, '2017', (err, info) => {
  466. assert.strictEqual(err, null)
  467. assert.deepStrictEqual(info.versionYear, 2017)
  468. })
  469. allVsVersions(finder)
  470. finder.findVisualStudio()
  471. })
  472. it('look for VS2017 by installation path', function () {
  473. const finder = new TestVisualStudioFinder(semverV1,
  474. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community',
  475. (err, info) => {
  476. assert.strictEqual(err, null)
  477. assert.deepStrictEqual(info.path,
  478. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community')
  479. })
  480. allVsVersions(finder)
  481. finder.findVisualStudio()
  482. })
  483. it('look for VS2019 by version number', function () {
  484. const finder = new TestVisualStudioFinder(semverV1, '2019', (err, info) => {
  485. assert.strictEqual(err, null)
  486. assert.deepStrictEqual(info.versionYear, 2019)
  487. })
  488. allVsVersions(finder)
  489. finder.findVisualStudio()
  490. })
  491. it('look for VS2019 by installation path', function () {
  492. const finder = new TestVisualStudioFinder(semverV1,
  493. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools',
  494. (err, info) => {
  495. assert.strictEqual(err, null)
  496. assert.deepStrictEqual(info.path,
  497. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
  498. })
  499. allVsVersions(finder)
  500. finder.findVisualStudio()
  501. })
  502. it('look for VS2022 by version number', function () {
  503. const finder = new TestVisualStudioFinder(semverV1, '2022', (err, info) => {
  504. assert.strictEqual(err, null)
  505. assert.deepStrictEqual(info.versionYear, 2022)
  506. })
  507. finder.msBuildPathExists = (path) => {
  508. return true
  509. }
  510. allVsVersions(finder)
  511. finder.findVisualStudio()
  512. })
  513. it('msvs_version match should be case insensitive', function () {
  514. const finder = new TestVisualStudioFinder(semverV1,
  515. 'c:\\program files (x86)\\microsoft visual studio\\2019\\BUILDTOOLS',
  516. (err, info) => {
  517. assert.strictEqual(err, null)
  518. assert.deepStrictEqual(info.path,
  519. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
  520. })
  521. allVsVersions(finder)
  522. finder.findVisualStudio()
  523. })
  524. it('latest version should be found by default', function () {
  525. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  526. assert.strictEqual(err, null)
  527. assert.deepStrictEqual(info.versionYear, 2022)
  528. })
  529. finder.msBuildPathExists = (path) => {
  530. return true
  531. }
  532. allVsVersions(finder)
  533. finder.findVisualStudio()
  534. })
  535. it('run on a usable VS Command Prompt', function () {
  536. process.env.VCINSTALLDIR = 'C:\\VS2015\\VC'
  537. // VSINSTALLDIR is not defined on Visual C++ Build Tools 2015
  538. delete process.env.VSINSTALLDIR
  539. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  540. assert.strictEqual(err, null)
  541. assert.deepStrictEqual(info.path, 'C:\\VS2015')
  542. })
  543. allVsVersions(finder)
  544. finder.findVisualStudio()
  545. })
  546. it('VCINSTALLDIR match should be case insensitive', function () {
  547. process.env.VCINSTALLDIR =
  548. 'c:\\program files (x86)\\microsoft visual studio\\2019\\BUILDTOOLS\\VC'
  549. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  550. assert.strictEqual(err, null)
  551. assert.deepStrictEqual(info.path,
  552. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools')
  553. })
  554. allVsVersions(finder)
  555. finder.findVisualStudio()
  556. })
  557. it('run on a unusable VS Command Prompt', function () {
  558. process.env.VCINSTALLDIR =
  559. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildToolsUnusable\\VC'
  560. const finder = new TestVisualStudioFinder(semverV1, null, (err, info) => {
  561. assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
  562. assert.ok(!info, 'no data')
  563. })
  564. allVsVersions(finder)
  565. finder.findVisualStudio()
  566. })
  567. it('run on a VS Command Prompt with matching msvs_version', function () {
  568. process.env.VCINSTALLDIR = 'C:\\VS2015\\VC'
  569. const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015',
  570. (err, info) => {
  571. assert.strictEqual(err, null)
  572. assert.deepStrictEqual(info.path, 'C:\\VS2015')
  573. })
  574. allVsVersions(finder)
  575. finder.findVisualStudio()
  576. })
  577. it('run on a VS Command Prompt with mismatched msvs_version', function () {
  578. process.env.VCINSTALLDIR =
  579. 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC'
  580. const finder = new TestVisualStudioFinder(semverV1, 'C:\\VS2015',
  581. (err, info) => {
  582. assert.ok(/find .* Visual Studio/i.test(err), 'expect error')
  583. assert.ok(!info, 'no data')
  584. })
  585. allVsVersions(finder)
  586. finder.findVisualStudio()
  587. })
  588. })