Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions packages/sdk/electron/__tests__/platform/ElectronInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ import * as os from 'os';

import ElectronInfo from '../../src/platform/ElectronInfo';

jest.mock('os', () => ({
...jest.requireActual('os'),
platform: jest.fn(),
release: jest.fn(),
arch: jest.fn(),
}));

const actualOs = jest.requireActual<typeof os>('os');

// Restore real os implementations before each test so non-mock tests still work.
// Mock tests override these per-test with mockReturnValue.
beforeEach(() => {
(os.platform as jest.Mock).mockImplementation(actualOs.platform);
(os.release as jest.Mock).mockImplementation(actualOs.release);
(os.arch as jest.Mock).mockImplementation(actualOs.arch);
});

describe('given an information instance', () => {
const info = new ElectronInfo();

Expand Down Expand Up @@ -34,15 +51,14 @@ describe('given an information instance', () => {
describe('given an information instance with mock data', () => {
const info = new ElectronInfo();

it('can get platform information', () => {
const platformSpy = jest.spyOn(os, 'platform');
platformSpy.mockReturnValue('darwin');

const releaseSpy = jest.spyOn(os, 'release');
releaseSpy.mockReturnValue('0.0.0');
afterEach(() => {
jest.clearAllMocks();
});

const archSpy = jest.spyOn(os, 'arch');
archSpy.mockReturnValue('x64');
it('can get platform information', () => {
(os.platform as jest.Mock).mockReturnValue('darwin');
(os.release as jest.Mock).mockReturnValue('0.0.0');
(os.arch as jest.Mock).mockReturnValue('x64');

global.process = {
...process,
Expand All @@ -65,9 +81,7 @@ describe('given an information instance with mock data', () => {
['linux', 'Linux'],
['some_os', 'some_os'],
])('handles known platforms', (platform, processed) => {
const platformSpy = jest.spyOn(os, 'platform');
// @ts-ignore
platformSpy.mockReturnValue(platform);
(os.platform as jest.Mock).mockReturnValue(platform);

const data = info.platformData();
expect(data.os).toBeDefined();
Expand Down
36 changes: 25 additions & 11 deletions packages/sdk/server-node/__tests__/platform/NodeInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@ import * as os from 'os';

import NodeInfo from '../../src/platform/NodeInfo';

jest.mock('os', () => ({
...jest.requireActual('os'),
platform: jest.fn(),
version: jest.fn(),
arch: jest.fn(),
}));

const actualOs = jest.requireActual<typeof os>('os');

// Restore real os implementations before each test so non-mock tests still work.
// Mock tests override these per-test with mockReturnValue.
beforeEach(() => {
(os.platform as jest.Mock).mockImplementation(actualOs.platform);
(os.version as jest.Mock).mockImplementation(actualOs.version);
(os.arch as jest.Mock).mockImplementation(actualOs.arch);
});

describe('given an information instance', () => {
const info = new NodeInfo({});

Expand Down Expand Up @@ -34,15 +51,14 @@ test('it supports wrapper name and version', () => {
describe('given an information instance with mock data', () => {
const info = new NodeInfo({});

it('can get platform information', () => {
const platformSpy = jest.spyOn(os, 'platform');
platformSpy.mockReturnValue('darwin');

const versionSpy = jest.spyOn(os, 'version');
versionSpy.mockReturnValue('0.0.0');
afterEach(() => {
jest.clearAllMocks();
});

const archSpy = jest.spyOn(os, 'arch');
archSpy.mockReturnValue('s390x');
it('can get platform information', () => {
(os.platform as jest.Mock).mockReturnValue('darwin');
(os.version as jest.Mock).mockReturnValue('0.0.0');
(os.arch as jest.Mock).mockReturnValue('s390x');

global.process = {
...process,
Expand All @@ -64,9 +80,7 @@ describe('given an information instance with mock data', () => {
['linux', 'Linux'],
['some_os', 'some_os'],
])('handles known platforms', (platform, processed) => {
const platformSpy = jest.spyOn(os, 'platform');
// @ts-ignore
platformSpy.mockReturnValue(platform);
(os.platform as jest.Mock).mockReturnValue(platform);

const data = info.platformData();
expect(data.os).toBeDefined();
Expand Down
Loading