From 8f19fe38ae816d630ecd414d162fbd70398ab9e5 Mon Sep 17 00:00:00 2001 From: Takashi Arai Date: Tue, 14 Nov 2023 14:22:15 -0800 Subject: [PATCH] Move tests. --- src/test/suite/utils/uiUtils.test.ts | 66 ---------------- src/test/suite/utils/workspaceUtils.test.ts | 84 +++++++++++++++++++++ 2 files changed, 84 insertions(+), 66 deletions(-) create mode 100644 src/test/suite/utils/workspaceUtils.test.ts diff --git a/src/test/suite/utils/uiUtils.test.ts b/src/test/suite/utils/uiUtils.test.ts index d47d4b18..f09c0967 100644 --- a/src/test/suite/utils/uiUtils.test.ts +++ b/src/test/suite/utils/uiUtils.test.ts @@ -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'); @@ -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(); - } - }); }); diff --git a/src/test/suite/utils/workspaceUtils.test.ts b/src/test/suite/utils/workspaceUtils.test.ts new file mode 100644 index 00000000..2c49aafa --- /dev/null +++ b/src/test/suite/utils/workspaceUtils.test.ts @@ -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(); + } + }); +});