Skip to content

Commit

Permalink
fix(associations): fix crash when workspace & user settings have asso… (
Browse files Browse the repository at this point in the history
vscode-icons#1708)

* fix(associations): fix crash when workspace & user settings have associations

* refactor(tests): change equals alias for equal
  • Loading branch information
robertohuertasm authored Sep 9, 2018
1 parent 1ce7d90 commit 1aa1465
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/utils/vscode-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getConfig(): vscode.WorkspaceConfiguration {

export function getVsiconsConfig(): IVSIcons {
const config = vscode.workspace.getConfiguration();
const mergedConfig = config.vsicons;
const mergedConfig = _.cloneDeep(config.vsicons);
const files = config.inspect<IFileExtension[]>('vsicons.associations.files');
const folders = config.inspect<IFileExtension[]>(
'vsicons.associations.folders',
Expand Down
22 changes: 11 additions & 11 deletions test/manifestMerger/fileExtensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('FileExtensions: merging configuration documents', function() {
const def = json.iconDefinitions['_f_actionscript'];
expect(def).exist;
expect(def.iconPath).exist;
expect(json.fileExtensions['as2']).to.equals('_f_actionscript');
expect(path.extname(def.iconPath)).to.equals('.svg');
expect(json.fileExtensions['as2']).to.equal('_f_actionscript');
expect(path.extname(def.iconPath)).to.equal('.svg');
});

it('overrides removes the specified extension', function() {
Expand Down Expand Up @@ -112,9 +112,9 @@ describe('FileExtensions: merging configuration documents', function() {
const newPath = json.iconDefinitions['_f_newExt'].iconPath;
expect(extendedDef).not.to.exist;
expect(newPath).exist;
expect(json.fileExtensions['as']).to.equals('_f_newExt');
expect(json.fileExtensions['mynew']).to.equals('_f_newExt');
expect(path.extname(newPath)).not.to.equals('.svg');
expect(json.fileExtensions['as']).to.equal('_f_newExt');
expect(json.fileExtensions['mynew']).to.equal('_f_newExt');
expect(path.extname(newPath)).not.to.equal('.svg');
});

it('disabled extensions are not included into the manifest', function() {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('FileExtensions: merging configuration documents', function() {
const ngGroup = Object.keys(json.iconDefinitions).filter(x =>
/^_f_ng_.*2$/.test(x),
);
expect(ngGroup.length).to.equals(14);
expect(ngGroup.length).to.equal(14);
});

it('are removed from the original extension', function() {
Expand All @@ -268,8 +268,8 @@ describe('FileExtensions: merging configuration documents', function() {
iconGenerator,
);
expect(json.iconDefinitions['_f_newExt']).exist;
expect(json.fileExtensions['bin']).to.equals('_f_newExt');
expect(json.fileExtensions['o']).to.equals('_f_newExt');
expect(json.fileExtensions['bin']).to.equal('_f_newExt');
expect(json.fileExtensions['o']).to.equal('_f_newExt');
});

it('accept languageId', function() {
Expand All @@ -292,7 +292,7 @@ describe('FileExtensions: merging configuration documents', function() {
iconGenerator,
);
expect(json.iconDefinitions['_f_actionscript']).exist;
expect(json.languageIds['newlang']).to.equals('_f_actionscript');
expect(json.languageIds['newlang']).to.equal('_f_actionscript');
});
});

Expand All @@ -317,7 +317,7 @@ describe('FileExtensions: merging configuration documents', function() {
);
const customDef = json.iconDefinitions['_f_custom_icon'];
expect(customDef).exist;
expect(path.extname(customDef.iconPath)).to.equals('.svg');
expect(path.extname(customDef.iconPath)).to.equal('.svg');
});

it('has a custom path', function() {
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('FileExtensions: merging configuration documents', function() {
expect(customDef.iconPath).to.contain(
extensionSettings.customIconFolderName,
);
expect(json.fileExtensions['custom']).to.equals('_f_custom_icon');
expect(json.fileExtensions['custom']).to.equal('_f_custom_icon');
} finally {
fs.unlinkSync(iconNamePath);
}
Expand Down
32 changes: 16 additions & 16 deletions test/manifestMerger/folderExtensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ describe('FolderExtensions: merging configuration documents', function() {
const def = json.iconDefinitions['_fd_aws'];
expect(def).exist;
expect(def.iconPath).exist;
expect(json.folderNames['aws3']).to.equals('_fd_aws');
expect(json.folderNamesExpanded['aws3']).to.equals('_fd_aws_open');
expect(path.extname(def.iconPath)).to.equals('.svg');
expect(json.folderNames['aws3']).to.equal('_fd_aws');
expect(json.folderNamesExpanded['aws3']).to.equal('_fd_aws_open');
expect(path.extname(def.iconPath)).to.equal('.svg');
});

it('overrides removes the specified extension', function() {
Expand Down Expand Up @@ -112,11 +112,11 @@ describe('FolderExtensions: merging configuration documents', function() {
const newPath = json.iconDefinitions['_fd_newExt'].iconPath;
expect(extendedPath).not.to.exist;
expect(newPath).exist;
expect(json.folderNames['aws']).to.equals('_fd_newExt');
expect(json.folderNamesExpanded['aws']).to.equals('_fd_newExt_open');
expect(json.folderNames['mynew']).to.equals('_fd_newExt');
expect(json.folderNamesExpanded['mynew']).to.equals('_fd_newExt_open');
expect(path.extname(newPath)).not.to.equals('.svg');
expect(json.folderNames['aws']).to.equal('_fd_newExt');
expect(json.folderNamesExpanded['aws']).to.equal('_fd_newExt_open');
expect(json.folderNames['mynew']).to.equal('_fd_newExt');
expect(json.folderNamesExpanded['mynew']).to.equal('_fd_newExt_open');
expect(path.extname(newPath)).not.to.equal('.svg');
});

it('disabled extensions are not included into the manifest', function() {
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('FolderExtensions: merging configuration documents', function() {
iconGenerator,
);
expect(json.iconDefinitions['_fd_newExt']).exist;
expect(json.folderNames['aws']).to.equals('_fd_newExt');
expect(json.folderNames['aws']).to.equal('_fd_newExt');
});

context('custom icon', function() {
Expand All @@ -211,7 +211,7 @@ describe('FolderExtensions: merging configuration documents', function() {
);
const customDef = json.iconDefinitions['_fd_custom_icon'];
expect(customDef).exist;
expect(path.extname(customDef.iconPath)).to.equals('.svg');
expect(path.extname(customDef.iconPath)).to.equal('.svg');
});

it('has a custom path', function() {
Expand Down Expand Up @@ -258,8 +258,8 @@ describe('FolderExtensions: merging configuration documents', function() {
expect(customDef.iconPath).contains(
extensionSettings.customIconFolderName,
);
expect(json.folderNames['custom']).to.equals('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equals(
expect(json.folderNames['custom']).to.equal('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equal(
'_fd_custom_icon_open',
);
} finally {
Expand Down Expand Up @@ -317,8 +317,8 @@ describe('FolderExtensions: merging configuration documents', function() {
const customDef = json.iconDefinitions['_fd_custom_icon'];
expect(customDef).exist;
expect(customDef.iconPath).to.contain(customIconFolderPathFull);
expect(json.folderNames['custom']).to.equals('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equals(
expect(json.folderNames['custom']).to.equal('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equal(
'_fd_custom_icon_open',
);
} finally {
Expand Down Expand Up @@ -377,8 +377,8 @@ describe('FolderExtensions: merging configuration documents', function() {
expect(
customDef.iconPath.startsWith(iconGenerator.iconsFolderBasePath),
).to.be.true;
expect(json.folderNames['custom']).to.equals('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equals(
expect(json.folderNames['custom']).to.equal('_fd_custom_icon');
expect(json.folderNamesExpanded['custom']).to.equal(
'_fd_custom_icon_open',
);
} finally {
Expand Down
8 changes: 4 additions & 4 deletions test/manifestMerger/presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('Presets: merging configuration documents', function() {
const nggroup = result.supported.filter(
x => x.icon.startsWith('ng_') && x.disabled,
);
expect(nggroup.length).to.equals(34);
expect(nggroup.length).to.equal(34);
});

it('only first set of angular extensions get enabled', function() {
const result = iconManifest.toggleAngularPreset(false, fileExtensions);
const nggroup = result.supported.filter(
x => x.icon.startsWith('ng_') && !x.disabled,
);
expect(nggroup.length).to.equals(18);
expect(nggroup.length).to.equal(18);
});

it('only second set of angular extensions get enabled', function() {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Presets: merging configuration documents', function() {
const ngGroup = result.supported.filter(
x => /^ng_.*2$/.test(x.icon) && !x.disabled,
);
expect(ngGroup.length).to.equals(16);
expect(ngGroup.length).to.equal(16);
});

it('all angular extensions are disabled even if duplicity is present', function() {
Expand All @@ -113,7 +113,7 @@ describe('Presets: merging configuration documents', function() {
const ngGroup = result.supported.filter(
x => x.icon.startsWith('ng_') && x.disabled,
);
expect(ngGroup.length).to.equals(4);
expect(ngGroup.length).to.equal(4);
});

it('JS official extension is enabled', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Utils: tests', function() {
utils.createDirectoryRecursively(directoryPath);

expect(fileCheck.called).to.be.true;
expect(createDirectory.callCount).to.equals(expectedCounts);
expect(createDirectory.callCount).to.equal(expectedCounts);

sandbox.restore();
};
Expand Down
18 changes: 9 additions & 9 deletions test/utils/vscode-extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('vscode-extensions: tests', function() {
},
];
config.vsicons.associations.files = config.files.globalValue;
expect(vsExt.getVsiconsConfig()).to.equals(config.vsicons);
expect(vsExt.getVsiconsConfig()).to.deep.equal(config.vsicons);
});

it(`the configuration's vsicons property if workspaceValue is an empty array`, function() {
Expand All @@ -104,7 +104,7 @@ describe('vscode-extensions: tests', function() {
];
config.files.workspaceValue = [];
config.vsicons.associations.files = config.files.globalValue;
expect(vsExt.getVsiconsConfig()).to.equals(config.vsicons);
expect(vsExt.getVsiconsConfig()).to.deep.equal(config.vsicons);
});

it('both workspace and global settings for files', function() {
Expand All @@ -124,7 +124,7 @@ describe('vscode-extensions: tests', function() {
];
// if workspaceValue is present vsicons will return it.
config.vsicons.associations.files = config.files.workspaceValue;
expect(vsExt.getVsiconsConfig().associations.files).to.deep.equals([
expect(vsExt.getVsiconsConfig().associations.files).to.deep.equal([
{
icon: 'js2',
extensions: ['myExt1', 'myExt2.custom.js'],
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('vscode-extensions: tests', function() {
];
// if workspaceValue is present vsicons will return it.
config.vsicons.associations.files = config.files.workspaceValue;
expect(vsExt.getVsiconsConfig().associations.files).to.deep.equals([
expect(vsExt.getVsiconsConfig().associations.files).to.deep.equal([
{
icon: 'js',
extensions: ['myExt1', 'myExt2.custom.js'],
Expand All @@ -185,7 +185,7 @@ describe('vscode-extensions: tests', function() {
},
];
config.vsicons.associations.folders = config.folders.globalValue;
expect(vsExt.getVsiconsConfig()).to.equals(config.vsicons);
expect(vsExt.getVsiconsConfig()).to.deep.equal(config.vsicons);
});

it(`the configuration's vsicons property if workspaceValue is an empty array`, function() {
Expand All @@ -197,8 +197,8 @@ describe('vscode-extensions: tests', function() {
},
];
config.folders.workspaceValue = [];
config.vsicons.associations.files = config.folders.globalValue;
expect(vsExt.getVsiconsConfig()).to.equals(config.vsicons);
config.vsicons.associations.folders = config.folders.globalValue;
expect(vsExt.getVsiconsConfig()).to.deep.equal(config.vsicons);
});

it('both workspace and global settings for files', function() {
Expand All @@ -218,7 +218,7 @@ describe('vscode-extensions: tests', function() {
];
// if workspaceValue is present vsicons will return it.
config.vsicons.associations.folders = config.folders.workspaceValue;
expect(vsExt.getVsiconsConfig().associations.folders).to.deep.equals([
expect(vsExt.getVsiconsConfig().associations.folders).to.deep.equal([
{
icon: 'js2',
extensions: ['myExt1', 'myExt2.custom.js'],
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('vscode-extensions: tests', function() {
];
// if workspaceValue is present vsicons will return it.
config.vsicons.associations.folders = config.folders.workspaceValue;
expect(vsExt.getVsiconsConfig().associations.folders).to.deep.equals([
expect(vsExt.getVsiconsConfig().associations.folders).to.deep.equal([
{
icon: 'js',
extensions: ['myExt1', 'myExt2.custom.js'],
Expand Down

0 comments on commit 1aa1465

Please sign in to comment.