Skip to content

Commit e85e183

Browse files
committed
Add unit test to force coverage generation
1 parent 75d9344 commit e85e183

File tree

8 files changed

+159
-20
lines changed

8 files changed

+159
-20
lines changed

__mocks__/vscode.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
const { URI } = require('vscode-uri');
18+
19+
module.exports = {
20+
Uri: URI,
21+
workspace: {
22+
getConfiguration: jest.fn(() => ({
23+
get: jest.fn(),
24+
})),
25+
},
26+
extensions: {
27+
getExtension: jest.fn(),
28+
},
29+
commands: {
30+
executeCommand: jest.fn(),
31+
}
32+
};

eslint.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ import tseslint from 'typescript-eslint';
2020
export default [
2121
{
2222
ignores: [
23+
"__mocks__/**/*",
24+
"coverage/**/*",
2325
"dist",
2426
"scripts",
2527
"**/*.d.ts",
26-
"jest.config.js",
28+
"*.config.{ts,js}",
29+
"*.setup.{ts,js}",
2730
"node_modules",
2831
"webpack.config.js"
2932
]

jest.config.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

jest.config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import type { Config } from 'jest';
18+
19+
const config: Config = {
20+
testEnvironment: "node",
21+
preset: "ts-jest",
22+
transform: {
23+
"^.+\\.tsx?$": [
24+
"ts-jest", {
25+
}
26+
],
27+
},
28+
setupFiles: ["<rootDir>/jest.setup.ts"],
29+
clearMocks: true,
30+
collectCoverage: true,
31+
collectCoverageFrom: [
32+
"src/**/*.{ts,tsx}",
33+
"!**/*.d.ts",
34+
"!**/*.factories.{ts,tsx}",
35+
"!src/desktop/extension.ts",
36+
],
37+
coverageDirectory: "./coverage",
38+
coverageReporters: ["lcov", "text"],
39+
};
40+
41+
export default config;

jest.setup.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
"ts-node": "^10.9.2",
255255
"typescript": "^5.4.5",
256256
"typescript-eslint": "8.24.1",
257+
"vscode-uri": "^3.1.0",
257258
"webpack": "^5.98.0",
258259
"webpack-cli": "^6.0.1",
259260
"yargs": "^17.7.2"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
import * as vscode from 'vscode';
18+
import * as fs from 'fs';
19+
import * as os from 'os';
20+
import * as path from 'path';
21+
import { BuiltinToolPath } from './builtin-tool-path';
22+
23+
const TOOL_EXTENSION = os.platform() === 'win32' ? '.exe' : '';
24+
25+
describe('BuiltinToolPath', () => {
26+
27+
let testFolder: string;
28+
29+
beforeEach(() => {
30+
testFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'jest-'));
31+
(vscode.extensions.getExtension as jest.Mock).mockReturnValue({
32+
extensionUri: vscode.Uri.file(testFolder),
33+
});
34+
});
35+
36+
afterEach(() => {
37+
jest.clearAllMocks();
38+
fs.rmSync(testFolder, { recursive: true, force: true });
39+
});
40+
41+
it('should return the correct path for a given tool', () => {
42+
const builtinToolPath = new BuiltinToolPath('tools/pyocd/pyocd');
43+
44+
fs.mkdirSync(`${testFolder}/tools/pyocd`, { recursive: true });
45+
fs.writeFileSync(`${testFolder}/tools/pyocd/pyocd${TOOL_EXTENSION}`, '');
46+
47+
const expected = vscode.Uri.file(`${testFolder}/tools/pyocd/pyocd${TOOL_EXTENSION}`);
48+
const result = builtinToolPath.getAbsolutePath();
49+
expect(result?.fsPath).toBe(expected.fsPath);
50+
});
51+
52+
it('should return undefined if tool does not exist', () => {
53+
const builtinToolPath = new BuiltinToolPath('tools/pyocd/pyocd');
54+
55+
const result = builtinToolPath.getAbsolutePath();
56+
expect(result).toBeUndefined();
57+
});
58+
59+
});
60+

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4838,6 +4838,11 @@ v8-to-istanbul@^9.0.1:
48384838
"@types/istanbul-lib-coverage" "^2.0.1"
48394839
convert-source-map "^2.0.0"
48404840

4841+
vscode-uri@^3.1.0:
4842+
version "3.1.0"
4843+
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.1.0.tgz#dd09ec5a66a38b5c3fffc774015713496d14e09c"
4844+
integrity sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ==
4845+
48414846
walker@^1.0.8:
48424847
version "1.0.8"
48434848
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.8.tgz#bd498db477afe573dc04185f011d3ab8a8d7653f"

0 commit comments

Comments
 (0)