|
| 1 | +/** |
| 2 | + * Copyright 2025 Arm Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +jest.mock('path'); |
| 18 | +import * as os from 'os'; |
| 19 | +import * as path from 'path'; |
| 20 | +import { getCmsisPackRootPath, isWindows } from './utils'; |
| 21 | + |
| 22 | +const CMSIS_PACK_ROOT_DEFAULT = 'mock/path'; |
| 23 | +describe('getCmsisPackRoot', () => { |
| 24 | + |
| 25 | + afterEach(() => { |
| 26 | + jest.clearAllMocks(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('checks if CMSIS_PACK_ROOT already exists', () => { |
| 30 | + const originalProcessEnv = process.env; |
| 31 | + process.env = { ...originalProcessEnv, CMSIS_PACK_ROOT: CMSIS_PACK_ROOT_DEFAULT }; |
| 32 | + const returnValue = getCmsisPackRootPath(); |
| 33 | + expect(returnValue).toBe(CMSIS_PACK_ROOT_DEFAULT); |
| 34 | + process.env = originalProcessEnv; |
| 35 | + }); |
| 36 | + |
| 37 | + it('checks if CMSIS_PACK_ROOT has been added or not', () => { |
| 38 | + const originalProcessEnv = process.env; |
| 39 | + delete process.env['CMSIS_PACK_ROOT']; |
| 40 | + const spy = jest.spyOn(path, 'join'); |
| 41 | + getCmsisPackRootPath(); |
| 42 | + if (isWindows) { |
| 43 | + expect(spy).toHaveBeenCalledWith(process.env['LOCALAPPDATA'] ?? os.homedir(), 'Arm', 'Packs'); |
| 44 | + } else { |
| 45 | + expect(spy).toHaveBeenCalledWith(os.homedir(), '.cache', 'arm', 'packs'); |
| 46 | + } |
| 47 | + process.env = originalProcessEnv; |
| 48 | + }); |
| 49 | +}); |
0 commit comments