Skip to content

Commit b764ceb

Browse files
Unit tests, documentation, deps
1 parent 61a5fc8 commit b764ceb

File tree

7 files changed

+128
-18
lines changed

7 files changed

+128
-18
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Key | Type | Allowed | Default
151151
`windowMode` | String | `'normal'`, `'maximized'`, `'minimized'` | `'normal'` | How the window should be displayed by default
152152
`hotkey` | String | Any string | None | A global hotkey to associate to opening this shortcut, like `'CTRL+ALT+F'`
153153
`workingDirectory` | String | Any valid path to a folder | None | The working directory for the shortcut when it launches
154+
`VBScriptPath` | String | Path to external VBS file | None | This is an advanced option specifically for projects packaged with `pkg`. You can create a copy of the `windows.vbs` file outside of your packaged executable and pass in the location of it. If your `vbs` file differs in any way to the version shipped with this library, it will have bugs. Ensure you are programmatically copying the shipped version, so if it changes in a future update, your code will still work. If you are not using `pkg`, you should not include `VBScriptPath` in your Windows settings.
154155

155156

156157
### Linux Settings
@@ -172,7 +173,7 @@ Key | Type | Allowed | Default
172173

173174
OSX will automatically inherit the icon of the target you point to. It doesn't care if you point to a folder, file, or application.
174175

175-
**NOTE:** If `overwrite` is set to `false` and a matching file already exists, a `console.error` will occur to inform you of this, however `create-desktop-shortcuts` will still report successful (return `true`). This `console.error` can be hidden by setting `verbose` to `false`, or using a `customLogger` to [intercept it](https://github.com/nwutils/create-desktop-shortcuts/blob/main/src/library.js#L252).
176+
**NOTE:** If `overwrite` is set to `false` and a matching file already exists, a `console.error` will occur to inform you of this, however `create-desktop-shortcuts` will still report successful (return `true`). This `console.error` can be hidden by setting `verbose` to `false`, or using a `customLogger` to [intercept it](https://github.com/nwutils/create-desktop-shortcuts/blob/main/src/library.js#L260).
176177

177178
Key | Type | Allowed | Default | Description
178179
:-- | :-- | :-- | :-- | :--

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "create-desktop-shortcuts",
33
"main": "index.js",
4-
"version": "1.9.0",
4+
"version": "1.10.0",
55
"description": "Easy API to create desktop shortcuts with Node",
66
"author": "The Jared Wilcurt",
77
"keywords": [
@@ -33,11 +33,11 @@
3333
"devDependencies": {
3434
"@babel/core": "^7.18.5",
3535
"@babel/eslint-parser": "^7.18.2",
36-
"eslint": "^8.17.0",
36+
"eslint": "^8.18.0",
3737
"eslint-config-tjw-base": "^2.0.0",
3838
"eslint-config-tjw-jest": "^2.0.0",
3939
"eslint-config-tjw-jsdoc": "^1.0.2",
40-
"eslint-plugin-jsdoc": "^39.3.2",
40+
"eslint-plugin-jsdoc": "^39.3.3",
4141
"fs-extra": "8.1.0",
4242
"get-windows-shortcut-properties": "^1.1.0",
4343
"jest": "24.9.0",

src/validation.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,24 @@ const validation = {
425425

426426
options.windows.VBScriptPath = helpers.resolveWindowsEnvironmentVariables(options.windows.VBScriptPath);
427427

428-
if (options.windows.VBScriptPath && !fs.existsSync(options.windows.VBScriptPath)) {
429-
options.windows.VBScriptPath = undefined;
428+
if (options.windows.VBScriptPath) {
429+
if (!fs.existsSync(options.windows.VBScriptPath)) {
430+
helpers.throwError(options, 'Optional WINDOWS VBScriptPath path does not exist: ' + options.windows.VBScriptPath);
431+
delete options.windows.VBScriptPath;
432+
return options;
433+
}
434+
if (fs.lstatSync(options.windows.VBScriptPath).isDirectory()) {
435+
helpers.throwError(options, 'Optional WINDOWS VBScriptPath path must not be a directory: ' + options.windows.VBScriptPath);
436+
delete options.windows.VBScriptPath;
437+
return options;
438+
}
430439
}
431440

432441
if (
433442
!options.windows.VBScriptPath ||
434443
typeof(options.windows.VBScriptPath) !== 'string'
435444
) {
436-
options.windows.VBScriptPath = undefined;
445+
delete options.windows.VBScriptPath;
437446
}
438447

439448
return options;
@@ -608,7 +617,7 @@ const validation = {
608617
return options;
609618
}
610619

611-
options = this.validateWindowsVBScriptPath(options);
620+
options = this.validateWindowsVBScriptPath(options);
612621
options = this.validateWindowsWindowMode(options);
613622
options = this.validateWindowsIcon(options);
614623
options = this.validateWindowsComment(options);

tests/src/library.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,36 @@ describe('library', () => {
564564
.not.toHaveBeenCalled();
565565
});
566566

567+
test('Custom vbscript', () => {
568+
const VBScriptPath = 'C:\\win.vbs';
569+
options.windows.VBScriptPath = VBScriptPath;
570+
571+
expect(library.makeWindowsShortcut(options))
572+
.toEqual(true);
573+
574+
expect(customLogger)
575+
.not.toHaveBeenCalled();
576+
577+
expect(childProcess.execSync)
578+
.not.toHaveBeenCalled();
579+
580+
expect(childProcess.spawnSync)
581+
.toHaveBeenLastCalledWith(
582+
'wscript',
583+
[
584+
VBScriptPath,
585+
'C:/Users/DUMMY/Desktop/file.lnk',
586+
'C:/file.ext',
587+
'',
588+
'',
589+
'',
590+
'C:/file.ext',
591+
1,
592+
''
593+
]
594+
);
595+
});
596+
567597
test('Catch error', () => {
568598
options.windows.filePath = 'Throw Error';
569599

tests/src/validation.test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,74 @@ describe('Validation', () => {
795795
});
796796
});
797797

798+
describe('validateWindowsVBScriptPath', () => {
799+
beforeEach(() => {
800+
delete options.windows.filePath;
801+
delete options.windows.outputPath;
802+
});
803+
804+
test('Empty options', () => {
805+
expect(validation.validateWindowsVBScriptPath({}))
806+
.toEqual({});
807+
});
808+
809+
test('Empty windows object', () => {
810+
expect(validation.validateWindowsVBScriptPath(options))
811+
.toEqual({
812+
...defaults,
813+
customLogger,
814+
windows: {}
815+
});
816+
817+
expect(customLogger)
818+
.not.toHaveBeenCalled();
819+
});
820+
821+
test('Path does not exist', () => {
822+
options.windows.VBScriptPath = 'C:\\fake\\path';
823+
824+
expect(validation.validateWindowsVBScriptPath(options))
825+
.toEqual({
826+
...defaults,
827+
customLogger,
828+
windows: {}
829+
});
830+
831+
expect(customLogger)
832+
.toHaveBeenCalledWith('Optional WINDOWS VBScriptPath path does not exist: C:\\fake\\path', undefined);
833+
});
834+
835+
test('Path is not a directory', () => {
836+
options.windows.VBScriptPath = 'C:\\folder';
837+
838+
expect(validation.validateWindowsVBScriptPath(options))
839+
.toEqual({
840+
...defaults,
841+
customLogger,
842+
windows: {}
843+
});
844+
845+
expect(customLogger)
846+
.toHaveBeenCalledWith('Optional WINDOWS VBScriptPath path must not be a directory: C:\\folder', undefined);
847+
});
848+
849+
test('Custom VBScript exists', () => {
850+
options.windows.VBScriptPath = 'C:\\win.vbs';
851+
852+
expect(validation.validateWindowsVBScriptPath(options))
853+
.toEqual({
854+
...defaults,
855+
customLogger,
856+
windows: {
857+
VBScriptPath: 'C:\\win.vbs'
858+
}
859+
});
860+
861+
expect(customLogger)
862+
.not.toHaveBeenCalled();
863+
});
864+
});
865+
798866
describe('validateWindowsWindowMode', () => {
799867
test('Empty options', () => {
800868
expect(validation.validateWindowsWindowMode({}))

tests/testHelpers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const testHelpers = {
153153
});
154154
const Windows = {
155155
[vbs]: 'text',
156+
'C:\\win.vbs': 'text',
156157
'C:\\file.ext': 'text',
157158
'C:\\folder': {},
158159
'C:\\Program Files\\DUMMY\\app.exe': windowsExecutable,
@@ -165,6 +166,7 @@ const testHelpers = {
165166
};
166167
let WindowsInLinuxCI = {
167168
[vbsLinux]: 'text',
169+
'C:\\win.vbs': 'text',
168170
'C:/file.ext': 'text',
169171
'C:/folder': {},
170172
'C:\\Program Files\\DUMMY\\app.exe': windowsExecutable,

0 commit comments

Comments
 (0)