Skip to content

Commit

Permalink
Make dockerCliSymlinks tests work with rdctl paths
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Pickering <adam.pickering@suse.com>
  • Loading branch information
adamkpickering committed Jun 20, 2023
1 parent 6ffe607 commit 216ce1b
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from 'os';
import path from 'path';

// The (mock) application directory.
let appDir = '';
let appDir = process.cwd();

// Mock Electron.app.getAppPath() to return appDir.
jest.mock('electron', () => {
Expand All @@ -29,6 +29,9 @@ jest.spyOn(fs.promises, 'readdir').mockImplementation((dir, encoding) => {
// eslint-disable-next-line import/first -- Need to mock first.
import { CheckerDockerCLISymlink } from '../dockerCliSymlinks';

// eslint-disable-next-line import/first -- Need to mock first.
import paths from '@pkg/utils/paths';

const { mkdtemp, rm } = jest.requireActual('fs/promises');
const describeUnix = process.platform === 'win32' ? describe.skip : describe;
const describeWin32 = process.platform === 'win32' ? describe : describe.skip;
Expand All @@ -39,13 +42,18 @@ describeUnix(CheckerDockerCLISymlink, () => {
const rdBinDir = path.join(os.homedir(), '.rd', 'bin');
const rdBinExecutable = path.join(rdBinDir, executable);
let appDirExecutable = '';
let replacedPathsResources: jest.ReplaceProperty<string>;

beforeAll(async() => {
appDir = await mkdtemp(path.join(os.tmpdir(), 'rd-diag-'));
await fs.promises.mkdir(path.join(appDir, 'resources'));
appDirExecutable = path.join(appDir, 'resources', os.platform(), 'bin', executable);
const resourcesDir = path.join(appDir, 'resources');

await fs.promises.mkdir(resourcesDir);
appDirExecutable = path.join(resourcesDir, os.platform(), 'bin', executable);
replacedPathsResources = jest.replaceProperty(paths, 'resources', resourcesDir);
});
afterAll(async() => {
replacedPathsResources.restore();
await rm(appDir, { recursive: true, force: true });
});

Expand Down

0 comments on commit 216ce1b

Please sign in to comment.