-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/redhat-developer/vscode-yaml
- Loading branch information
Showing
17 changed files
with
345 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules/ | ||
out/ | ||
.vscode-test/ | ||
test/testFixture/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,19 @@ os: | |
- osx | ||
- linux | ||
before_install: | ||
- if [ $TRAVIS_OS_NAME == "linux" ]; then export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0; | ||
sh -e /etc/init.d/xvfb start; sleep 3; fi | ||
- npm install -g [email protected] | ||
install: | ||
- | | ||
if [ $TRAVIS_OS_NAME == "linux" ]; then | ||
export DISPLAY=':99.0'; | ||
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & | ||
fi | ||
- npm install | ||
- npm run vscode:prepublish | ||
- npm install -g vsce | ||
- vsce package | ||
script: | ||
- npm test --silent | ||
- npm test | ||
deploy: | ||
provider : npm | ||
email : [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
export CODE_TESTS_PATH="$(pwd)/out/test" | ||
export CODE_TESTS_WORKSPACE="$(pwd)/test/testFixture" | ||
export CODE_DISABLE_EXTENSIONS=1 | ||
|
||
node "$(pwd)/node_modules/vscode/bin/test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import * as vscode from 'vscode'; | ||
import { getDocUri, activate, testCompletion, updateSettings, testCompletionNotEmpty, resetSettings } from './helper'; | ||
|
||
|
||
describe('Completion should work in multiple different scenarios', () => { | ||
const docUri = getDocUri('completion/completion.yaml'); | ||
const travisUri = getDocUri('completion/.travis.yml'); | ||
|
||
afterEach(async () => { | ||
await resetSettings("schemas", {}); | ||
await resetSettings("schemaStore.enable", true); | ||
}); | ||
|
||
it('completion works with local schema', async () => { | ||
await activate(docUri); | ||
await updateSettings("schemas", { | ||
"./schemas/basic_completion_schema.json": "completion.yaml" | ||
}); | ||
await testCompletion(docUri, new vscode.Position(0, 0), { | ||
items: [ | ||
{ | ||
label: "my_key", | ||
kind: 9 | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('completion works with external schema', async () => { | ||
await activate(docUri); | ||
await updateSettings("schemas", { | ||
"https://gist.githubusercontent.com/JPinkney/4c4a43977932402c2a09a677f29287c3/raw/4d4f638b37ddeda84fb27e6b2cf14d3dc0793029/a.yaml": "completion.yaml" | ||
}); | ||
await testCompletion(docUri, new vscode.Position(0, 0), { | ||
items: [ | ||
{ | ||
label: "version", | ||
kind: 9 | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
it('completion works with schema store schema', async () => { | ||
await activate(travisUri); | ||
await updateSettings("schemaStore.enable", true); | ||
await testCompletionNotEmpty(travisUri, new vscode.Position(0, 0)); | ||
}); | ||
|
||
it('completion does not work with schema store disabled and no schemas set', async () => { | ||
await activate(travisUri); | ||
await updateSettings("schemaStore.enable", false); | ||
await testCompletion(travisUri, new vscode.Position(0, 0), { | ||
items: [] | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import assert = require('assert'); | ||
|
||
export let doc: vscode.TextDocument; | ||
export let editor: vscode.TextEditor; | ||
export let documentEol: string; | ||
export let platformEol: string; | ||
|
||
/** | ||
* Activates the redhat.vscode-yaml extension | ||
*/ | ||
export async function activate(docUri: vscode.Uri) { | ||
const ext = vscode.extensions.getExtension('redhat.vscode-yaml')!; | ||
const activation = await ext.activate(); | ||
try { | ||
doc = await vscode.workspace.openTextDocument(docUri); | ||
editor = await vscode.window.showTextDocument(doc); | ||
await sleep(2000); // Wait for server activation | ||
return activation; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
export async function sleep(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
export const getDocPath = (p: string) => { | ||
return path.resolve(__dirname, '../../test/testFixture', p); | ||
}; | ||
|
||
export const getDocUri = (p: string) => { | ||
return vscode.Uri.file(getDocPath(p)); | ||
}; | ||
|
||
export const updateSettings = (setting: any, value: any) => { | ||
const yamlConfiguration = vscode.workspace.getConfiguration("yaml"); | ||
return yamlConfiguration.update(setting, value, false); | ||
} | ||
|
||
export const resetSettings = (setting: any, value: any) => { | ||
const yamlConfiguration = vscode.workspace.getConfiguration("yaml"); | ||
return yamlConfiguration.update(setting, value, false); | ||
} | ||
|
||
export async function setTestContent(content: string): Promise<boolean> { | ||
const all = new vscode.Range( | ||
doc.positionAt(0), | ||
doc.positionAt(doc.getText().length) | ||
); | ||
return editor.edit(eb => eb.replace(all, content)); | ||
} | ||
|
||
export async function testCompletion( | ||
docUri: vscode.Uri, | ||
position: vscode.Position, | ||
expectedCompletionList: vscode.CompletionList | ||
) { | ||
|
||
// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion | ||
const actualCompletionList = (await vscode.commands.executeCommand( | ||
'vscode.executeCompletionItemProvider', | ||
docUri, | ||
position | ||
)) as vscode.CompletionList; | ||
|
||
assert.equal(actualCompletionList.items.length, expectedCompletionList.items.length); | ||
expectedCompletionList.items.forEach((expectedItem, i) => { | ||
const actualItem = actualCompletionList.items[i]; | ||
assert.equal(actualItem.label, expectedItem.label); | ||
assert.equal(actualItem.kind, expectedItem.kind); | ||
}); | ||
} | ||
|
||
export async function testCompletionNotEmpty( | ||
docUri: vscode.Uri, | ||
position: vscode.Position | ||
) { | ||
|
||
// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion | ||
const actualCompletionList = (await vscode.commands.executeCommand( | ||
'vscode.executeCompletionItemProvider', | ||
docUri, | ||
position | ||
)) as vscode.CompletionList; | ||
|
||
assert.notEqual(actualCompletionList.items.length, 0); | ||
} | ||
|
||
export async function testHover( | ||
docUri: vscode.Uri, | ||
position: vscode.Position, | ||
expectedHover: vscode.Hover[] | ||
) { | ||
|
||
// Executing the command `vscode.executeCompletionItemProvider` to simulate triggering completion | ||
const actualHoverResults = (await vscode.commands.executeCommand( | ||
'vscode.executeHoverProvider', | ||
docUri, | ||
position | ||
)) as vscode.Hover[]; | ||
|
||
assert.equal(actualHoverResults.length, expectedHover.length); | ||
expectedHover.forEach((expectedItem, i) => { | ||
const actualItem = actualHoverResults[i]; | ||
assert.equal((actualItem.contents[i] as vscode.MarkdownString).value, expectedItem.contents[i]); | ||
}); | ||
} | ||
|
||
export async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) { | ||
const actualDiagnostics = vscode.languages.getDiagnostics(docUri); | ||
|
||
assert.equal(actualDiagnostics.length, expectedDiagnostics.length); | ||
|
||
expectedDiagnostics.forEach((expectedDiagnostic, i) => { | ||
const actualDiagnostic = actualDiagnostics[i] | ||
assert.equal(actualDiagnostic.message, expectedDiagnostic.message) | ||
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range) | ||
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.