Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 3930838

Browse files
committed
feat: Add basic unit tests
1 parent 574d50a commit 3930838

File tree

6 files changed

+1966
-46
lines changed

6 files changed

+1966
-46
lines changed

__mocks__/electron.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const app = {
2+
getPath: jest.fn(),
3+
};

common/utils/__tests__/utils.test.ts

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { IWindow } from '@app/Terminal';
2+
import { addQuotes, resolveToWSLPath } from '@common/utils/utils';
3+
4+
describe('Resolve WSL paths', () => {
5+
6+
it('should resolve path if shell is wsl', () => {
7+
8+
const window: IWindow = {
9+
10+
id: 0,
11+
name: '',
12+
selected: true,
13+
terminalType: {
14+
name: '',
15+
path: 'wsl.exe',
16+
},
17+
};
18+
19+
const path = 'C:\\Users\\tom';
20+
const expected = '/mnt/c/Users/tom';
21+
22+
expect(resolveToWSLPath(window, path)).toEqual(expected);
23+
});
24+
25+
it('should not resolve path if shell is not wsl', () => {
26+
27+
const window: IWindow = {
28+
29+
id: 0,
30+
name: '',
31+
selected: true,
32+
terminalType: {
33+
name: '',
34+
path: '/bin/zsh',
35+
},
36+
};
37+
38+
const path = '/var/www/html';
39+
const expected = '/var/www/html';
40+
41+
expect(resolveToWSLPath(window, path)).toEqual(expected);
42+
});
43+
44+
it('should not resolve path if window is ssh', () => {
45+
46+
const window: IWindow = {
47+
48+
id: 0,
49+
name: '',
50+
selected: true,
51+
terminalType: {
52+
name: '',
53+
host: '',
54+
port: 0,
55+
username: '',
56+
},
57+
};
58+
59+
const path = '/var/www/html';
60+
const expected = '/var/www/html';
61+
62+
expect(resolveToWSLPath(window, path)).toEqual(expected);
63+
});
64+
});
65+
66+
describe('Add quotes', () => {
67+
68+
it('should add quotes to string containing multiple paths', () => {
69+
70+
const paths = '/var/www/html /var/log';
71+
const expected = '"/var/www/html /var/log"';
72+
73+
expect(addQuotes(paths)).toEqual(expected);
74+
});
75+
76+
it('should not add quotes to string with only one path', () => {
77+
78+
const paths = '/var/log';
79+
const expected = '/var/log';
80+
81+
expect(addQuotes(paths)).toEqual(expected);
82+
});
83+
});

common/utils/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import electron from 'electron';
1+
import * as electron from 'electron';
22
import { IWindow, TerminalType } from '@app/Terminal';
33
import { IShell } from '@common/config/Config';
4-
import crypto from 'crypto';
4+
import * as crypto from 'crypto';
55

66
export const homePath = (electron.app || electron.remote.app).getPath('home');
77
export const isDev = process.env.NODE_ENV !== 'production';

jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
moduleNameMapper: {
5+
'^@app/(.*)$': '<rootDir>/app/$1',
6+
'^@common/(.*)$': '<rootDir>/common/$1',
7+
'^@src/(.*)$': '<rootDir>/src/$1',
8+
'^@ui/(.*)$': '<rootDir>/ui/$1',
9+
},
10+
};

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
},
4545
"devDependencies": {
4646
"@babel/preset-react": "^7.12.10",
47+
"@types/jest": "^26.0.20",
4748
"@types/keytar": "^4.4.2",
4849
"@types/node": "^12.13.0",
4950
"@types/react": "^17.0.0",
@@ -62,9 +63,11 @@
6263
"eslint-plugin-tsdoc": "^0.2.10",
6364
"eslint-plugin-unused-imports": "^1.0.1",
6465
"husky": "^5.0.6",
66+
"jest": "^26.6.3",
6567
"node-sass": "^5.0.0",
6668
"sass-loader": "^10.1.0",
67-
"typescript": "^4.1.3",
69+
"ts-jest": "^26.5.4",
70+
"typescript": "^4.2.3",
6871
"webpack": "~4.42.1"
6972
},
7073
"optionalDependencies": {

0 commit comments

Comments
 (0)