Skip to content

Commit c3172b8

Browse files
author
rocketraccoon
committed
fix(create-testplane): fix scripts test
1 parent 6d24431 commit c3172b8

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
build
33
build-spec
44
.DS_Store
5+
.idea

src/fsUtils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ export const writeJson = async (filePath: string, obj: Record<string, unknown>):
123123
return fs.promises.writeFile(filePath, JSON.stringify(obj, null, 4));
124124
};
125125

126-
export default { exists, ensureDirectory, writeTestplaneConfig, writeTest, writeJson };
126+
export const readJson = async (filePath: string): Promise<Record<string, unknown>> => {
127+
return new Promise(resolve => {
128+
fs.readFile(filePath, "utf8", (_, data: string) => resolve(JSON.parse(data)));
129+
});
130+
};
131+
132+
export default { exists, ensureDirectory, writeTestplaneConfig, writeTest, writeJson, readJson };

src/package.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ const initNodeProject = (dirPath: string, packageManager: PackageManager): Promi
6161
);
6262
});
6363

64+
interface MinimalPackageJson {
65+
scripts?: { [key: string]: string };
66+
}
67+
6468
export const initApp = async (dirPath: string, extraQuestions: boolean): Promise<PackageManager> => {
6569
await fsUtils.ensureDirectory(dirPath);
6670

@@ -79,6 +83,18 @@ export const initApp = async (dirPath: string, extraQuestions: boolean): Promise
7983
await initNodeProject(dirPath, packageManager);
8084
}
8185

86+
const packageJson: MinimalPackageJson = await fsUtils.readJson(path.resolve(dirPath, PACKAGE_JSON));
87+
88+
if (packageJson && (!packageJson?.scripts?.test || !isPackageJsonExist)) {
89+
packageJson.scripts = {
90+
...(packageJson?.scripts || {}),
91+
test: "testplane",
92+
"test:gui": "testplane gui",
93+
};
94+
95+
await fsUtils.writeJson(path.resolve(dirPath, PACKAGE_JSON), packageJson as Record<string, string>);
96+
}
97+
8298
return packageManager;
8399
};
84100

0 commit comments

Comments
 (0)