Skip to content

Commit 6ed4647

Browse files
committed
Fix path test cases
1 parent 7b8289b commit 6ed4647

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

src/util/config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import PHPIdentifyMalformatError from '@/error/PHPIdentifyMalformatError';
1717
describe('getWpConfigByPath()', () => {
1818
test('should call getWpConfig()', () => {
1919
const result = getWpConfigByPath(path.join(appRootPath, 'test/wordpress'));
20-
expect(result.dbHost).toBe('localhost');
21-
expect(result.dbPort).toBe(3306);
22-
expect(result.dbUser).toBe('username_here');
23-
expect(result.database).toBe('database_name_here');
20+
expect(result.dbHost).toBe('database.host.local');
21+
expect(result.dbPort).toBe(3389);
22+
expect(result.dbUser).toBe('username');
23+
expect(result.database).toBe('new_database');
2424
});
2525
});
2626

src/util/path.spec.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import { describe, expect, test } from 'vitest';
1+
import fs from 'fs';
2+
import { describe, expect, test, vi } from 'vitest';
23

3-
import { getPHPErrorLogPath, getUnixPath, getWpSampleConfigPath } from './path';
4+
import {
5+
getPHPErrorLogPath,
6+
getUnixPath,
7+
getWpSampleConfigPath,
8+
isDirectory,
9+
isFile,
10+
} from './path';
411

512
const path = '/var/www/';
613
const phpVer = '8.1';
714
const identity = 'my.site';
815

16+
vi.mock('fs');
17+
918
describe('getUnixPath()', () => {
1019
test('return correct paths', () => {
1120
const { wp, php, nginx } = getUnixPath(path, phpVer, identity);
@@ -29,3 +38,27 @@ describe('getPHPErrorLogPath()', () => {
2938
expect(getPHPErrorLogPath(phpVer, identity)).toBe('/var/log/php8.1-fpm-my.site.log.error');
3039
});
3140
});
41+
42+
describe('isDirectory()', () => {
43+
test('return true', () => {
44+
vi.mocked(fs.existsSync).mockReturnValueOnce(true);
45+
vi.mocked(fs.lstatSync).mockReturnValueOnce({
46+
isDirectory() {
47+
return true;
48+
},
49+
} as any);
50+
expect(isDirectory('/')).toBe(true);
51+
});
52+
});
53+
54+
describe('isFile()', () => {
55+
test('return true', () => {
56+
vi.mocked(fs.existsSync).mockReturnValueOnce(true);
57+
vi.mocked(fs.lstatSync).mockReturnValueOnce({
58+
isFile() {
59+
return true;
60+
},
61+
} as any);
62+
expect(isFile('/')).toBe(true);
63+
});
64+
});

0 commit comments

Comments
 (0)