Skip to content

Commit 04d7411

Browse files
committed
eng: update mocha 2 -> 8
1 parent 65e1707 commit 04d7411

File tree

11 files changed

+344
-233
lines changed

11 files changed

+344
-233
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@
155155
"mime": "^1.4.1",
156156
"minimatch": "^3.0.4",
157157
"mkdirp": "^0.5.0",
158-
"mocha": "^2.2.5",
159-
"mocha-junit-reporter": "^1.17.0",
158+
"mocha": "^8.2.1",
159+
"mocha-junit-reporter": "^2.0.0",
160160
"npm-run-all": "^4.1.5",
161161
"opn": "^6.0.0",
162162
"optimist": "0.3.5",

src/vs/platform/files/test/electron-browser/diskFileService.test.ts

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,73 +2008,72 @@ suite('Disk File Service', function () {
20082008

20092009
const runWatchTests = isLinux;
20102010

2011-
(runWatchTests ? test : test.skip)('watch - file', done => {
2011+
(runWatchTests ? test : test.skip)('watch - file', async () => {
20122012
const toWatch = URI.file(join(testDir, 'index-watch1.html'));
20132013
writeFileSync(toWatch.fsPath, 'Init');
20142014

2015-
assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]], done);
2016-
2015+
const promise = assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]]);
20172016
setTimeout(() => writeFileSync(toWatch.fsPath, 'Changes'), 50);
2017+
await promise;
20182018
});
20192019

2020-
(runWatchTests && !isWindows /* symbolic links not reliable on windows */ ? test : test.skip)('watch - file symbolic link', async done => {
2020+
(runWatchTests && !isWindows /* symbolic links not reliable on windows */ ? test : test.skip)('watch - file symbolic link', async () => {
20212021
const toWatch = URI.file(join(testDir, 'lorem.txt-linked'));
20222022
await symlink(join(testDir, 'lorem.txt'), toWatch.fsPath);
20232023

2024-
assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]], done);
2025-
2024+
const promise = assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]]);
20262025
setTimeout(() => writeFileSync(toWatch.fsPath, 'Changes'), 50);
2026+
await promise;
20272027
});
20282028

2029-
(runWatchTests ? test : test.skip)('watch - file - multiple writes', done => {
2029+
(runWatchTests ? test : test.skip)('watch - file - multiple writes', async () => {
20302030
const toWatch = URI.file(join(testDir, 'index-watch1.html'));
20312031
writeFileSync(toWatch.fsPath, 'Init');
20322032

2033-
assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]], done);
2034-
2033+
const promise = assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]]);
20352034
setTimeout(() => writeFileSync(toWatch.fsPath, 'Changes 1'), 0);
20362035
setTimeout(() => writeFileSync(toWatch.fsPath, 'Changes 2'), 10);
20372036
setTimeout(() => writeFileSync(toWatch.fsPath, 'Changes 3'), 20);
2037+
await promise;
20382038
});
20392039

2040-
(runWatchTests ? test : test.skip)('watch - file - delete file', done => {
2040+
(runWatchTests ? test : test.skip)('watch - file - delete file', async () => {
20412041
const toWatch = URI.file(join(testDir, 'index-watch1.html'));
20422042
writeFileSync(toWatch.fsPath, 'Init');
20432043

2044-
assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]], done);
2045-
2044+
const promise = assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]]);
20462045
setTimeout(() => unlinkSync(toWatch.fsPath), 50);
2046+
await promise;
20472047
});
20482048

2049-
(runWatchTests ? test : test.skip)('watch - file - rename file', done => {
2049+
(runWatchTests ? test : test.skip)('watch - file - rename file', async () => {
20502050
const toWatch = URI.file(join(testDir, 'index-watch1.html'));
20512051
const toWatchRenamed = URI.file(join(testDir, 'index-watch1-renamed.html'));
20522052
writeFileSync(toWatch.fsPath, 'Init');
20532053

2054-
assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]], done);
2055-
2054+
const promise = assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]]);
20562055
setTimeout(() => renameSync(toWatch.fsPath, toWatchRenamed.fsPath), 50);
2056+
await promise;
20572057
});
20582058

2059-
(runWatchTests ? test : test.skip)('watch - file - rename file (different case)', done => {
2059+
(runWatchTests ? test : test.skip)('watch - file - rename file (different case)', async () => {
20602060
const toWatch = URI.file(join(testDir, 'index-watch1.html'));
20612061
const toWatchRenamed = URI.file(join(testDir, 'INDEX-watch1.html'));
20622062
writeFileSync(toWatch.fsPath, 'Init');
20632063

2064-
if (isLinux) {
2065-
assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]], done);
2066-
} else {
2067-
assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]], done); // case insensitive file system treat this as change
2068-
}
2064+
const promise = isLinux
2065+
? assertWatch(toWatch, [[FileChangeType.DELETED, toWatch]])
2066+
: assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]]); // case insensitive file system treat this as change
20692067

20702068
setTimeout(() => renameSync(toWatch.fsPath, toWatchRenamed.fsPath), 50);
2069+
await promise;
20712070
});
20722071

2073-
(runWatchTests ? test : test.skip)('watch - file (atomic save)', function (done) {
2072+
(runWatchTests ? test : test.skip)('watch - file (atomic save)', async () => {
20742073
const toWatch = URI.file(join(testDir, 'index-watch2.html'));
20752074
writeFileSync(toWatch.fsPath, 'Init');
20762075

2077-
assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]], done);
2076+
const promise = assertWatch(toWatch, [[FileChangeType.UPDATED, toWatch]]);
20782077

20792078
setTimeout(() => {
20802079
// Simulate atomic save by deleting the file, creating it under different name
@@ -2084,79 +2083,81 @@ suite('Disk File Service', function () {
20842083
writeFileSync(renamed, 'Changes');
20852084
renameSync(renamed, toWatch.fsPath);
20862085
}, 50);
2086+
2087+
await promise;
20872088
});
20882089

2089-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - change file', done => {
2090+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - change file', async () => {
20902091
const watchDir = URI.file(join(testDir, 'watch3'));
20912092
mkdirSync(watchDir.fsPath);
20922093

20932094
const file = URI.file(join(watchDir.fsPath, 'index.html'));
20942095
writeFileSync(file.fsPath, 'Init');
20952096

2096-
assertWatch(watchDir, [[FileChangeType.UPDATED, file]], done);
2097-
2097+
const promise = assertWatch(watchDir, [[FileChangeType.UPDATED, file]]);
20982098
setTimeout(() => writeFileSync(file.fsPath, 'Changes'), 50);
2099+
await promise;
20992100
});
21002101

2101-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - add file', done => {
2102+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - add file', async () => {
21022103
const watchDir = URI.file(join(testDir, 'watch4'));
21032104
mkdirSync(watchDir.fsPath);
21042105

21052106
const file = URI.file(join(watchDir.fsPath, 'index.html'));
21062107

2107-
assertWatch(watchDir, [[FileChangeType.ADDED, file]], done);
2108-
2108+
const promise = assertWatch(watchDir, [[FileChangeType.ADDED, file]]);
21092109
setTimeout(() => writeFileSync(file.fsPath, 'Changes'), 50);
2110+
await promise;
21102111
});
21112112

2112-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - delete file', done => {
2113+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - delete file', async () => {
21132114
const watchDir = URI.file(join(testDir, 'watch5'));
21142115
mkdirSync(watchDir.fsPath);
21152116

21162117
const file = URI.file(join(watchDir.fsPath, 'index.html'));
21172118
writeFileSync(file.fsPath, 'Init');
21182119

2119-
assertWatch(watchDir, [[FileChangeType.DELETED, file]], done);
2120-
2120+
const promise = assertWatch(watchDir, [[FileChangeType.DELETED, file]]);
21212121
setTimeout(() => unlinkSync(file.fsPath), 50);
2122+
await promise;
21222123
});
21232124

2124-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - add folder', done => {
2125+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - add folder', async () => {
21252126
const watchDir = URI.file(join(testDir, 'watch6'));
21262127
mkdirSync(watchDir.fsPath);
21272128

21282129
const folder = URI.file(join(watchDir.fsPath, 'folder'));
21292130

2130-
assertWatch(watchDir, [[FileChangeType.ADDED, folder]], done);
2131-
2131+
const promise = assertWatch(watchDir, [[FileChangeType.ADDED, folder]]);
21322132
setTimeout(() => mkdirSync(folder.fsPath), 50);
2133+
await promise;
21332134
});
21342135

2135-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - delete folder', done => {
2136+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - delete folder', async () => {
21362137
const watchDir = URI.file(join(testDir, 'watch7'));
21372138
mkdirSync(watchDir.fsPath);
21382139

21392140
const folder = URI.file(join(watchDir.fsPath, 'folder'));
21402141
mkdirSync(folder.fsPath);
21412142

2142-
assertWatch(watchDir, [[FileChangeType.DELETED, folder]], done);
2143-
2143+
const promise = assertWatch(watchDir, [[FileChangeType.DELETED, folder]]);
21442144
setTimeout(() => rimrafSync(folder.fsPath), 50);
2145+
await promise;
21452146
});
21462147

2147-
(runWatchTests && !isWindows /* symbolic links not reliable on windows */ ? test : test.skip)('watch - folder (non recursive) - symbolic link - change file', async done => {
2148+
(runWatchTests && !isWindows /* symbolic links not reliable on windows */ ? test : test.skip)('watch - folder (non recursive) - symbolic link - change file', async () => {
21482149
const watchDir = URI.file(join(testDir, 'deep-link'));
21492150
await symlink(join(testDir, 'deep'), watchDir.fsPath);
21502151

21512152
const file = URI.file(join(watchDir.fsPath, 'index.html'));
21522153
writeFileSync(file.fsPath, 'Init');
21532154

2154-
assertWatch(watchDir, [[FileChangeType.UPDATED, file]], done);
2155-
2155+
const promise = assertWatch(watchDir, [[FileChangeType.UPDATED, file]]);
21562156
setTimeout(() => writeFileSync(file.fsPath, 'Changes'), 50);
2157+
await promise;
21572158
});
21582159

2159-
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - rename file', done => {
2160+
(runWatchTests ? test : test.skip)('watch - folder (non recursive) - rename file', async () => {
21602161
const watchDir = URI.file(join(testDir, 'watch8'));
21612162
mkdirSync(watchDir.fsPath);
21622163

@@ -2165,12 +2166,12 @@ suite('Disk File Service', function () {
21652166

21662167
const fileRenamed = URI.file(join(watchDir.fsPath, 'index-renamed.html'));
21672168

2168-
assertWatch(watchDir, [[FileChangeType.DELETED, file], [FileChangeType.ADDED, fileRenamed]], done);
2169-
2169+
const promise = assertWatch(watchDir, [[FileChangeType.DELETED, file], [FileChangeType.ADDED, fileRenamed]]);
21702170
setTimeout(() => renameSync(file.fsPath, fileRenamed.fsPath), 50);
2171+
await promise;
21712172
});
21722173

2173-
(runWatchTests && isLinux /* this test requires a case sensitive file system */ ? test : test.skip)('watch - folder (non recursive) - rename file (different case)', done => {
2174+
(runWatchTests && isLinux /* this test requires a case sensitive file system */ ? test : test.skip)('watch - folder (non recursive) - rename file (different case)', async () => {
21742175
const watchDir = URI.file(join(testDir, 'watch8'));
21752176
mkdirSync(watchDir.fsPath);
21762177

@@ -2179,46 +2180,48 @@ suite('Disk File Service', function () {
21792180

21802181
const fileRenamed = URI.file(join(watchDir.fsPath, 'INDEX.html'));
21812182

2182-
assertWatch(watchDir, [[FileChangeType.DELETED, file], [FileChangeType.ADDED, fileRenamed]], done);
2183-
2183+
const promise = assertWatch(watchDir, [[FileChangeType.DELETED, file], [FileChangeType.ADDED, fileRenamed]]);
21842184
setTimeout(() => renameSync(file.fsPath, fileRenamed.fsPath), 50);
2185+
await promise;
21852186
});
21862187

2187-
function assertWatch(toWatch: URI, expected: [FileChangeType, URI][], done: MochaDone): void {
2188-
const watcherDisposable = service.watch(toWatch);
2188+
function assertWatch(toWatch: URI, expected: [FileChangeType, URI][]): Promise<void> {
2189+
return new Promise<void>((resolve, reject) => {
2190+
const watcherDisposable = service.watch(toWatch);
21892191

2190-
function toString(type: FileChangeType): string {
2191-
switch (type) {
2192-
case FileChangeType.ADDED: return 'added';
2193-
case FileChangeType.DELETED: return 'deleted';
2194-
case FileChangeType.UPDATED: return 'updated';
2192+
function toString(type: FileChangeType): string {
2193+
switch (type) {
2194+
case FileChangeType.ADDED: return 'added';
2195+
case FileChangeType.DELETED: return 'deleted';
2196+
case FileChangeType.UPDATED: return 'updated';
2197+
}
21952198
}
2196-
}
21972199

2198-
function printEvents(event: FileChangesEvent): string {
2199-
return event.changes.map(change => `Change: type ${toString(change.type)} path ${change.resource.toString()}`).join('\n');
2200-
}
2200+
function printEvents(event: FileChangesEvent): string {
2201+
return event.changes.map(change => `Change: type ${toString(change.type)} path ${change.resource.toString()}`).join('\n');
2202+
}
22012203

2202-
const listenerDisposable = service.onDidFilesChange(event => {
2203-
watcherDisposable.dispose();
2204-
listenerDisposable.dispose();
2204+
const listenerDisposable = service.onDidFilesChange(event => {
2205+
watcherDisposable.dispose();
2206+
listenerDisposable.dispose();
22052207

2206-
try {
2207-
assert.equal(event.changes.length, expected.length, `Expected ${expected.length} events, but got ${event.changes.length}. Details (${printEvents(event)})`);
2208+
try {
2209+
assert.equal(event.changes.length, expected.length, `Expected ${expected.length} events, but got ${event.changes.length}. Details (${printEvents(event)})`);
22082210

2209-
if (expected.length === 1) {
2210-
assert.equal(event.changes[0].type, expected[0][0], `Expected ${toString(expected[0][0])} but got ${toString(event.changes[0].type)}. Details (${printEvents(event)})`);
2211-
assert.equal(event.changes[0].resource.fsPath, expected[0][1].fsPath);
2212-
} else {
2213-
for (const expect of expected) {
2214-
assert.equal(hasChange(event.changes, expect[0], expect[1]), true, `Unable to find ${toString(expect[0])} for ${expect[1].fsPath}. Details (${printEvents(event)})`);
2211+
if (expected.length === 1) {
2212+
assert.equal(event.changes[0].type, expected[0][0], `Expected ${toString(expected[0][0])} but got ${toString(event.changes[0].type)}. Details (${printEvents(event)})`);
2213+
assert.equal(event.changes[0].resource.fsPath, expected[0][1].fsPath);
2214+
} else {
2215+
for (const expect of expected) {
2216+
assert.equal(hasChange(event.changes, expect[0], expect[1]), true, `Unable to find ${toString(expect[0])} for ${expect[1].fsPath}. Details (${printEvents(event)})`);
2217+
}
22152218
}
2216-
}
22172219

2218-
done();
2219-
} catch (error) {
2220-
done(error);
2221-
}
2220+
resolve();
2221+
} catch (error) {
2222+
reject(error);
2223+
}
2224+
});
22222225
});
22232226
}
22242227

src/vs/workbench/services/configuration/test/electron-browser/configurationService.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,24 @@ suite('WorkspaceContextService - Workspace Editing', () => {
363363
});
364364
});
365365

366-
test('remove folders and add them back by writing into the file', async done => {
366+
test('remove folders and add them back by writing into the file', async () => {
367367
const folders = testObject.getWorkspace().folders;
368368
await testObject.removeFolders([folders[0].uri]);
369369

370-
testObject.onDidChangeWorkspaceFolders(actual => {
371-
try {
372-
assert.deepEqual(actual.added.map(r => r.uri.toString()), [folders[0].uri.toString()]);
373-
done();
374-
} catch (error) {
375-
done(error);
376-
}
370+
const promise = new Promise<void>((resolve, reject) => {
371+
testObject.onDidChangeWorkspaceFolders(actual => {
372+
try {
373+
assert.deepEqual(actual.added.map(r => r.uri.toString()), [folders[0].uri.toString()]);
374+
resolve();
375+
} catch (error) {
376+
reject(error);
377+
}
378+
});
377379
});
378380

379381
const workspace = { folders: [{ path: folders[0].uri.fsPath }, { path: folders[1].uri.fsPath }] };
380382
await instantiationService.get(ITextFileService).write(testObject.getWorkspace().configuration!, JSON.stringify(workspace, null, '\t'));
383+
await promise;
381384
});
382385

383386
test('update folders (remove last and add to end)', () => {

test/.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://json.schemastore.org/mocharc",
3+
"ui": "tdd",
4+
"timeout": 10000
5+
}

test/automation/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vscode-automation",
3-
"version": "1.39.0",
3+
"version": "1.53.0",
44
"description": "VS Code UI automation driver",
55
"author": {
66
"name": "Microsoft Corporation"
@@ -36,4 +36,4 @@
3636
"vscode-uri": "^2.0.3",
3737
"watch": "^1.0.2"
3838
}
39-
}
39+
}

test/mocha.opts

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

test/unit/browser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ class EchoRunner extends events.EventEmitter {
205205
suites: suite.suites,
206206
tests: suite.tests,
207207
title: titleExtra && suite.title ? `${suite.title} - /${titleExtra}/` : suite.title,
208+
titlePath: () => suite.titlePath,
208209
fullTitle: () => suite.fullTitle,
209210
timeout: () => suite.timeout,
210211
retries: () => suite.retries,
211-
enableTimeouts: () => suite.enableTimeouts,
212212
slow: () => suite.slow,
213213
bail: () => suite.bail
214214
};

test/unit/browser/renderer.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@
6969
tests: suite.tests.map(serializeRunnable),
7070
title: suite.title,
7171
fullTitle: suite.fullTitle(),
72+
titlePath: suite.titlePath(),
7273
timeout: suite.timeout(),
7374
retries: suite.retries(),
74-
enableTimeouts: suite.enableTimeouts(),
7575
slow: suite.slow(),
7676
bail: suite.bail()
7777
};
7878
}
7979
function serializeRunnable(runnable) {
8080
return {
8181
title: runnable.title,
82+
titlePath: runnable.titlePath(),
8283
fullTitle: runnable.fullTitle(),
8384
async: runnable.async,
8485
slow: runnable.slow(),

0 commit comments

Comments
 (0)