Skip to content

Commit 7a66d53

Browse files
authored
Merge pull request #252 from apisim/fix-251
[FIX-251] Tests fail when upgrading dependencies
2 parents b9a8f2d + 2289e9c commit 7a66d53

File tree

9 files changed

+428
-2659
lines changed

9 files changed

+428
-2659
lines changed

package-lock.json

Lines changed: 0 additions & 2295 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
},
3131
"dependencies": {
3232
"js-yaml": "^3.13.1",
33-
"jsonc-parser": "^2.1.0",
33+
"jsonc-parser": "^2.2.1",
3434
"request-light": "^0.2.4",
35-
"vscode-json-languageservice": "^3.3.0",
35+
"vscode-json-languageservice": "^3.5.2",
3636
"vscode-languageserver": "^5.2.1",
37-
"vscode-languageserver-types": "^3.14.0",
38-
"vscode-nls": "^4.1.1",
39-
"vscode-uri": "^2.0.3",
37+
"vscode-languageserver-types": "^3.15.1",
38+
"vscode-nls": "^4.1.2",
39+
"vscode-uri": "^2.1.1",
4040
"yaml-ast-parser-custom-tags": "0.0.43"
4141
},
4242
"optionalDependencies": {
@@ -52,9 +52,9 @@
5252
"nyc": "^14.1.1",
5353
"source-map-support": "^0.5.12",
5454
"ts-node": "^5.0.1",
55-
"tslint": "^5.18.0",
56-
"typescript": "^3.5.3",
57-
"typescript-tslint-plugin": "^0.5.4"
55+
"tslint": "^6.1.1",
56+
"typescript": "^3.8.3",
57+
"typescript-tslint-plugin": "^0.5.5"
5858
},
5959
"scripts": {
6060
"compile": "installServerIntoExtension ./out ./package.json ./tsconfig.json && tsc -p .",

src/languageservice/services/yamlSchemaService.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { SchemaRequestService, WorkspaceContextService, PromiseConstructor, Then
1010
import { UnresolvedSchema, ResolvedSchema, JSONSchemaService,
1111
SchemaDependencies, ISchemaContributions } from 'vscode-json-languageservice/lib/umd/services/jsonSchemaService';
1212

13+
import { URI } from 'vscode-uri';
14+
1315
import * as nls from 'vscode-nls';
1416
import { convertSimple2RegExpPattern } from '../utils/strings';
1517
const localize = nls.loadMessageBundle();
@@ -71,7 +73,7 @@ export class YAMLSchemaService extends JSONSchemaService {
7173
[x: string]: any;
7274

7375
private customSchemaProvider: CustomSchemaProvider | undefined;
74-
private filePatternAssociations: FilePatternAssociation[];
76+
private filePatternAssociations: JSONSchemaService.FilePatternAssociation[];
7577
private contextService: WorkspaceContextService;
7678

7779
constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService, promiseConstructor?: PromiseConstructor) {
@@ -219,7 +221,7 @@ export class YAMLSchemaService extends JSONSchemaService {
219221
const schemas: string[] = [];
220222
for (const entry of this.filePatternAssociations) {
221223
if (entry.matchesPattern(resource)) {
222-
for (const schemaId of entry.getSchemas()) {
224+
for (const schemaId of entry.getURIs()) {
223225
if (!seen[schemaId]) {
224226
schemas.push(schemaId);
225227
seen[schemaId] = true;
@@ -368,7 +370,13 @@ export class YAMLSchemaService extends JSONSchemaService {
368370
*/
369371

370372
normalizeId(id: string) {
371-
return super.normalizeId(id);
373+
// The parent's `super.normalizeId(id)` isn't visible, so duplicated the code here
374+
try {
375+
return URI.parse(id).toString();
376+
}
377+
catch (e) {
378+
return id;
379+
}
372380
}
373381

374382
getOrAddSchemaHandle(id: string, unresolvedSchemaContent?: JSONSchema) {

test/autoCompletion.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import { TextDocument } from 'vscode-languageserver';
66
import { getLanguageService } from '../src/languageservice/yamlLanguageService';
7-
import { schemaRequestService, workspaceContext } from './utils/testHelper';
7+
import { schemaRequestService, workspaceContext, TEST_URI } from './utils/testHelper';
88
import assert = require('assert');
99

1010
const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null);
@@ -21,7 +21,7 @@ languageService.configure(languageSettings);
2121
suite('Auto Completion Tests', () => {
2222

2323
function setup(content: string) {
24-
return TextDocument.create('file://~/Desktop/vscode-k8s/test.yaml', 'yaml', 0, content);
24+
return TextDocument.create(TEST_URI, 'yaml', 0, content);
2525
}
2626

2727
function parseSetup(content: string, position) {
@@ -194,7 +194,7 @@ suite('Auto Completion Tests', () => {
194194
};
195195
languageService.configure({
196196
schemas: [{
197-
uri: 'file://test.yaml',
197+
uri: TEST_URI,
198198
fileMatch: ['*.yaml', '*.yml'],
199199
schema
200200
}],

test/documentSymbols.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ suite('Document Symbols Tests', () => {
3232
assert.equal(symbols.length, 1);
3333
assert.deepEqual(
3434
symbols[0],
35-
createExpectedSymbolInformation('cwd', 15, undefined, TEST_URI, 0, 0, 0, 9)
35+
createExpectedSymbolInformation('cwd', 15, "", TEST_URI, 0, 0, 0, 9)
3636
);
3737
});
3838

@@ -42,7 +42,7 @@ suite('Document Symbols Tests', () => {
4242
assert.equal(symbols.length, 1);
4343
assert.deepEqual(
4444
symbols[0],
45-
createExpectedSymbolInformation('node1', 16, undefined, TEST_URI, 0, 0, 0, 12)
45+
createExpectedSymbolInformation('node1', 16, "", TEST_URI, 0, 0, 0, 12)
4646
);
4747
});
4848

@@ -52,7 +52,7 @@ suite('Document Symbols Tests', () => {
5252
assert.equal(symbols.length, 1);
5353
assert.deepEqual(
5454
symbols[0],
55-
createExpectedSymbolInformation('node1', 17, undefined, TEST_URI, 0, 0, 0, 12)
55+
createExpectedSymbolInformation('node1', 17, "", TEST_URI, 0, 0, 0, 12)
5656
);
5757
});
5858

@@ -62,7 +62,7 @@ suite('Document Symbols Tests', () => {
6262
assert.equal(symbols.length, 3);
6363
assert.deepEqual(
6464
symbols[0],
65-
createExpectedSymbolInformation('scripts', 2, undefined, TEST_URI, 0, 0, 2, 13)
65+
createExpectedSymbolInformation('scripts', 2, "", TEST_URI, 0, 0, 2, 13)
6666
);
6767
assert.deepEqual(
6868
symbols[1],
@@ -80,7 +80,7 @@ suite('Document Symbols Tests', () => {
8080
assert.equal(symbols.length, 1);
8181
assert.deepEqual(
8282
symbols[0],
83-
createExpectedSymbolInformation('apiVersion', SymbolKind.Variable, undefined, TEST_URI, 0, 0, 0, 16)
83+
createExpectedSymbolInformation('apiVersion', SymbolKind.Variable, "", TEST_URI, 0, 0, 0, 16)
8484
);
8585
});
8686

@@ -90,7 +90,7 @@ suite('Document Symbols Tests', () => {
9090
assert.equal(symbols.length, 1);
9191
assert.deepEqual(
9292
symbols[0],
93-
createExpectedSymbolInformation('items', SymbolKind.Array, undefined, TEST_URI, 0, 0, 2, 8)
93+
createExpectedSymbolInformation('items', SymbolKind.Array, "", TEST_URI, 0, 0, 2, 8)
9494
);
9595
});
9696

@@ -100,7 +100,7 @@ suite('Document Symbols Tests', () => {
100100
assert.equal(symbols.length, 3);
101101
assert.deepEqual(
102102
symbols[0],
103-
createExpectedSymbolInformation('authors', 18, undefined, TEST_URI, 0, 0, 2, 13)
103+
createExpectedSymbolInformation('authors', 18, "", TEST_URI, 0, 0, 2, 13)
104104
);
105105
assert.deepEqual(
106106
symbols[1],
@@ -116,29 +116,33 @@ suite('Document Symbols Tests', () => {
116116
const content = 'scripts:\n node1: test\n node2: test\nauthors:\n - name: Josh\n - email: jp';
117117
const symbols = parseNonHierarchicalSetup(content);
118118
assert.equal(symbols.length, 6);
119+
120+
// Sort the items first so they have predictable order in the array
121+
symbols.sort((a, b) => a.name.localeCompare(b.name));
122+
119123
assert.deepEqual(
120124
symbols[0],
121-
createExpectedSymbolInformation('scripts', 2, undefined, TEST_URI, 0, 0, 2, 13)
125+
createExpectedSymbolInformation('authors', 18, "", TEST_URI, 3, 0, 5, 13)
122126
);
123127
assert.deepEqual(
124128
symbols[1],
125-
createExpectedSymbolInformation('node1', 15, 'scripts', TEST_URI, 1, 2, 1, 13)
129+
createExpectedSymbolInformation('email', 15, 'authors', TEST_URI, 5, 4, 5, 13)
126130
);
127131
assert.deepEqual(
128132
symbols[2],
129-
createExpectedSymbolInformation('node2', 15, 'scripts', TEST_URI, 2, 2, 2, 13)
133+
createExpectedSymbolInformation('name', 15, 'authors', TEST_URI, 4, 4, 4, 14)
130134
);
131135
assert.deepEqual(
132136
symbols[3],
133-
createExpectedSymbolInformation('authors', 18, undefined, TEST_URI, 3, 0, 5, 13)
137+
createExpectedSymbolInformation('node1', 15, 'scripts', TEST_URI, 1, 2, 1, 13)
134138
);
135139
assert.deepEqual(
136140
symbols[4],
137-
createExpectedSymbolInformation('name', 15, 'authors', TEST_URI, 4, 4, 4, 14)
141+
createExpectedSymbolInformation('node2', 15, 'scripts', TEST_URI, 2, 2, 2, 13)
138142
);
139143
assert.deepEqual(
140144
symbols[5],
141-
createExpectedSymbolInformation('email', 15, 'authors', TEST_URI, 5, 4, 5, 13)
145+
createExpectedSymbolInformation('scripts', 2, "", TEST_URI, 0, 0, 2, 13)
142146
);
143147
});
144148

@@ -148,11 +152,11 @@ suite('Document Symbols Tests', () => {
148152
assert.equal(symbols.length, 2);
149153
assert.deepEqual(
150154
symbols[0],
151-
createExpectedSymbolInformation('analytics', 17, undefined, TEST_URI, 1, 0, 1, 15)
155+
createExpectedSymbolInformation('analytics', 17, "", TEST_URI, 1, 0, 1, 15)
152156
);
153157
assert.deepEqual(
154158
symbols[1],
155-
createExpectedSymbolInformation('json', 15, undefined, TEST_URI, 4, 0, 4, 10)
159+
createExpectedSymbolInformation('json', 15, "", TEST_URI, 4, 0, 4, 10)
156160
);
157161
});
158162

test/schema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ suite('JSON Schema', () => {
257257

258258
service.getResolvedSchema('main').then(fs => {
259259
const section = fs.getSection(['child', 'grandchild']);
260-
assert.strictEqual(section, null);
260+
assert.strictEqual(section, undefined);
261261
}).then(() => testDone(), error => {
262262
testDone(error);
263263
});

test/schemaValidation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Red Hat. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { configureLanguageService, setupTextDocument } from './utils/testHelper';
5+
import { configureLanguageService, setupTextDocument, TEST_URI } from './utils/testHelper';
66
import { createExpectedError } from './utils/verifyError';
77
import { ServiceSetup } from './utils/serviceSetup';
88
import { StringTypeError, BooleanTypeError, ArrayTypeError, ObjectTypeError, IncludeWithoutValueError, ColonMissingError, BlockMappingEntryError } from './utils/errorMessages';
@@ -406,7 +406,7 @@ suite('Validation Tests', () => {
406406
};
407407
languageService.configure({
408408
schemas: [{
409-
uri: 'file://test.yaml',
409+
uri: TEST_URI,
410410
fileMatch: ['*.yaml', '*.yml'],
411411
schema
412412
}],
@@ -432,7 +432,7 @@ suite('Validation Tests', () => {
432432
};
433433
languageService.configure({
434434
schemas: [{
435-
uri: 'file://test.yaml',
435+
uri: TEST_URI,
436436
fileMatch: ['*.yaml', '*.yml'],
437437
schema
438438
}],
@@ -459,7 +459,7 @@ suite('Validation Tests', () => {
459459
};
460460
languageService.configure({
461461
schemas: [{
462-
uri: 'file://test.yaml',
462+
uri: TEST_URI,
463463
fileMatch: ['*.yaml', '*.yml'],
464464
schema
465465
}],

test/utils/verifyError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function createExpectedError(
3131

3232
export function createExpectedSymbolInformation(
3333
name: string,
34-
kind: number,
34+
kind: SymbolKind,
3535
containerName: string | undefined,
3636
uri: string,
3737
startLine: number,

0 commit comments

Comments
 (0)