Skip to content

Commit

Permalink
Move tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfdctaka committed Nov 14, 2023
1 parent 2710bb0 commit 8f19fe3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 66 deletions.
66 changes: 0 additions & 66 deletions src/test/suite/utils/uiUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@
*/

import * as assert from 'assert';
import * as path from 'path';
import { mkdir } from 'fs/promises';
import { UIUtils } from '../../../utils/uiUtils';
import {
NoStaticResourcesDirError,
NoWorkspaceError,
WorkspaceUtils
} from '../../../utils/workspaceUtils';
import { TempProjectDirManager } from '../../TestHelper';
import { QuickPickItem, window, QuickPick } from 'vscode';
import { afterEach, beforeEach } from 'mocha';
import sinon = require('sinon');
Expand Down Expand Up @@ -102,62 +94,4 @@ suite('UIUtils Test Suite', () => {
assert.equal(exceptionCount, 1);
assert.equal(quickPickSpy.dispose.called, true); // ensure it was disposed of after item selected
});

test('Static resources dir: workspace does not exist', async () => {
try {
await WorkspaceUtils.getStaticResourcesDir();
assert.fail('There should have been an error thrown.');
} catch (noWorkspaceErr) {
assert.ok(
noWorkspaceErr instanceof NoWorkspaceError,
'No workspace should be defined in this test.'
);
}
});

test('Static resources dir: static resources dir does not exist', async () => {
const projectDirMgr =
await TempProjectDirManager.createTempProjectDir();
const getWorkspaceDirStub = sinon.stub(
WorkspaceUtils,
'getWorkspaceDir'
);
getWorkspaceDirStub.returns(projectDirMgr.projectDir);
try {
await WorkspaceUtils.getStaticResourcesDir();
assert.fail('There should have been an error thrown.');
} catch (noStaticDirErr) {
assert.ok(
noStaticDirErr instanceof NoStaticResourcesDirError,
'No static resources dir should be defined in this test.'
);
} finally {
await projectDirMgr.removeDir();
getWorkspaceDirStub.restore();
}
});

test('Static resources dir: static resources dir exists', async () => {
const projectDirMgr =
await TempProjectDirManager.createTempProjectDir();
const getWorkspaceDirStub = sinon.stub(
WorkspaceUtils,
'getWorkspaceDir'
);
getWorkspaceDirStub.returns(projectDirMgr.projectDir);

const staticResourcesAbsPath = path.join(
projectDirMgr.projectDir,
WorkspaceUtils.STATIC_RESOURCES_PATH
);
await mkdir(staticResourcesAbsPath, { recursive: true });

try {
const outputDir = await WorkspaceUtils.getStaticResourcesDir();
assert.equal(outputDir, staticResourcesAbsPath);
} finally {
await projectDirMgr.removeDir();
getWorkspaceDirStub.restore();
}
});
});
84 changes: 84 additions & 0 deletions src/test/suite/utils/workspaceUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import * as assert from 'assert';
import * as path from 'path';
import { mkdir } from 'fs/promises';
import {
NoStaticResourcesDirError,
NoWorkspaceError,
WorkspaceUtils
} from '../../../utils/workspaceUtils';
import { TempProjectDirManager } from '../../TestHelper';
import { afterEach, beforeEach } from 'mocha';
import sinon = require('sinon');

suite('Workspace Test Suite', () => {
beforeEach(function () {});

afterEach(function () {
sinon.restore();
});

test('Static resources dir: workspace does not exist', async () => {
try {
await WorkspaceUtils.getStaticResourcesDir();
assert.fail('There should have been an error thrown.');
} catch (noWorkspaceErr) {
assert.ok(
noWorkspaceErr instanceof NoWorkspaceError,
'No workspace should be defined in this test.'
);
}
});

test('Static resources dir: static resources dir does not exist', async () => {
const projectDirMgr =
await TempProjectDirManager.createTempProjectDir();
const getWorkspaceDirStub = sinon.stub(
WorkspaceUtils,
'getWorkspaceDir'
);
getWorkspaceDirStub.returns(projectDirMgr.projectDir);
try {
await WorkspaceUtils.getStaticResourcesDir();
assert.fail('There should have been an error thrown.');
} catch (noStaticDirErr) {
assert.ok(
noStaticDirErr instanceof NoStaticResourcesDirError,
'No static resources dir should be defined in this test.'
);
} finally {
await projectDirMgr.removeDir();
getWorkspaceDirStub.restore();
}
});

test('Static resources dir: static resources dir exists', async () => {
const projectDirMgr =
await TempProjectDirManager.createTempProjectDir();
const getWorkspaceDirStub = sinon.stub(
WorkspaceUtils,
'getWorkspaceDir'
);
getWorkspaceDirStub.returns(projectDirMgr.projectDir);

const staticResourcesAbsPath = path.join(
projectDirMgr.projectDir,
WorkspaceUtils.STATIC_RESOURCES_PATH
);
await mkdir(staticResourcesAbsPath, { recursive: true });

try {
const outputDir = await WorkspaceUtils.getStaticResourcesDir();
assert.equal(outputDir, staticResourcesAbsPath);
} finally {
await projectDirMgr.removeDir();
getWorkspaceDirStub.restore();
}
});
});

0 comments on commit 8f19fe3

Please sign in to comment.