Skip to content

Commit d107ac9

Browse files
committed
[tests] Use dynamic import for 'chai' and 'sinon-chai' modules
Signed-off-by: Victor Rubezhny <[email protected]>
1 parent b219af4 commit d107ac9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5022
-4893
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@
9393
"@segment/analytics-next": "^1.76.0",
9494
"@svgr/plugin-jsx": "^8.1.0",
9595
"@types/chai": "^5.0.1",
96-
"@typescript-eslint/eslint-plugin": "^8.18.0",
97-
"@typescript-eslint/parser": "^8.18.0",
9896
"@types/dockerode": "^3.3.32",
9997
"@types/express": "^5.0.0",
10098
"@types/fs-extra": "^11.0.4",
@@ -115,6 +113,8 @@
115113
"@types/unzip-stream": "^0.3.4",
116114
"@types/validator": "^13.12.2",
117115
"@types/vscode": "1.82.0",
116+
"@typescript-eslint/eslint-plugin": "^8.18.0",
117+
"@typescript-eslint/parser": "^8.18.0",
118118
"@uiw/codemirror-theme-github": "^4.23.6",
119119
"@uiw/codemirror-theme-vscode": "^4.23.6",
120120
"@uiw/react-codemirror": "^4.23.6",

Diff for: test/integration/alizerWrapper.test.ts

+107-104
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55
import { fail } from 'assert';
6-
import { expect } from 'chai';
76
import * as fs from 'fs/promises';
87
import { suite, suiteSetup } from 'mocha';
98
import * as path from 'path';
@@ -16,128 +15,132 @@ import { OdoPreference } from '../../src/odo/odoPreference';
1615
import { Odo } from '../../src/odo/odoWrapper';
1716
import { LoginUtil } from '../../src/util/loginUtil';
1817

19-
suite('./alizer/alizerWrapper.ts', function () {
20-
const isOpenShift: boolean = Boolean(parseInt(process.env.IS_OPENSHIFT, 10)) || false;
21-
const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443';
22-
const username = process.env.CLUSTER_USER || 'developer';
23-
const password = process.env.CLUSTER_PASSWORD || 'developer';
18+
void import('chai').then((chai) => {
19+
const expect = chai.expect;
2420

25-
suiteSetup(async function () {
26-
await OdoPreference.Instance.getRegistries(); // This creates the ODO preferences, if needed
27-
if (isOpenShift) {
21+
suite('./alizer/alizerWrapper.ts', function () {
22+
const isOpenShift: boolean = Boolean(parseInt(process.env.IS_OPENSHIFT, 10)) || false;
23+
const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443';
24+
const username = process.env.CLUSTER_USER || 'developer';
25+
const password = process.env.CLUSTER_PASSWORD || 'developer';
26+
27+
suiteSetup(async function () {
28+
await OdoPreference.Instance.getRegistries(); // This creates the ODO preferences, if needed
29+
if (isOpenShift) {
30+
try {
31+
await LoginUtil.Instance.logout();
32+
} catch {
33+
// do nothing
34+
}
35+
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
36+
}
37+
});
38+
39+
suiteTeardown(async function () {
40+
// ensure projects are cleaned up
2841
try {
29-
await LoginUtil.Instance.logout();
42+
await Oc.Instance.deleteProject('my-test-project-1');
43+
} catch {
44+
// do nothing
45+
}
46+
try {
47+
await Oc.Instance.deleteProject('my-test-project-2');
3048
} catch {
3149
// do nothing
3250
}
33-
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
34-
}
35-
});
36-
37-
suiteTeardown(async function () {
38-
// ensure projects are cleaned up
39-
try {
40-
await Oc.Instance.deleteProject('my-test-project-1');
41-
} catch {
42-
// do nothing
43-
}
44-
try {
45-
await Oc.Instance.deleteProject('my-test-project-2');
46-
} catch {
47-
// do nothing
48-
}
49-
50-
if (isOpenShift) {
51-
await LoginUtil.Instance.logout();
52-
}
53-
});
5451

55-
suite('analyse folder', function () {
56-
const project1 = 'my-test-project-1';
52+
if (isOpenShift) {
53+
await LoginUtil.Instance.logout();
54+
}
55+
});
5756

58-
let tmpFolder1: Uri;
59-
let tmpFolder2: Uri;
57+
suite('analyse folder', function () {
58+
const project1 = 'my-test-project-1';
59+
60+
let tmpFolder1: Uri;
61+
let tmpFolder2: Uri;
62+
63+
suiteSetup(async function () {
64+
await Oc.Instance.createProject(project1);
65+
tmpFolder1 = Uri.parse(await promisify(tmp.dir)());
66+
tmpFolder2 = Uri.parse(await promisify(tmp.dir)());
67+
await Odo.Instance.createComponentFromFolder(
68+
'nodejs',
69+
'latest',
70+
undefined,
71+
'component1',
72+
tmpFolder1,
73+
'nodejs-starter',
74+
);
75+
await Odo.Instance.createComponentFromFolder(
76+
'go',
77+
'latest',
78+
undefined,
79+
'component2',
80+
tmpFolder2,
81+
'go-starter',
82+
);
83+
});
6084

61-
suiteSetup(async function () {
62-
await Oc.Instance.createProject(project1);
63-
tmpFolder1 = Uri.parse(await promisify(tmp.dir)());
64-
tmpFolder2 = Uri.parse(await promisify(tmp.dir)());
65-
await Odo.Instance.createComponentFromFolder(
66-
'nodejs',
67-
'latest',
68-
undefined,
69-
'component1',
70-
tmpFolder1,
71-
'nodejs-starter',
72-
);
73-
await Odo.Instance.createComponentFromFolder(
74-
'go',
75-
'latest',
76-
undefined,
77-
'component2',
78-
tmpFolder2,
79-
'go-starter',
80-
);
81-
});
85+
suiteTeardown(async function () {
86+
if (isOpenShift) {
87+
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
88+
}
89+
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => {
90+
const fsPath = workspaceFolder.uri.fsPath;
91+
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath);
92+
});
93+
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders);
94+
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true });
95+
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true });
96+
await Oc.Instance.deleteProject(project1);
97+
});
8298

83-
suiteTeardown(async function () {
84-
if (isOpenShift) {
85-
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
86-
}
87-
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => {
88-
const fsPath = workspaceFolder.uri.fsPath;
89-
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath);
99+
test('analyze()', async function () {
100+
const analysis1 = await Alizer.Instance.alizerDevfile(tmpFolder1);
101+
expect(analysis1.Name).to.exist;
102+
expect(analysis1.Name).to.equal('nodejs');
103+
const analysis2 = await Alizer.Instance.alizerDevfile(tmpFolder2);
104+
expect(analysis2.Name).to.exist;
105+
expect(analysis2.Name).to.equal('go');
90106
});
91-
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders);
92-
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true });
93-
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true });
94-
await Oc.Instance.deleteProject(project1);
95107
});
96108

97-
test('analyze()', async function () {
98-
const analysis1 = await Alizer.Instance.alizerDevfile(tmpFolder1);
99-
expect(analysis1.Name).to.exist;
100-
expect(analysis1.Name).to.equal('nodejs');
101-
const analysis2 = await Alizer.Instance.alizerDevfile(tmpFolder2);
102-
expect(analysis2.Name).to.exist;
103-
expect(analysis2.Name).to.equal('go');
104-
});
105-
});
109+
suite('create component', function() {
106110

107-
suite('create component', function() {
111+
const COMPONENT_TYPE = 'dotnet50';
112+
const COMPONENT_VERSION = 'latest';
108113

109-
const COMPONENT_TYPE = 'dotnet50';
110-
const COMPONENT_VERSION = 'latest';
114+
let tmpFolder: string;
111115

112-
let tmpFolder: string;
116+
suiteSetup(async function() {
117+
tmpFolder = await promisify(tmp.dir)();
118+
});
113119

114-
suiteSetup(async function() {
115-
tmpFolder = await promisify(tmp.dir)();
116-
});
120+
suiteTeardown(async function() {
121+
await fs.rm(tmpFolder, { recursive: true, force: true });
122+
});
117123

118-
suiteTeardown(async function() {
119-
await fs.rm(tmpFolder, { recursive: true, force: true });
120-
});
124+
test('createComponentFromTemplateProject()', async function() {
125+
await Odo.Instance.createComponentFromTemplateProject(
126+
tmpFolder, 'my-component', 8080,
127+
COMPONENT_TYPE, COMPONENT_VERSION,
128+
OdoPreference.DEFAULT_DEVFILE_REGISTRY_NAME, 'dotnet50-example');
129+
try {
130+
await fs.access(path.join(tmpFolder, 'devfile.yaml'));
131+
} catch {
132+
fail('Expected devfile to be created');
133+
}
134+
});
121135

122-
test('createComponentFromTemplateProject()', async function() {
123-
await Odo.Instance.createComponentFromTemplateProject(
124-
tmpFolder, 'my-component', 8080,
125-
COMPONENT_TYPE, COMPONENT_VERSION,
126-
OdoPreference.DEFAULT_DEVFILE_REGISTRY_NAME, 'dotnet50-example');
127-
try {
128-
await fs.access(path.join(tmpFolder, 'devfile.yaml'));
129-
} catch {
130-
fail('Expected devfile to be created');
131-
}
132-
});
136+
test('analyze()', async function() {
137+
const analysis = await Alizer.Instance.alizerDevfile(Uri.file(tmpFolder));
138+
expect(analysis).to.exist;
139+
expect(analysis.Name).to.equal(COMPONENT_TYPE);
140+
});
133141

134-
test('analyze()', async function() {
135-
const analysis = await Alizer.Instance.alizerDevfile(Uri.file(tmpFolder));
136-
expect(analysis).to.exist;
137-
expect(analysis.Name).to.equal(COMPONENT_TYPE);
138142
});
139143

144+
test('deleteComponentConfiguration');
140145
});
141-
142-
test('deleteComponentConfiguration');
143-
});
146+
});

0 commit comments

Comments
 (0)