Skip to content

Commit

Permalink
[tests] Use dynamic import for 'chai' and 'sinon-chai' modules
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Dec 13, 2024
1 parent b219af4 commit b4a8f47
Show file tree
Hide file tree
Showing 44 changed files with 2,507 additions and 2,420 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@
"@segment/analytics-next": "^1.76.0",
"@svgr/plugin-jsx": "^8.1.0",
"@types/chai": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@types/dockerode": "^3.3.32",
"@types/express": "^5.0.0",
"@types/fs-extra": "^11.0.4",
Expand All @@ -115,6 +113,8 @@
"@types/unzip-stream": "^0.3.4",
"@types/validator": "^13.12.2",
"@types/vscode": "1.82.0",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"@uiw/codemirror-theme-github": "^4.23.6",
"@uiw/codemirror-theme-vscode": "^4.23.6",
"@uiw/react-codemirror": "^4.23.6",
Expand Down
211 changes: 107 additions & 104 deletions test/integration/alizerWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { fail } from 'assert';
import { expect } from 'chai';
import * as fs from 'fs/promises';
import { suite, suiteSetup } from 'mocha';
import * as path from 'path';
Expand All @@ -16,128 +15,132 @@ import { OdoPreference } from '../../src/odo/odoPreference';
import { Odo } from '../../src/odo/odoWrapper';
import { LoginUtil } from '../../src/util/loginUtil';

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

suiteSetup(async function () {
await OdoPreference.Instance.getRegistries(); // This creates the ODO preferences, if needed
if (isOpenShift) {
suite('./alizer/alizerWrapper.ts', function () {
const isOpenShift: boolean = Boolean(parseInt(process.env.IS_OPENSHIFT, 10)) || false;
const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443';
const username = process.env.CLUSTER_USER || 'developer';
const password = process.env.CLUSTER_PASSWORD || 'developer';

suiteSetup(async function () {
await OdoPreference.Instance.getRegistries(); // This creates the ODO preferences, if needed
if (isOpenShift) {
try {
await LoginUtil.Instance.logout();
} catch {
// do nothing
}
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
}
});

suiteTeardown(async function () {
// ensure projects are cleaned up
try {
await LoginUtil.Instance.logout();
await Oc.Instance.deleteProject('my-test-project-1');
} catch {
// do nothing
}
try {
await Oc.Instance.deleteProject('my-test-project-2');
} catch {
// do nothing
}
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
}
});

suiteTeardown(async function () {
// ensure projects are cleaned up
try {
await Oc.Instance.deleteProject('my-test-project-1');
} catch {
// do nothing
}
try {
await Oc.Instance.deleteProject('my-test-project-2');
} catch {
// do nothing
}

if (isOpenShift) {
await LoginUtil.Instance.logout();
}
});

suite('analyse folder', function () {
const project1 = 'my-test-project-1';
if (isOpenShift) {
await LoginUtil.Instance.logout();
}
});

let tmpFolder1: Uri;
let tmpFolder2: Uri;
suite('analyse folder', function () {
const project1 = 'my-test-project-1';

let tmpFolder1: Uri;
let tmpFolder2: Uri;

suiteSetup(async function () {
await Oc.Instance.createProject(project1);
tmpFolder1 = Uri.parse(await promisify(tmp.dir)());
tmpFolder2 = Uri.parse(await promisify(tmp.dir)());
await Odo.Instance.createComponentFromFolder(
'nodejs',
'latest',
undefined,
'component1',
tmpFolder1,
'nodejs-starter',
);
await Odo.Instance.createComponentFromFolder(
'go',
'latest',
undefined,
'component2',
tmpFolder2,
'go-starter',
);
});

suiteSetup(async function () {
await Oc.Instance.createProject(project1);
tmpFolder1 = Uri.parse(await promisify(tmp.dir)());
tmpFolder2 = Uri.parse(await promisify(tmp.dir)());
await Odo.Instance.createComponentFromFolder(
'nodejs',
'latest',
undefined,
'component1',
tmpFolder1,
'nodejs-starter',
);
await Odo.Instance.createComponentFromFolder(
'go',
'latest',
undefined,
'component2',
tmpFolder2,
'go-starter',
);
});
suiteTeardown(async function () {
if (isOpenShift) {
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
}
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => {
const fsPath = workspaceFolder.uri.fsPath;
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath);
});
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders);
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true });
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true });
await Oc.Instance.deleteProject(project1);
});

suiteTeardown(async function () {
if (isOpenShift) {
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password);
}
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => {
const fsPath = workspaceFolder.uri.fsPath;
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath);
test('analyze()', async function () {
const analysis1 = await Alizer.Instance.alizerDevfile(tmpFolder1);
expect(analysis1.Name).to.exist;
expect(analysis1.Name).to.equal('nodejs');
const analysis2 = await Alizer.Instance.alizerDevfile(tmpFolder2);
expect(analysis2.Name).to.exist;
expect(analysis2.Name).to.equal('go');
});
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders);
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true });
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true });
await Oc.Instance.deleteProject(project1);
});

test('analyze()', async function () {
const analysis1 = await Alizer.Instance.alizerDevfile(tmpFolder1);
expect(analysis1.Name).to.exist;
expect(analysis1.Name).to.equal('nodejs');
const analysis2 = await Alizer.Instance.alizerDevfile(tmpFolder2);
expect(analysis2.Name).to.exist;
expect(analysis2.Name).to.equal('go');
});
});
suite('create component', function() {

suite('create component', function() {
const COMPONENT_TYPE = 'dotnet50';
const COMPONENT_VERSION = 'latest';

const COMPONENT_TYPE = 'dotnet50';
const COMPONENT_VERSION = 'latest';
let tmpFolder: string;

let tmpFolder: string;
suiteSetup(async function() {
tmpFolder = await promisify(tmp.dir)();
});

suiteSetup(async function() {
tmpFolder = await promisify(tmp.dir)();
});
suiteTeardown(async function() {
await fs.rm(tmpFolder, { recursive: true, force: true });
});

suiteTeardown(async function() {
await fs.rm(tmpFolder, { recursive: true, force: true });
});
test('createComponentFromTemplateProject()', async function() {
await Odo.Instance.createComponentFromTemplateProject(
tmpFolder, 'my-component', 8080,
COMPONENT_TYPE, COMPONENT_VERSION,
OdoPreference.DEFAULT_DEVFILE_REGISTRY_NAME, 'dotnet50-example');
try {
await fs.access(path.join(tmpFolder, 'devfile.yaml'));
} catch {
fail('Expected devfile to be created');
}
});

test('createComponentFromTemplateProject()', async function() {
await Odo.Instance.createComponentFromTemplateProject(
tmpFolder, 'my-component', 8080,
COMPONENT_TYPE, COMPONENT_VERSION,
OdoPreference.DEFAULT_DEVFILE_REGISTRY_NAME, 'dotnet50-example');
try {
await fs.access(path.join(tmpFolder, 'devfile.yaml'));
} catch {
fail('Expected devfile to be created');
}
});
test('analyze()', async function() {
const analysis = await Alizer.Instance.alizerDevfile(Uri.file(tmpFolder));
expect(analysis).to.exist;
expect(analysis.Name).to.equal(COMPONENT_TYPE);
});

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

test('deleteComponentConfiguration');
});

test('deleteComponentConfiguration');
});
});
Loading

0 comments on commit b4a8f47

Please sign in to comment.