e2e test environment fortwenty-cli (#15123)
# Introduction Defining very first basis of the twenty-cli e2e testing env. Dynamically generating tests cases based on a list of applications names that will be matched to stored twenty-apps and run install delete and reinstall with their configuration on the same instance We could use a glob pattern with a specific e2e configuration in every apps but right now overkill ## Notes - We should define typescript path aliasing to ease import devxp - parse the config using a zod object ## Some vision on test granularity Right now we only check that the server sent back success or failure on below operation. In the future the synchronize will return a report of what has been installed per entity exactly. We will be able to snapshot everything in order to detect regressions We should also be testing the cli directly for init and other stuff in the end, we could get some inspiration from what's done in preconstruct e2e tests with an on heap virtual file system ## Conclusion Any suggestions are more than welcomed ! close https://github.com/twentyhq/core-team-issues/issues/1721
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
import { existsSync } from 'fs';
|
||||
import { AppDeleteCommand } from '../../commands/app-delete.command';
|
||||
import { AppSyncCommand } from '../../commands/app-sync.command';
|
||||
import { COVERED_APPLICATION_FOLDERS } from './constants/covered-applications-folder.constant';
|
||||
import { getTestedApplicationPath } from './utils/get-tested-application-path.util';
|
||||
|
||||
describe.each(COVERED_APPLICATION_FOLDERS)(
|
||||
'Application: "%s" install delete and reinstall test suite',
|
||||
(applicationName) => {
|
||||
const syncCommand = new AppSyncCommand();
|
||||
const deleteCommand = new AppDeleteCommand();
|
||||
const appPath = getTestedApplicationPath(applicationName);
|
||||
|
||||
beforeAll(async () => {
|
||||
expect(existsSync(appPath)).toBe(true);
|
||||
});
|
||||
|
||||
// TODO uncomment when reinstall is fix to cleanup gracefully
|
||||
// afterAll(async () => {
|
||||
// const result = await deleteCommand.execute({
|
||||
// appPath,
|
||||
// askForConfirmation: false,
|
||||
// });
|
||||
|
||||
// expect(result.success).toBe(true);
|
||||
// });
|
||||
|
||||
it(`should successfully install ${applicationName} application`, async () => {
|
||||
const result = await syncCommand.execute(appPath);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it(`should successfully delete ${applicationName} application`, async () => {
|
||||
const result = await deleteCommand.execute({
|
||||
appPath,
|
||||
askForConfirmation: false,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
});
|
||||
|
||||
it.failing(
|
||||
`should successfully re-install ${applicationName} application`,
|
||||
async () => {
|
||||
const result = await syncCommand.execute(appPath);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
+1
@@ -0,0 +1 @@
|
||||
export const COVERED_APPLICATION_FOLDERS = ['hello-world'] as const;
|
||||
@@ -0,0 +1 @@
|
||||
export const SERVER_URL = 'http://localhost:3000';
|
||||
@@ -0,0 +1,21 @@
|
||||
import axios from 'axios';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { SERVER_URL } from './constants/server-url.constant';
|
||||
|
||||
describe('Twenty Server Health Check (E2E)', () => {
|
||||
const configService = new ConfigService();
|
||||
const HEALTH_ENDPOINT = `${SERVER_URL}/healthz`;
|
||||
|
||||
it('should assert e2e configuration is loaded by default', async () => {
|
||||
const configuration = await configService.getConfig();
|
||||
expect(configuration).toMatchObject({
|
||||
defaultApp: 'e2e-default-app',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 200 for health', async () => {
|
||||
const response = await axios.get(HEALTH_ENDPOINT);
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.data).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { exec } from 'child_process';
|
||||
|
||||
export default async function globalTeardown() {
|
||||
return new Promise<void>((resolve) => {
|
||||
exec('pkill -f "nest start" || true', (error: unknown) => {
|
||||
if (error) {
|
||||
console.log('No server processes to kill');
|
||||
} else {
|
||||
console.log('✅ Server processes cleaned up');
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import path from 'path';
|
||||
|
||||
export const getTestedApplicationPath = (relativePath: string): string => {
|
||||
const currentFileDir = __dirname;
|
||||
|
||||
const twentyAppsPath = path.resolve(
|
||||
currentFileDir,
|
||||
'../../../../../twenty-apps',
|
||||
);
|
||||
|
||||
return path.join(twentyAppsPath, relativePath);
|
||||
};
|
||||
Reference in New Issue
Block a user