-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath-with-spaces.test.ts
68 lines (57 loc) · 2.63 KB
/
path-with-spaces.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as assert from 'assert';
import { suiteSetup, test } from 'mocha';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import { Uri } from 'vscode';
import { activateIfNotActive } from './util/activate-if-not-active';
suite('Path with spaces tests', () => {
const folder = vscode.workspace.workspaceFolders![0];
suiteSetup(async function () {
// 10 minutes - for downloading and installing the scuri npm package
this.timeout(10 * 60 * 1000);
await activateIfNotActive();
return await vscode.commands.executeCommand("scuri:install-deps");
});
test('should create spec when missing', async () => {
const fileName = folder.uri.path + "/example.ts";
// open a file
const example = await vscode.workspace.openTextDocument(fileName);
// and have it be the active editor
await vscode.window.showTextDocument(example);
await vscode.commands.executeCommand("scuri:generate");
const createdFile = await waitTillFileExists('example.spec.ts');
const spec = await vscode.workspace.openTextDocument(createdFile);
assert.notEqual(null, spec);
const text = spec.getText();
assert.equal(true, text.includes("function setup()"));
});
test('should create for file with spaces', async function() {
// arrange
const fileName = folder.uri.path + "/spaced folder/my spaced component.ts";
// open a file
const example = await vscode.workspace.openTextDocument(fileName);
// and have it be the active editor
await vscode.window.showTextDocument(example);
// act
await vscode.commands.executeCommand("scuri:generate");
const created = await waitTillFileExists('**/my spaced component.spec.ts');
// assert
const spec = await vscode.workspace.openTextDocument(created);
assert.notEqual(null, spec);
const text = spec.getText();
assert.equal(true, text.includes("function setup()"));
});
});
function waitTillFileExists(fileName: string, step: number = 100, timeout: number = 9900): Promise<Uri> {
return new Promise<Uri[]>(res => setTimeout(() => {
res(vscode.workspace.findFiles(fileName));
}, step))
.then((files: Uri[]) => {
return step >= timeout
? Promise.reject(`Timed out looking for ${fileName}`)
: files.length > 0
? files[0]
: waitTillFileExists(fileName, step, timeout - step);
});
}