Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:update import for test file #100

Merged
merged 6 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

39 changes: 23 additions & 16 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ Keploy simplifies the testing process by seamlessly generating end-to-end test c
``` bash
"scripts": {
// ... other scripts
"test": "jest",
"test": "jest --coverage",
"coverage": "nyc npm test && npm run coverage:merge && npm run coverage:report",
"coverage:merge": "nyc merge ./coverage .nyc_output/out.json",
"coverage:report": "nyc report --reporter=lcov --reporter=text",
"coverage:merge": "mkdir -p ./coverage && nyc merge ./coverage .nyc_output/out.json",
"coverage:report": "nyc report --reporter=lcov --reporter=text"
// ... other scripts
}
```
Expand All @@ -58,28 +58,35 @@ Keploy simplifies the testing process by seamlessly generating end-to-end test c

The contents of the file will be
```bash
const {
KeployTest,
Config,
} = require('../../typescript-sdk/dist/keployCli');

const { expect } = require('@jest/globals');
const keploy = require('@keploy-sdk'); //shortend this
const timeOut = 300000;

const { expect } = require('@jest/globals');
describe('Keploy Server Tests', () => {
test('TestKeploy', async () => {
// testResult = await KeployTest()
const config = new Config('npm start')
testResult = await KeployTest(config)
//by default command is set to "npm start", incase of custom command update the keployTest as shown above
expect(testResult).toBeTruthy();
test('TestKeploy', (done) => {
const cmd = 'npm start';
const options = {};
keploy.Test(cmd, options, (err, res) => {
if (err) {
done(err);
} else {
expect(res).toBeTruthy(); // Assert the test result
done();
}
});
}, timeOut);
}, timeOut);
```
3. **Test**
Execute
```bash
keploy test -c "npm test" --delay 10
keploy test -c "npm test" --delay 10 --coverage
```

4. **Get Combined coverage**
Execute
```bash
keploy test -c "npm run coverage" --delay 10 --coverage
```

🎉TADA: You've successfully tested end-to-end test cases alongside unit test cases without the need to write additional test files or manage mocks/stubs.
Expand Down
21 changes: 7 additions & 14 deletions keployCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ export enum TestRunStatus {
FAILED = 'FAILED'
}

export class Config {
appCmd: string;

constructor(appCmd: string) {
this.appCmd = appCmd;
}
}
let hasTestRunCompleted = false;

export const setTestRunCompletionStatus = (status: boolean) => {
Expand All @@ -28,9 +21,9 @@ export const setTestRunCompletionStatus = (status: boolean) => {

let userCommandPID: any = 0;

export const KeployTest = async (config: Config = { appCmd: '' }) => {
if (config.appCmd == "") {
config.appCmd = "npm start"
export const Test = async (appCmd: string, options: any, callback: (err: Error | null, result?: boolean) => void) => {
if (appCmd == "") {
appCmd = "npm start"
}
let testResult = true;
const MAX_TIMEOUT = 10000;
Expand All @@ -44,7 +37,7 @@ export const KeployTest = async (config: Config = { appCmd: '' }) => {
console.log("starting user application");
for (let testset of testSets) {
let result = true;
StartUserApplication(config.appCmd)
StartUserApplication(appCmd)
const testRunId = await RunTestSet(testset);
let testRunStatus;
while (true) {
Expand All @@ -71,11 +64,11 @@ export const KeployTest = async (config: Config = { appCmd: '' }) => {
console.log(`TestResult of [${testset}]: ${result}`);
testResult = testResult && result;
StopUserApplication()
setTimeout(() => { }, 5000); // wait for the application to stop
await new Promise(res => setTimeout(res, 5000)); // wait for the application to stop
}
return testResult
callback(null, testResult); // Callback with no error and the test result
} catch (error) {
throw error;
callback(error as Error); // Callback with the error cast to an Error object
}
}

Expand Down
Loading
Loading