test(language-service): Remove non-deterministic test (#33120)
A few specs in `completions_spec.ts` are non-deterministic and do not provide much value to test a specific behavior of language service. Besides that, they are also slow to run. PR Close #33120
This commit is contained in:
parent
84ba1f012e
commit
4acf0a09ac
|
@ -41,12 +41,6 @@ describe('completions', () => {
|
|||
it('should be able to find common angular attributes',
|
||||
() => { expectContains('/app/test.ng', 'div-attributes', '(click)', '[ngClass]'); });
|
||||
|
||||
it('should be able to get completions in some random garbage', () => {
|
||||
const fileName = '/app/test.ng';
|
||||
mockHost.override(fileName, ' > {{tle<\n {{retl ><bel/beled}}di>\n la</b </d &a ');
|
||||
expect(() => ngService.getCompletionsAt(fileName, 31)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should be able to infer the type of a ngForOf', () => {
|
||||
const fileName = mockHost.addCode(`
|
||||
interface Person {
|
||||
|
@ -75,58 +69,6 @@ describe('completions', () => {
|
|||
expectContains(fileName, 'name', 'name', 'street');
|
||||
});
|
||||
|
||||
it('should be able to complete every character in the file', () => {
|
||||
const fileName = '/app/test.ng';
|
||||
|
||||
expect(() => {
|
||||
let chance = 0.05;
|
||||
function tryCompletionsAt(position: number) {
|
||||
try {
|
||||
if (Math.random() < chance) {
|
||||
ngService.getCompletionsAt(fileName, position);
|
||||
}
|
||||
} catch (e) {
|
||||
// Emit enough diagnostic information to reproduce the error.
|
||||
console.error(
|
||||
`Position: ${position}\nContent: "${mockHost.readFile(fileName)}"\nStack:\n${e.stack}`);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const originalContent = mockHost.readFile(fileName) !;
|
||||
|
||||
// For each character in the file, add it to the file and request a completion after it.
|
||||
for (let index = 0, len = originalContent.length; index < len; index++) {
|
||||
const content = originalContent.substr(0, index);
|
||||
mockHost.override(fileName, content);
|
||||
tryCompletionsAt(index);
|
||||
}
|
||||
|
||||
// For the complete file, try to get a completion at every character.
|
||||
mockHost.override(fileName, originalContent);
|
||||
for (let index = 0, len = originalContent.length; index < len; index++) {
|
||||
tryCompletionsAt(index);
|
||||
}
|
||||
|
||||
// Delete random characters in the file until we get an empty file.
|
||||
let content = originalContent;
|
||||
while (content.length > 0) {
|
||||
const deleteIndex = Math.floor(Math.random() * content.length);
|
||||
content = content.slice(0, deleteIndex - 1) + content.slice(deleteIndex + 1);
|
||||
mockHost.override(fileName, content);
|
||||
|
||||
const requestIndex = Math.floor(Math.random() * content.length);
|
||||
tryCompletionsAt(requestIndex);
|
||||
}
|
||||
|
||||
// Build up the string from zero asking for a completion after every char
|
||||
buildUp(originalContent, (text, position) => {
|
||||
mockHost.override(fileName, text);
|
||||
tryCompletionsAt(position);
|
||||
});
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
describe('with regression tests', () => {
|
||||
it('should not crash with an incomplete component', () => {
|
||||
expect(() => {
|
||||
|
@ -222,35 +164,3 @@ function expectEntries(
|
|||
`Expected result from ${locationMarker} to include at least one of the following, ${missing.join(', ')}, in the list of entries ${completion.entries.map(entry => entry.name).join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
function buildUp(originalText: string, cb: (text: string, position: number) => void) {
|
||||
let count = originalText.length;
|
||||
|
||||
let inString: boolean[] = (new Array(count)).fill(false);
|
||||
let unused: number[] = (new Array(count)).fill(1).map((v, i) => i);
|
||||
|
||||
function getText() {
|
||||
return new Array(count)
|
||||
.fill(1)
|
||||
.map((v, i) => i)
|
||||
.filter(i => inString[i])
|
||||
.map(i => originalText[i])
|
||||
.join('');
|
||||
}
|
||||
|
||||
function randomUnusedIndex() { return Math.floor(Math.random() * unused.length); }
|
||||
|
||||
while (unused.length > 0) {
|
||||
let unusedIndex = randomUnusedIndex();
|
||||
let index = unused[unusedIndex];
|
||||
if (index == null) throw new Error('Internal test buildup error');
|
||||
if (inString[index]) throw new Error('Internal test buildup error');
|
||||
inString[index] = true;
|
||||
unused.splice(unusedIndex, 1);
|
||||
let text = getText();
|
||||
let position = inString.filter((_, i) => i <= index)
|
||||
.map(v => v ? 1 : 0)
|
||||
.reduce((p: number, v) => p + v, 0);
|
||||
cb(text, position);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue