This repository was archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathworkspace-config-files-watcher.spec.ts
More file actions
106 lines (84 loc) · 3.56 KB
/
workspace-config-files-watcher.spec.ts
File metadata and controls
106 lines (84 loc) · 3.56 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/
import 'reflect-metadata';
import { AbstractFileWatcher, DevfileWatcher } from '../../src/browser/workspace-config-files-watcher';
import { ChePluginManager } from '@eclipse-che/theia-plugin-ext/lib/browser/plugin/che-plugin-manager';
import { Container } from '@theia/core/shared/inversify';
import { DevfileService } from '@eclipse-che/theia-remote-api/lib/common/devfile-service';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { FileStat } from '@theia/filesystem/lib/common/files';
import { FrontendApplication } from '@theia/core/lib/browser';
import { MessageService } from '@theia/core';
import URI from '@theia/core/lib/common/uri';
import { WorkspaceService } from '@theia/workspace/lib/browser';
describe('Test workspace config files watchers', function () {
let container: Container;
let fileService: FileService;
let workspaceService: WorkspaceService;
const fileServiceWatchMethod = jest.fn();
const workspaceServiceOnWorkspaceChangedMethod = jest.fn();
beforeEach(() => {
jest.restoreAllMocks();
jest.resetAllMocks();
container = new Container();
fileService = ({
watch: fileServiceWatchMethod,
} as unknown) as FileService;
workspaceService = ({
onWorkspaceChanged: workspaceServiceOnWorkspaceChangedMethod,
} as unknown) as WorkspaceService;
container.bind(FileService).toConstantValue(fileService);
container.bind(WorkspaceService).toConstantValue(workspaceService);
});
describe('Test DevfileWatcher', function () {
let devfileWatcher: AbstractFileWatcher;
const devfileServiceUpdateDevfileMethod = jest.fn();
const chePluginManagerRestartWorkspaceMethod = jest.fn();
const messageServiceInfoMethod = jest.fn();
beforeEach(() => {
const devfileService = ({
updateDevfile: devfileServiceUpdateDevfileMethod,
} as unknown) as DevfileService;
const chePluginManager = ({
restartWorkspace: chePluginManagerRestartWorkspaceMethod,
} as unknown) as ChePluginManager;
const messageService = ({
info: messageServiceInfoMethod,
} as unknown) as MessageService;
container.bind(DevfileService).toConstantValue(devfileService);
container.bind(ChePluginManager).toConstantValue(chePluginManager);
container.bind(MessageService).toConstantValue(messageService);
container.bind(DevfileWatcher).toSelf().inSingletonScope();
devfileWatcher = container.get(DevfileWatcher);
});
test('shouldWatch', async () => {
const resolveFn = jest.fn();
const resource = ({
resolve: resolveFn,
} as unknown) as URI;
resolveFn.mockReturnValue(resource);
const roots: FileStat[] = [
{
name: 'testFile',
isDirectory: false,
isFile: true,
isSymbolicLink: false,
resource: resource,
},
];
Object.defineProperty(workspaceService, 'roots', {
get: jest.fn(() => roots),
});
await devfileWatcher.onStart({} as FrontendApplication);
expect(fileServiceWatchMethod.mock.calls.length).toEqual(1);
expect(fileServiceWatchMethod).toHaveBeenCalledWith(resource);
});
});
});