fix(tests): Refactored test setup for consistency and isolated config initialization.
This commit is contained in:
@ -5,37 +5,39 @@ import * as cloudly from '../../ts/index.js';
|
||||
|
||||
const stopFunctions: Array<() => Promise<void>> = [];
|
||||
|
||||
const tapToolsNodeMod = await import('@push.rocks/tapbundle/node');
|
||||
const smartmongo = await tapToolsNodeMod.tapNodeTools.createSmartmongo();
|
||||
stopFunctions.push(async () => {
|
||||
await smartmongo.stopAndDumpToDir('./.nogit/mongodump');
|
||||
});
|
||||
const smarts3 = await tapToolsNodeMod.tapNodeTools.createSmarts3();
|
||||
await smarts3.createBucket('cloudly-test');
|
||||
stopFunctions.push(async () => {
|
||||
await smarts3.stop();
|
||||
});
|
||||
|
||||
export const testCloudlyConfig: cloudly.ICloudlyConfig = {
|
||||
cfToken: await testQenv.getEnvVarOnDemand('CF_TOKEN'),
|
||||
environment: 'integration',
|
||||
letsEncryptEmail: 'test@serve.zone',
|
||||
publicUrl: '127.0.0.1',
|
||||
publicPort: '8080',
|
||||
mongoDescriptor: await smartmongo.getMongoDescriptor(),
|
||||
s3Descriptor: await smarts3.getS3Descriptor(),
|
||||
sslMode: 'none',
|
||||
...(() => {
|
||||
if (process.env.NPMCI_SECRET01) {
|
||||
return {
|
||||
hetznerToken: process.env.NPMCI_SECRET01,
|
||||
};
|
||||
}
|
||||
})(),
|
||||
};
|
||||
|
||||
export const createCloudly = async () => {
|
||||
const tapToolsNodeMod = await import('@push.rocks/tapbundle/node');
|
||||
const smartmongo = await tapToolsNodeMod.tapNodeTools.createSmartmongo();
|
||||
stopFunctions.push(async () => {
|
||||
await smartmongo.stopAndDumpToDir('./.nogit/mongodump');
|
||||
});
|
||||
const smarts3 = await tapToolsNodeMod.tapNodeTools.createSmarts3();
|
||||
await smarts3.createBucket('cloudly-test');
|
||||
stopFunctions.push(async () => {
|
||||
await smarts3.stop();
|
||||
});
|
||||
const cloudlyConfig: cloudly.ICloudlyConfig = {
|
||||
cfToken: await testQenv.getEnvVarOnDemand('CF_TOKEN'),
|
||||
environment: 'integration',
|
||||
letsEncryptEmail: 'test@serve.zone',
|
||||
publicUrl: 'localhost',
|
||||
publicPort: '8080',
|
||||
mongoDescriptor: await smartmongo.getMongoDescriptor(),
|
||||
s3Descriptor: await smarts3.getS3Descriptor(),
|
||||
sslMode: 'none',
|
||||
...(() => {
|
||||
if (process.env.NPMCI_SECRET01) {
|
||||
return {
|
||||
hetznerToken: process.env.NPMCI_SECRET01
|
||||
}
|
||||
}
|
||||
})()
|
||||
};
|
||||
const cloudlyInstance = new cloudly.Cloudly(cloudlyConfig);
|
||||
const cloudlyInstance = new cloudly.Cloudly(testCloudlyConfig);
|
||||
return cloudlyInstance;
|
||||
}
|
||||
};
|
||||
|
||||
export const stopCloudly = async () => {
|
||||
await Promise.all(stopFunctions.map((stopFunction) => stopFunction()));
|
||||
@ -43,5 +45,4 @@ export const stopCloudly = async () => {
|
||||
|
||||
export const getEnvVarOnDemand = async (envVarName: string) => {
|
||||
return testQenv.getEnvVarOnDemand(envVarName);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -33,7 +33,7 @@ tap.preTask('should create a new machine user for testing', async () => {
|
||||
tap.test('should create a new cloudlyApiClient', async () => {
|
||||
testClient = new cloudlyApiClient.CloudlyApiClient({
|
||||
registerAs: 'api',
|
||||
cloudlyUrl: `http://localhost:${await helpers.getEnvVarOnDemand('SERVEZONE_PORT')}`,
|
||||
cloudlyUrl: `http://localhost:${helpers.testCloudlyConfig.publicPort}`,
|
||||
});
|
||||
await testClient.start();
|
||||
expect(testClient).toBeTruthy();
|
||||
|
Reference in New Issue
Block a user