Skip to content

Commit a9b669b

Browse files
author
Artem
committed
fix tests + avoid using fs-extra ensure dir due to folder permissions
1 parent 3170efa commit a9b669b

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

redisinsight/api/config/default.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { join } from 'path';
22

3-
const prevHomedir = join(__dirname, '..', '.redisinsight-v2.0-dev');
4-
5-
const homedir = join(__dirname, '..', '.redisinsight-v2-dev');
3+
const homedir = join(__dirname, '..');
64

75
const buildInfoFileName = 'build.json';
86
const dataZipFileName = 'data.zip';
@@ -18,7 +16,7 @@ const defaultsDir = process.env.BUILD_TYPE === 'ELECTRON' && process['resourcesP
1816
export default {
1917
dir_path: {
2018
homedir,
21-
prevHomedir,
19+
prevHomedir: homedir,
2220
staticDir,
2321
defaultsDir,
2422
logs: join(homedir, 'logs'),

redisinsight/api/src/app.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from 'fs-extra';
1+
import * as fs from 'fs';
22
import {
33
MiddlewareConsumer, Module, NestModule, OnModuleInit,
44
} from '@nestjs/common';
@@ -73,14 +73,18 @@ const PATH_CONFIG = config.get('dir_path');
7373
providers: [],
7474
})
7575
export class AppModule implements OnModuleInit, NestModule {
76-
async onModuleInit() {
76+
onModuleInit() {
7777
// creating required folders
7878
const foldersToCreate = [
7979
PATH_CONFIG.pluginsAssets,
8080
PATH_CONFIG.customPlugins,
8181
];
8282

83-
await Promise.all(foldersToCreate.map(fs.ensureDir));
83+
foldersToCreate.forEach((folder) => {
84+
if (!fs.existsSync(folder)) {
85+
fs.mkdirSync(folder, { recursive: true });
86+
}
87+
});
8488
}
8589

8690
configure(consumer: MiddlewareConsumer) {

redisinsight/api/src/init-helper.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@ import { join } from 'path';
55
const PATH_CONFIG = config.get('dir_path');
66
const DB_CONFIG = config.get('db');
77

8+
/**
9+
* Copy source if exists
10+
* @param source
11+
* @param destination
12+
*/
13+
const copySource = async (source, destination) => {
14+
if (await fs.pathExists(source)) {
15+
await fs.copy(source, destination).catch();
16+
}
17+
};
18+
19+
/**
20+
* Migrate data from previous home folder defined in configs
21+
*/
822
export const migrateHomeFolder = async () => {
923
try {
10-
if (!await fs.pathExists(DB_CONFIG.database) && await fs.pathExists(PATH_CONFIG.prevHomedir)) {
24+
if (!(await fs.pathExists(DB_CONFIG.database)) && await fs.pathExists(PATH_CONFIG.prevHomedir)) {
1125
await fs.ensureDir(PATH_CONFIG.homedir);
1226

1327
await Promise.all([
1428
'redisinsight.db',
1529
'plugins',
16-
'plugins2',
17-
].map((target) => fs.copy(
30+
].map((target) => copySource(
1831
join(PATH_CONFIG.prevHomedir, target),
1932
join(PATH_CONFIG.homedir, target),
20-
).catch()));
33+
)));
2134
}
2235
} catch (e) {
2336
// continue initialization even without migration

redisinsight/api/test/test-runs/docker.build.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
APP_DATA_HOMEDIR=/root/.redisinsight-v2.0
21
COV_FOLDER=./coverage
32
ID=defaultid
43
RTE=defaultrte
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
APP_DATA_HOMEDIR=/root/.redisinsight-2.0
21
COV_FOLDER=./coverage
32
ID=defaultid
43
RTE=defaultrte

0 commit comments

Comments
 (0)