Skip to content

Commit

Permalink
Merge pull request #43 from Abiji-2020/unit-test
Browse files Browse the repository at this point in the history
Unit test for the components
  • Loading branch information
gemanor authored Dec 30, 2024
2 parents 4b13060 + 7daf0b9 commit 954a69e
Show file tree
Hide file tree
Showing 40 changed files with 2,458 additions and 758 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ Based on [Pastel](https://github.com/vadimdemedes/create-pastel-app)
- run `npm install`
- run `npx tsx ./source/cli.tsx`

### Writing Tests

Permit CLI uses [`vitest`](https://vitest.dev/) as a tool for writing tests. It also uses [`ink-testing-library`](https://github.com/vadimdemedes/ink-testing-library) to render the `Ink` components.

- run `npx vitest` for testing
- run `npx vitest --coverage` for code coverage.

## CLI

```
Expand Down
501 changes: 321 additions & 180 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@types/react": "^18.0.32",
"@typescript-eslint/eslint-plugin": "^8.12.2",
"@typescript-eslint/parser": "^8.12.2",
"@vitest/coverage-istanbul": "^2.1.5",
"@vitest/coverage-v8": "^2.1.5",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"chalk": "^5.2.0",
"delay": "^6.0.0",
"eslint": "^9.13.0",
Expand All @@ -59,12 +59,11 @@
"eslint-plugin-sonarjs": "^2.0.4",
"globals": "^15.11.0",
"ink-testing-library": "^4.0.0",
"jsdom": "^25.0.1",
"parser": "^0.1.4",
"prettier": "^3.3.3",
"ts-node": "^10.9.1",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0",
"vitest": "^2.1.5"
"vitest": "^2.1.8"
}
}
8 changes: 6 additions & 2 deletions source/commands/apiKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zod from 'zod';
import { keyAccountOption } from '../options/keychain.js';
import { KEYSTORE_PERMIT_SERVICE_NAME } from '../config.js';

import keytar from 'keytar';
import * as keytar from 'keytar';

export const args = zod.tuple([
zod
Expand Down Expand Up @@ -34,7 +34,11 @@ export default function ApiKey({ args, options }: Props) {
keytar
.getPassword(KEYSTORE_PERMIT_SERVICE_NAME, options.keyAccount)
.then(value => setReadKey(value || ''))
.catch(reason => setReadKey(`-- Failed to read key- reason ${reason}`));
.catch(reason =>
setReadKey(
`-- Failed to read key- reason ${reason instanceof Error ? reason.message : String(reason)}`,
),
);
}
}, [action, options.keyAccount]);

Expand Down
6 changes: 5 additions & 1 deletion source/commands/pdp/check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ export default function Check({ options }: Props) {
queryPDP(apiKey);
})
.catch(reason => {
setError(reason);
if (reason instanceof Error) {
setError(reason.message);
} else {
setError(String(reason));
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [options.keyAccount]);
Expand Down
209 changes: 0 additions & 209 deletions source/components/EnvSelectionWizard.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion source/components/LoginFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const LoginFlow: React.FC<LoginFlowProps> = ({
}
onSuccess(token, headers.getSetCookie()[0] ?? '');
} catch (error: unknown) {
onError(`Unexpected error during authentication. ${error}`);
onError(`Unexpected error during authentication. ${error as string}`);
return;
}
}
Expand Down
70 changes: 0 additions & 70 deletions source/components/WorkspaceSelector.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion source/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash, randomBytes } from 'node:crypto';
import * as http from 'node:http';
import open from 'open';
import pkg from 'keytar';
import * as pkg from 'keytar';
import {
DEFAULT_PERMIT_KEYSTORE_ACCOUNT,
KEYSTORE_PERMIT_SERVICE_NAME,
Expand Down
2 changes: 1 addition & 1 deletion source/lib/gitops/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function configurePermit(
status: gitConfigResponse.status,
};
} else {
throw new Error('Invalid Configuration ' + response);
throw new Error('Invalid Configuration ');
}
}

Expand Down
Loading

0 comments on commit 954a69e

Please sign in to comment.