From 34adcb749a8d36837a655996929bbd4d8dd2669d Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Fri, 13 Apr 2018 16:26:07 -0700 Subject: [PATCH] Dont depende on workspace settings for tests --- .../emmet/src/test/abbreviationAction.test.ts | 24 ++++++++++--------- extensions/emmet/src/test/tagActions.test.ts | 11 +++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/extensions/emmet/src/test/abbreviationAction.test.ts b/extensions/emmet/src/test/abbreviationAction.test.ts index 8aed9b00830..f9db8a3b944 100644 --- a/extensions/emmet/src/test/abbreviationAction.test.ts +++ b/extensions/emmet/src/test/abbreviationAction.test.ts @@ -5,7 +5,7 @@ import 'mocha'; import * as assert from 'assert'; -import { Selection, workspace, CompletionList, CancellationTokenSource, CompletionTriggerKind } from 'vscode'; +import { Selection, workspace, CompletionList, CancellationTokenSource, CompletionTriggerKind, ConfigurationTarget } from 'vscode'; import { withRandomFileEditor, closeAllEditors } from './testUtils'; import { expandEmmetAbbreviation } from '../abbreviationActions'; import { DefaultCompletionItemProvider } from '../defaultCompletionProvider'; @@ -36,9 +36,10 @@ const htmlContents = ` `; suite('Tests for Expand Abbreviations (HTML)', () => { + const oldValueForExcludeLanguages = workspace.getConfiguration('emmet').inspect('excludeLanguages'); teardown(() => { - // Reset config and close all editors - return workspace.getConfiguration('emmet').update('excludeLanguages', []).then(closeAllEditors); + // close all editors + return closeAllEditors; }); test('Expand snippets (HTML)', () => { @@ -255,25 +256,25 @@ suite('Tests for Expand Abbreviations (HTML)', () => { // }); test('No expanding when html is excluded in the settings', () => { - return workspace.getConfiguration('emmet').update('excludeLanguages', ['html']).then(() => { + return workspace.getConfiguration('emmet').update('excludeLanguages', ['html'], ConfigurationTarget.Global).then(() => { return testExpandAbbreviation('html', new Selection(9, 6, 9, 6), '', '', true).then(() => { - return workspace.getConfiguration('emmet').update('excludeLanguages', []); + return workspace.getConfiguration('emmet').update('excludeLanguages', oldValueForExcludeLanguages ? oldValueForExcludeLanguages.globalValue : undefined, ConfigurationTarget.Global); }); }); }); test('No expanding when html is excluded in the settings in completion list', () => { - return workspace.getConfiguration('emmet').update('excludeLanguages', ['html']).then(() => { + return workspace.getConfiguration('emmet').update('excludeLanguages', ['html'], ConfigurationTarget.Global).then(() => { return testHtmlCompletionProvider(new Selection(9, 6, 9, 6), '', '', true).then(() => { - return workspace.getConfiguration('emmet').update('excludeLanguages', []); + return workspace.getConfiguration('emmet').update('excludeLanguages', oldValueForExcludeLanguages ? oldValueForExcludeLanguages.globalValue : undefined, ConfigurationTarget.Global); }); }); }); test('No expanding when php (mapped syntax) is excluded in the settings', () => { - return workspace.getConfiguration('emmet').update('excludeLanguages', ['php']).then(() => { + return workspace.getConfiguration('emmet').update('excludeLanguages', ['php'], ConfigurationTarget.Global).then(() => { return testExpandAbbreviation('php', new Selection(9, 6, 9, 6), '', '', true).then(() => { - return workspace.getConfiguration('emmet').update('excludeLanguages', []); + return workspace.getConfiguration('emmet').update('excludeLanguages', oldValueForExcludeLanguages ? oldValueForExcludeLanguages.globalValue : undefined, ConfigurationTarget.Global); }); }); }); @@ -282,6 +283,7 @@ suite('Tests for Expand Abbreviations (HTML)', () => { }); suite('Tests for jsx, xml and xsl', () => { + const oldValueForSyntaxProfiles = workspace.getConfiguration('emmet').inspect('syntaxProfiles'); teardown(closeAllEditors); test('Expand abbreviation with className instead of class in jsx', () => { @@ -305,12 +307,12 @@ suite('Tests for jsx, xml and xsl', () => { }); test('Expand abbreviation with single quotes for jsx', () => { - return workspace.getConfiguration('emmet').update('syntaxProfiles', {jsx: {"attr_quotes": "single"}}).then(() => { + return workspace.getConfiguration('emmet').update('syntaxProfiles', {jsx: {"attr_quotes": "single"}}, ConfigurationTarget.Global).then(() => { return withRandomFileEditor('img', 'javascriptreact', (editor, doc) => { editor.selection = new Selection(0, 6, 0, 6); return expandEmmetAbbreviation({ language: 'javascriptreact' }).then(() => { assert.equal(editor.document.getText(), '\'\'/'); - return workspace.getConfiguration('emmet').update('syntaxProfiles', {}); + return workspace.getConfiguration('emmet').update('syntaxProfiles', oldValueForSyntaxProfiles ? oldValueForSyntaxProfiles.globalValue : undefined, ConfigurationTarget.Global); }); }); }); diff --git a/extensions/emmet/src/test/tagActions.test.ts b/extensions/emmet/src/test/tagActions.test.ts index ed69ae7d11c..4c721cf4d54 100644 --- a/extensions/emmet/src/test/tagActions.test.ts +++ b/extensions/emmet/src/test/tagActions.test.ts @@ -5,7 +5,7 @@ import 'mocha'; import * as assert from 'assert'; -import { Selection, workspace } from 'vscode'; +import { Selection, workspace, ConfigurationTarget } from 'vscode'; import { withRandomFileEditor, closeAllEditors } from './testUtils'; import { removeTag } from '../removeTag'; import { updateTag } from '../updateTag'; @@ -15,8 +15,8 @@ import { mergeLines } from '../mergeLines'; suite('Tests for Emmet actions on html tags', () => { teardown(() => { - // Reset config and close all editors - return workspace.getConfiguration('emmet').update('syntaxProfiles', {}).then(closeAllEditors); + // close all editors + return closeAllEditors; }); const contents = ` @@ -116,7 +116,8 @@ suite('Tests for Emmet actions on html tags', () => { `; - return workspace.getConfiguration('emmet').update('syntaxProfiles', {jsx: {selfClosingStyle: 'xhtml'}}).then(() =>{ + const oldValueForSyntaxProfiles = workspace.getConfiguration('emmet').inspect('syntaxProfiles'); + return workspace.getConfiguration('emmet').update('syntaxProfiles', {jsx: {selfClosingStyle: 'xhtml'}}, ConfigurationTarget.Global).then(() =>{ return withRandomFileEditor(contents, 'jsx', (editor, doc) => { editor.selections = [ new Selection(3, 17, 3, 17), // join tag @@ -125,7 +126,7 @@ suite('Tests for Emmet actions on html tags', () => { return splitJoinTag()!.then(() => { assert.equal(doc.getText(), expectedContents); - return workspace.getConfiguration('emmet').update('syntaxProfiles', {}); + return workspace.getConfiguration('emmet').update('syntaxProfiles', oldValueForSyntaxProfiles ? oldValueForSyntaxProfiles.globalValue : undefined, ConfigurationTarget.Global); }); }); }); -- GitLab