diff --git a/__tests__/creator-spec.ts b/__tests__/creator-spec.ts index a4b7ec2..7877a0d 100644 --- a/__tests__/creator-spec.ts +++ b/__tests__/creator-spec.ts @@ -74,31 +74,47 @@ const defaultOptions = { outputDirectory: path.join(os.tmpdir(), 'electron-wix-msi-test') }; -const testIncludes = (title: string, ...content: Array) => { +const testIncludesBase = (title: string, expectation: boolean , ...content: Array) => { return test(`.wxs file includes ${title}`, () => { if (Array.isArray(content)) { // We want to be able to search across line breaks and multiple spaces. const singleLineWxContent = wxsContent.replace(/\s\s+/g, ' '); content.forEach((innerContent) => { - expect(singleLineWxContent.includes(innerContent)).toBeTruthy(); + expect(singleLineWxContent.includes(innerContent)).toBe(expectation); }); } }); }; +const testIncludes = (title: string, ...content: Array) => { + return testIncludesBase(title, true, ...content ); +}; -const regexTestIncludes = (title: string, ...content: Array) => { +const testIncludesNot = (title: string, ...content: Array) => { + return testIncludesBase(title, false, ...content ); +}; + + +const regexTestIncludesBase = (title: string, expectation: boolean , ...content: Array) => { return test(`.wxs file includes ${title}`, () => { if (Array.isArray(content)) { // We want to be able to search across line breaks and multiple spaces. const singleLineWxContent = wxsContent.replace(/\s\s+/g, ' '); content.forEach((innerContent) => { - expect(innerContent.test(singleLineWxContent)).toBeTruthy(); + expect(innerContent.test(singleLineWxContent)).toBe(expectation); }); } }); }; +const regexTestIncludes = (title: string, ...content: Array) => { + return regexTestIncludesBase(title, true, ...content ); +}; + +const regexTestIncludesNot = (title: string, ...content: Array) => { + return regexTestIncludesBase(title, false, ...content ); +}; + let wxsContent = ''; let mockWixInstalled = true; @@ -133,9 +149,9 @@ regexTestIncludes('versioned app folder', / { - // Files + 2 Shortcuts + 1 StubExecutable + 1 installInfo file + 2 purge components + // Files + 2 Shortcuts + 2 special files + 7 registry + 1 purge components const count = wxsContent.split('').length - 1; - expect(count).toEqual(numberOfFiles + 6); + expect(count).toEqual(numberOfFiles + 12); }); test('MSICreator create() creates Wix file with UI properties', async () => { @@ -424,12 +440,28 @@ testIncludes('Custom shortcut name', ''); testIncludes('correct default perUser setting', ''); testIncludes('Install path property', ''); -testIncludes('Install RegistrySearch', ''); testIncludes('PurgeOnUninstall component', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); +testIncludes('RegistryRunKey component-ref', ''); + +testIncludesNot('RegistryRunKey component', ''); +regexTestIncludesNot('AutoLaunch feature', //); +regexTestIncludesNot('AutoUpdater feature', //); +regexTestIncludesNot('Squirrel executable component-ref', // ); +testIncludesNot('Permission component-ref', ``); +testIncludesNot('RegistryRunKey component-ref', ''); + describe('auto-updater', () => { test('MSICreator includes Auto-Updater feature', async () => { const msiCreator = new MSICreator({ ...defaultOptions, features: {autoUpdate: true, autoLaunch: false }}); @@ -439,9 +471,9 @@ describe('auto-updater', () => { }); test('.wxs file has as many components as we have files', () => { - // Files + 2 Shortcuts + StubExecutable + installInfo file + Update.exe + Permission Component + 2 purge components + // Files + 2 Shortcuts + 3 special files + 8 registry + 1 permission component + 1 purge components const count = wxsContent.split('').length - 1; - expect(count).toEqual(numberOfFiles + 8); + expect(count).toEqual(numberOfFiles + 15); }); test('.wxs file contains as many component refs as components', () => { @@ -450,15 +482,24 @@ describe('auto-updater', () => { expect(componentCount).toEqual(refCount); }); - regexTestIncludes('Squirrel executable component', /'); testIncludes('Updater user group property', ''); regexTestIncludes('AutoUpdater feature', //); - regexTestIncludes('Squirrel executable component-ref', // ); + regexTestIncludes('Squirrel executable component-ref', // ); testIncludes('Permission component-ref', ``); + + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); }); describe('auto-launch', () => { @@ -466,14 +507,13 @@ describe('auto-launch', () => { const msiCreator = new MSICreator({ ...defaultOptions, features: {autoUpdate: false, autoLaunch: true }}); const { wxsFile } = await msiCreator.create(); wxsContent = await fs.readFile(wxsFile, 'utf-8'); - console.log(wxsContent); expect(wxsFile).toBeTruthy(); }); test('.wxs file has as many components as we have files', () => { - // Files + 2 Shortcuts + StubExecutable + installInfo file + 2 purge components + run key + // Files + 2 Shortcuts + 2 special files + 8 registry + 1 purge components const count = wxsContent.split('').length - 1; - expect(count).toEqual(numberOfFiles + 7); + expect(count).toEqual(numberOfFiles + 13); }); test('.wxs file contains as many component refs as components', () => { @@ -484,6 +524,13 @@ describe('auto-launch', () => { testIncludes('RegistryRunKey component', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); + testIncludes('RegistryRunKey component-ref', ''); regexTestIncludes('AutoLaunch feature', //); }); @@ -492,7 +539,6 @@ describe('perUser install by default', () => { const msiCreator = new MSICreator({ ...defaultOptions, defaultInstallMode: 'perUser' }); const { wxsFile } = await msiCreator.create(); wxsContent = await fs.readFile(wxsFile, 'utf-8'); - console.log(wxsContent); expect(wxsFile).toBeTruthy(); }); diff --git a/__tests__/utils/array-to-tree-spec.ts b/__tests__/utils/array-to-tree-spec.ts index 73ad01c..184e328 100644 --- a/__tests__/utils/array-to-tree-spec.ts +++ b/__tests__/utils/array-to-tree-spec.ts @@ -1,12 +1,13 @@ import { cloneDeep, defaultsDeep } from 'lodash'; import * as mockFs from 'mock-fs'; +import { Registry } from '../../src/interfaces'; import { addFilesToTree, arrayToTree, isChild, isDirectChild } from '../../src/utils/array-to-tree'; import { separator as S } from '../../src/utils/separator'; import { getMockFileSystem } from '../mocks/mock-fs'; const installInfoRegex = process.platform === 'win32' ? /C:\\tmp\\\.installInfo.*\\\.installInfo\.json/ : /\/tmp\/\.installInfo.*\.installInfo\.json/; -const msiAwareSquirrelRegex = process.platform === 'win32' ? /.*\\vendor\\MsiAwareSquirrel_1\.9\.1\.exe/ : /.*\/vendor\/MsiAwareSquirrel_1\.9\.1\.exe/; +const msqSquirrelRegex = process.platform === 'win32' ? /.*\\vendor\\msq.exe/ : /.*\/vendor\/msq.exe/; const originalTmp = process.env.TEMP; const mockFolders = [ @@ -27,6 +28,27 @@ const mockFiles = [ `slack${S}locales${S}en-US.json`, ]; +const mockSpecialFiles = [ + { name: `slack.exe`, path: `C:${S}temp${S}slack.exe`}, + { name: `.installInfo.json`, path: 'C:\\temp\\installInfo.json' } +]; + +const mockUpdaterSpecialFiles = [ + ...mockSpecialFiles, + { name: `Update.exe`, path: 'C:\\temp\\Update.exe' } +]; + +const mockRegistry: Array = [ + { + id: 'RegistryInstallPath', + root: 'HKMU', + name: 'InstallPath', + key: 'SOFTWARE\\{{Manufacturer}}\\{{ApplicationName}}', + type: 'string', + value: '[APPLICATIONROOTDIRECTORY]', + } +]; + const mockFolderTree = { __ELECTRON_WIX_MSI_PATH__: `slack`, __ELECTRON_WIX_MSI_DIR_NAME__: 'slack', @@ -73,7 +95,7 @@ const mockFolderTree = { const mockFolderFileTree = defaultsDeep(cloneDeep(mockFolderTree), { __ELECTRON_WIX_MSI_FILES__: [ { name: 'slack.exe', path: `C:${S}temp${S}slack.exe` }, { name: '.installInfo.json', - path: expect.stringMatching(installInfoRegex) } ], + path: 'C:\\temp\\installInfo.json' }], __ELECTRON_WIX_MSI_REGISTRY__: [{ id: 'RegistryInstallPath', key: 'SOFTWARE\\{{Manufacturer}}\\{{ApplicationName}}', @@ -165,19 +187,19 @@ test(`arrayToTree() creates a tree structure`, () => { }); test(`addFilesToTree() adds files to a tree structure`, () => { - const folderFileTree = addFilesToTree(mockFolderTree, mockFiles, `slack`, `C:${S}temp${S}slack.exe`, false, false, '1.0.0'); + const folderFileTree = addFilesToTree(mockFolderTree, mockFiles, mockSpecialFiles, mockRegistry, '1.0.0'); expect(folderFileTree).toEqual(mockFolderFileTree); }); -test(`addFilesToTree() adds files to a tree structure on Mac`, () => { +test(`addFilesToTree() adds files to a tree structure`, () => { const updaterMockFolderFileTree = cloneDeep(mockFolderFileTree); updaterMockFolderFileTree.__ELECTRON_WIX_MSI_FILES__ = [ { name: 'slack.exe', path: `C:${S}temp${S}slack.exe` }, { name: '.installInfo.json', - path: expect.stringMatching(installInfoRegex) }, + path: 'C:\\temp\\installInfo.json' }, { name: 'Update.exe', - path: expect.stringMatching(msiAwareSquirrelRegex) - } ]; + path: 'C:\\temp\\Update.exe' + } ]; const folderFileTree = - addFilesToTree(mockFolderTree, mockFiles, `slack`, `C:${S}temp${S}slack.exe`, true, false, '1.0.0'); + addFilesToTree(mockFolderTree, mockFiles, mockUpdaterSpecialFiles, mockRegistry, '1.0.0'); expect(folderFileTree).toEqual(updaterMockFolderFileTree); });