Skip to content

Commit

Permalink
fix: add unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
narol1024 committed Jun 2, 2024
1 parent b131e22 commit b27b8f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/platforms/npm-package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function countNpmPackageDependants(packageName: string, version: st
const path = version !== null ? `${packageName}/v/${version}` : packageName;
const url = `https://www.npmjs.com/package/${path}?activeTab=dependents&t=${Date.now()}`;
const timeoutPromise = new Promise<void>((_, timeoutReject) => {
countNpmPackageDependantsTimeId = setTimeout(() => timeoutReject(new Error('Operation timed out')), 8000);
countNpmPackageDependantsTimeId = setTimeout(() => timeoutReject(new Error('Operation timed out')), 20000);
});
const fetchPromise = async (): Promise<void> => {
try {
Expand Down Expand Up @@ -130,6 +130,6 @@ export async function analyze(packageNames: string): Promise<Dep[]> {
const deps = await Promise.all(depsPromises);
return Promise.resolve(deps);
} catch (error: any) {
return Promise.reject(new Error(`Cannot analyze ${packageNames}, the reason is ${error.message}`));
return Promise.reject(new Error(`Cannot analyze ${packageNames}, the reason is \"${error.message}\"`));
}
}
4 changes: 2 additions & 2 deletions src/platforms/workspaces/yarn/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ describe('Workspaces Tests', () => {
it('should not read an invalid package', async () => {
await expect(analyze('./src/platforms/workspaces/yarn/fixture/invalid-packages')).rejects.toEqual(
new Error(
`It seems that the 'subpackages' directory has not been found, please check the configuration of yarn workspaces..`,
`It seems that the 'subpackages' directory has not been found, please check the configuration of yarn workspaces.`,
),
);
});
it('can not analyze for the invalid local packages', async () => {
await expect(analyze('./error-path')).rejects.toEqual(
new Error(`Cannot analyze ./error-path, the reason is Cannot find package.json on ./error-path.`),
new Error(`Cannot analyze ./error-path, the reason is \"Cannot find package.json on ./error-path.\".`),
);
});
it('can be analyzed for the local packages', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/workspaces/yarn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function analyze(packagePath: string) {
if (dependencyMap.length === 0) {
return Promise.reject(
new Error(
"It seems that the 'subpackages' directory has not been found, please check the configuration of yarn workspaces..",
"It seems that the 'subpackages' directory has not been found, please check the configuration of yarn workspaces.",
),
);
}
Expand All @@ -62,6 +62,6 @@ export async function analyze(packagePath: string) {
}),
);
} catch (error: any) {
return Promise.reject(new Error(`Cannot analyze ${packagePath}, the reason is ${error.message}`));
return Promise.reject(new Error(`Cannot analyze ${packagePath}, the reason is \"${error.message}\".`));
}
}

0 comments on commit b27b8f6

Please sign in to comment.