Skip to content

Commit

Permalink
Unit tests, documentation, deps
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt authored Jun 20, 2022
1 parent 61a5fc8 commit b764ceb
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ Key | Type | Allowed | Default
`windowMode` | String | `'normal'`, `'maximized'`, `'minimized'` | `'normal'` | How the window should be displayed by default
`hotkey` | String | Any string | None | A global hotkey to associate to opening this shortcut, like `'CTRL+ALT+F'`
`workingDirectory` | String | Any valid path to a folder | None | The working directory for the shortcut when it launches
`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.


### Linux Settings
Expand All @@ -172,7 +173,7 @@ Key | Type | Allowed | Default

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.

**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).
**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).

Key | Type | Allowed | Default | Description
:-- | :-- | :-- | :-- | :--
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-desktop-shortcuts",
"main": "index.js",
"version": "1.9.0",
"version": "1.10.0",
"description": "Easy API to create desktop shortcuts with Node",
"author": "The Jared Wilcurt",
"keywords": [
Expand Down Expand Up @@ -33,11 +33,11 @@
"devDependencies": {
"@babel/core": "^7.18.5",
"@babel/eslint-parser": "^7.18.2",
"eslint": "^8.17.0",
"eslint": "^8.18.0",
"eslint-config-tjw-base": "^2.0.0",
"eslint-config-tjw-jest": "^2.0.0",
"eslint-config-tjw-jsdoc": "^1.0.2",
"eslint-plugin-jsdoc": "^39.3.2",
"eslint-plugin-jsdoc": "^39.3.3",
"fs-extra": "8.1.0",
"get-windows-shortcut-properties": "^1.1.0",
"jest": "24.9.0",
Expand Down
17 changes: 13 additions & 4 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,24 @@ const validation = {

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

if (options.windows.VBScriptPath && !fs.existsSync(options.windows.VBScriptPath)) {
options.windows.VBScriptPath = undefined;
if (options.windows.VBScriptPath) {
if (!fs.existsSync(options.windows.VBScriptPath)) {
helpers.throwError(options, 'Optional WINDOWS VBScriptPath path does not exist: ' + options.windows.VBScriptPath);
delete options.windows.VBScriptPath;
return options;
}
if (fs.lstatSync(options.windows.VBScriptPath).isDirectory()) {
helpers.throwError(options, 'Optional WINDOWS VBScriptPath path must not be a directory: ' + options.windows.VBScriptPath);
delete options.windows.VBScriptPath;
return options;
}
}

if (
!options.windows.VBScriptPath ||
typeof(options.windows.VBScriptPath) !== 'string'
) {
options.windows.VBScriptPath = undefined;
delete options.windows.VBScriptPath;
}

return options;
Expand Down Expand Up @@ -608,7 +617,7 @@ const validation = {
return options;
}

options = this.validateWindowsVBScriptPath(options);
options = this.validateWindowsVBScriptPath(options);
options = this.validateWindowsWindowMode(options);
options = this.validateWindowsIcon(options);
options = this.validateWindowsComment(options);
Expand Down
30 changes: 30 additions & 0 deletions tests/src/library.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,36 @@ describe('library', () => {
.not.toHaveBeenCalled();
});

test('Custom vbscript', () => {
const VBScriptPath = 'C:\\win.vbs';
options.windows.VBScriptPath = VBScriptPath;

expect(library.makeWindowsShortcut(options))
.toEqual(true);

expect(customLogger)
.not.toHaveBeenCalled();

expect(childProcess.execSync)
.not.toHaveBeenCalled();

expect(childProcess.spawnSync)
.toHaveBeenLastCalledWith(
'wscript',
[
VBScriptPath,
'C:/Users/DUMMY/Desktop/file.lnk',
'C:/file.ext',
'',
'',
'',
'C:/file.ext',
1,
''
]
);
});

test('Catch error', () => {
options.windows.filePath = 'Throw Error';

Expand Down
68 changes: 68 additions & 0 deletions tests/src/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,74 @@ describe('Validation', () => {
});
});

describe('validateWindowsVBScriptPath', () => {
beforeEach(() => {
delete options.windows.filePath;
delete options.windows.outputPath;
});

test('Empty options', () => {
expect(validation.validateWindowsVBScriptPath({}))
.toEqual({});
});

test('Empty windows object', () => {
expect(validation.validateWindowsVBScriptPath(options))
.toEqual({
...defaults,
customLogger,
windows: {}
});

expect(customLogger)
.not.toHaveBeenCalled();
});

test('Path does not exist', () => {
options.windows.VBScriptPath = 'C:\\fake\\path';

expect(validation.validateWindowsVBScriptPath(options))
.toEqual({
...defaults,
customLogger,
windows: {}
});

expect(customLogger)
.toHaveBeenCalledWith('Optional WINDOWS VBScriptPath path does not exist: C:\\fake\\path', undefined);
});

test('Path is not a directory', () => {
options.windows.VBScriptPath = 'C:\\folder';

expect(validation.validateWindowsVBScriptPath(options))
.toEqual({
...defaults,
customLogger,
windows: {}
});

expect(customLogger)
.toHaveBeenCalledWith('Optional WINDOWS VBScriptPath path must not be a directory: C:\\folder', undefined);
});

test('Custom VBScript exists', () => {
options.windows.VBScriptPath = 'C:\\win.vbs';

expect(validation.validateWindowsVBScriptPath(options))
.toEqual({
...defaults,
customLogger,
windows: {
VBScriptPath: 'C:\\win.vbs'
}
});

expect(customLogger)
.not.toHaveBeenCalled();
});
});

describe('validateWindowsWindowMode', () => {
test('Empty options', () => {
expect(validation.validateWindowsWindowMode({}))
Expand Down
2 changes: 2 additions & 0 deletions tests/testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const testHelpers = {
});
const Windows = {
[vbs]: 'text',
'C:\\win.vbs': 'text',
'C:\\file.ext': 'text',
'C:\\folder': {},
'C:\\Program Files\\DUMMY\\app.exe': windowsExecutable,
Expand All @@ -165,6 +166,7 @@ const testHelpers = {
};
let WindowsInLinuxCI = {
[vbsLinux]: 'text',
'C:\\win.vbs': 'text',
'C:/file.ext': 'text',
'C:/folder': {},
'C:\\Program Files\\DUMMY\\app.exe': windowsExecutable,
Expand Down

0 comments on commit b764ceb

Please sign in to comment.