@pega/custom-dx-components
Version:
Utility for building custom UI components
454 lines (369 loc) • 16.8 kB
JavaScript
// import { exec } from 'child_process';
const path = require('path');
const fs = require('fs');
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const tasksConfigDir = path.resolve('../../..', 'tasks.config.json');
const tasksConfigData = fs.readFileSync(tasksConfigDir, { encoding: 'utf8' });
let tasksConfigJSON = JSON.parse(tasksConfigData);
const packageJSONDir = path.resolve('../../..', 'package.json');
const packageJSONData = fs.readFileSync(packageJSONDir, { encoding: 'utf8'});
let packageJSON = JSON.parse(packageJSONData);
let isLibraryBasedCL = tasksConfigJSON['libraryModeCL'];
const savedLibraryBased = isLibraryBasedCL;
const savedOrganization = packageJSON.organization;
const serverType = tasksConfigJSON['server-config'].serverType;
const serverDir = serverType === 'launchpad' ? 'Launchpad' : 'Constellation';
let compType = isLibraryBasedCL ? "library" : "original";
describe(`createLib createAll list createLibVersion(with copy) switchLibe list deleteLibVersion(all) : ${serverDir} - ${compType}` , () => {
beforeAll( async() => {
// make libraryBased
isLibraryBasedCL = true;
tasksConfigJSON['libraryModeCL'] = isLibraryBasedCL;
compType = isLibraryBasedCL ? "library" : "original";
fs.writeFileSync(tasksConfigDir, JSON.stringify(tasksConfigJSON, null, 4), { encoding: 'utf8' });
const storeDir = path.join(path.resolve('../../..'), 'store');
if (fs.existsSync(storeDir)) {
fs.rmSync(storeDir, { recursive: true, force: true, maxRetries: 2 });
}
// make organzation Pega
packageJSON.organization = "Pega";
fs.writeFileSync(packageJSONDir, JSON.stringify(packageJSON, null, 4), { encoding: 'utf8' });
const componentsDir = path.join(path.resolve('../../..'), 'src/components');
if (fs.existsSync(componentsDir)) {
fs.rmSync(componentsDir, { recursive: true, force: true, maxRetries: 2 });
fs.mkdirSync(componentsDir, { recursive: true });
}
await new Promise((r) => setTimeout(r, 2000));
});
afterAll( async() => {
//restore
isLibraryBasedCL = savedLibraryBased
tasksConfigJSON['libraryModeCL'] = isLibraryBasedCL;
fs.writeFileSync(tasksConfigDir, JSON.stringify(tasksConfigJSON, null, 4), { encoding: 'utf8' });
// return organzation
packageJSON.organization = savedOrganization;
fs.writeFileSync(packageJSONDir, JSON.stringify(packageJSON, null, 4), { encoding: 'utf8' });
const componentsDir = path.join(path.resolve('../../..'), 'src/components');
if (fs.existsSync(componentsDir)) {
fs.rmSync(componentsDir, { recursive: true, force: true, maxRetries: 2 });
fs.mkdirSync(componentsDir, { recursive: true });
}
const storeDir = path.join(path.resolve('../../..'), 'store');
if (fs.existsSync(storeDir)) {
fs.rmSync(storeDir, { recursive: true, force: true, maxRetries: 2 });
}
await new Promise((r) => setTimeout(r, 2000));
});
it(`npm run createLib - ${isLibraryBasedCL}`, async() => {
const script = `npm run createLib DXIL 0.0.1 N Original --prefix ../../..`;
const compConf = path.join("store", "Pega_DXIL","0.0.1", "componentsconfig.json");
const { stdout, stderr } = await exec(script);
expect(stdout).toContain('Library Pega_DXIL/0.0.1 has been created!');
const doesExist = fs.existsSync(path.resolve('../../..', compConf));
expect(doesExist).toBeTruthy();
}, 30000);
it('npm run createAll', async () => {
const script = `npm run createAll "My" 0.0.1 DXIL Pega Jest --prefix ../../..`;
const { stdout, stderr } = await exec(script);
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stderr).not.toBeNull();
// want message to contain component name
expect(stdout).toContain('created Pega_DXIL_My');
// don't want message with already exists
expect(stdout).not.toContain('already exists');
// check to see file exists
// pick one
const newFileName = 'Pega_DXIL_MyBoolean';
// const fileDir = path.resolve(`src/components/${newFileName}`);
const createFile = path.resolve(
'../../..',
path.join(`src/components/${newFileName}`, 'index.tsx')
);
const doesExist = fs.existsSync(createFile);
expect(doesExist).toBeTruthy();
// if (doesExist) {
// // remove it
// fs.rmdirSync(fileDir, { recursive: true });
// }
}, 90000);
it('npm run list', async () => {
const script = 'npm run list --prefix ../../..';
const { stdout, stderr } = await exec(script);
expect(stderr).not.toBeNull();
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stdout).toContain('Pega_DXIL_MyText');
expect(stdout).toContain('Pega_DXIL_MyTextInput');
expect(stdout).toContain('Pega_DXIL_MyParagraph');
expect(stdout).toContain('Pega_DXIL_MyEmail');
expect(stdout).toContain('Pega_DXIL_MyPhone');
expect(stdout).toContain('Pega_DXIL_MyURL');
expect(stdout).toContain('Pega_DXIL_MyInteger');
expect(stdout).toContain('Pega_DXIL_MyDecimal');
expect(stdout).toContain('Pega_DXIL_MyCurrency');
expect(stdout).toContain('Pega_DXIL_MyPercentage');
expect(stdout).toContain('Pega_DXIL_MyBoolean');
expect(stdout).toContain('Pega_DXIL_MyDate');
expect(stdout).toContain('Pega_DXIL_MyDateTime');
expect(stdout).toContain('Pega_DXIL_MyTimeOfDay');
expect(stdout).toContain('Pega_DXIL_MyPicklist');
expect(stdout).toContain('Pega_DXIL_MySearchbox');
expect(stdout).toContain('Pega_DXIL_MyRadiobuttons');
expect(stdout).toContain('Pega_DXIL_MyDetails');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnDetails');
expect(stdout).toContain('Pega_DXIL_MyForm');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnForm');
expect(stdout).toContain('Pega_DXIL_MyPage');
expect(stdout).toContain('Pega_DXIL_MyCaseWidget');
expect(stdout).toContain('Pega_DXIL_MyPageWidget');
expect(stdout).toContain('Pega_DXIL_MyPageCaseWidget');
// done();
}, 10000);
it('compare created to default', async () => {
const compList = [
'Pega_DXIL_MyText',
'Pega_DXIL_MyTextInput',
'Pega_DXIL_MyParagraph',
'Pega_DXIL_MyEmail',
'Pega_DXIL_MyPhone',
'Pega_DXIL_MyURL',
'Pega_DXIL_MyInteger',
'Pega_DXIL_MyDecimal',
'Pega_DXIL_MyCurrency',
'Pega_DXIL_MyPercentage',
'Pega_DXIL_MyBoolean',
'Pega_DXIL_MyDate',
'Pega_DXIL_MyDateTime',
'Pega_DXIL_MyTimeOfDay',
'Pega_DXIL_MyPicklist',
'Pega_DXIL_MySearchbox',
'Pega_DXIL_MyRadiobuttons',
'Pega_DXIL_MyDetails',
'Pega_DXIL_MyTwoColumnDetails',
'Pega_DXIL_MyForm',
'Pega_DXIL_MyTwoColumnForm',
'Pega_DXIL_MyPage',
'Pega_DXIL_MyCaseWidget',
'Pega_DXIL_MyPageWidget',
'Pega_DXIL_MyPageCaseWidget'
];
compList.forEach(component => {
const componentDir = path.resolve('../../..', `src/components/${component}`);
const assetDir = path.resolve(`tests/assets/${compType}/components/createAll/${serverDir}/${component}`);
// get files of directory
const componentFiles = fs.readdirSync(componentDir);
// get files of assets
// const assetFiles = fs.readdirSync(assetDir);
// compare
componentFiles.forEach(file => {
const componentFilePath = path.join(componentDir, file);
const assetFilePath = path.join(assetDir, file);
let componentFileData = fs.readFileSync(componentFilePath, { encoding: 'utf8' });
let assetFileData = fs.readFileSync(assetFilePath, { encoding: 'utf8' });
// so that we don't have to generate all new assets, change "version"
// from 0.0.1 to 0.0.1 for now
if (file === "config.json") {
expect(componentFileData).toContain("0.0.1");
// componentFileData = componentFileData.replace("0.0.1", "0.0.1");
// normalize
componentFileData = JSON.stringify(JSON.parse(componentFileData));
assetFileData = JSON.stringify(JSON.parse(assetFileData));
}
expect(componentFileData).toEqual(assetFileData);
});
});
}, 10000);
it(`npm run createLibVersion and copy - ${isLibraryBasedCL}`, async() => {
const script = `npm run createLibVersion 0.0.2 N Y NoAbout --prefix ../../..`;
const { stdout, stderr } = await exec(script);
expect(stdout).toContain('Library Pega_DXIL/0.0.1 has been stored.');
expect(stdout).toContain('Library Pega_DXIL/0.0.2 has been created!');
}, 30000);
it('npm run list of new version', async () => {
const script = 'npm run list --prefix ../../..';
const { stdout, stderr } = await exec(script);
expect(stderr).not.toBeNull();
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stdout).toContain('Pega_DXIL_MyText');
expect(stdout).toContain('Pega_DXIL_MyTextInput');
expect(stdout).toContain('Pega_DXIL_MyParagraph');
expect(stdout).toContain('Pega_DXIL_MyEmail');
expect(stdout).toContain('Pega_DXIL_MyPhone');
expect(stdout).toContain('Pega_DXIL_MyURL');
expect(stdout).toContain('Pega_DXIL_MyInteger');
expect(stdout).toContain('Pega_DXIL_MyDecimal');
expect(stdout).toContain('Pega_DXIL_MyCurrency');
expect(stdout).toContain('Pega_DXIL_MyPercentage');
expect(stdout).toContain('Pega_DXIL_MyBoolean');
expect(stdout).toContain('Pega_DXIL_MyDate');
expect(stdout).toContain('Pega_DXIL_MyDateTime');
expect(stdout).toContain('Pega_DXIL_MyTimeOfDay');
expect(stdout).toContain('Pega_DXIL_MyPicklist');
expect(stdout).toContain('Pega_DXIL_MySearchbox');
expect(stdout).toContain('Pega_DXIL_MyRadiobuttons');
expect(stdout).toContain('Pega_DXIL_MyDetails');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnDetails');
expect(stdout).toContain('Pega_DXIL_MyForm');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnForm');
expect(stdout).toContain('Pega_DXIL_MyPage');
expect(stdout).toContain('Pega_DXIL_MyCaseWidget');
expect(stdout).toContain('Pega_DXIL_MyPageWidget');
expect(stdout).toContain('Pega_DXIL_MyPageCaseWidget');
// done();
}, 10000);
it('compare created to default', async () => {
const compList = [
'Pega_DXIL_MyText',
'Pega_DXIL_MyTextInput',
'Pega_DXIL_MyParagraph',
'Pega_DXIL_MyEmail',
'Pega_DXIL_MyPhone',
'Pega_DXIL_MyURL',
'Pega_DXIL_MyInteger',
'Pega_DXIL_MyDecimal',
'Pega_DXIL_MyCurrency',
'Pega_DXIL_MyPercentage',
'Pega_DXIL_MyBoolean',
'Pega_DXIL_MyDate',
'Pega_DXIL_MyDateTime',
'Pega_DXIL_MyTimeOfDay',
'Pega_DXIL_MyPicklist',
'Pega_DXIL_MySearchbox',
'Pega_DXIL_MyRadiobuttons',
'Pega_DXIL_MyDetails',
'Pega_DXIL_MyTwoColumnDetails',
'Pega_DXIL_MyForm',
'Pega_DXIL_MyTwoColumnForm',
'Pega_DXIL_MyPage',
'Pega_DXIL_MyCaseWidget',
'Pega_DXIL_MyPageWidget',
'Pega_DXIL_MyPageCaseWidget'
];
compList.forEach(component => {
const componentDir = path.resolve('../../..', `src/components/${component}`);
const assetDir = path.resolve(`tests/assets/${compType}/components/createAll/${serverDir}/${component}`);
// get files of directory
const componentFiles = fs.readdirSync(componentDir);
// get files of assets
// const assetFiles = fs.readdirSync(assetDir);
// compare
componentFiles.forEach(file => {
const componentFilePath = path.join(componentDir, file);
const assetFilePath = path.join(assetDir, file);
let componentFileData = fs.readFileSync(componentFilePath, { encoding: 'utf8' });
let assetFileData = fs.readFileSync(assetFilePath, { encoding: 'utf8' });
// so that we don't have to generate all new assets, change "version"
// from 0.0.2 to 0.0.1 for now
if (file === "config.json") {
expect(componentFileData).toContain("0.0.2");
componentFileData = componentFileData.replace("0.0.2", "0.0.1");
// normalize
componentFileData = JSON.stringify(JSON.parse(componentFileData));
assetFileData = JSON.stringify(JSON.parse(assetFileData));
}
expect(componentFileData).toEqual(assetFileData);
});
});
}, 10000);
it(`npm run switchLibVersion - ${isLibraryBasedCL}`, async() => {
// we are at version 0.0.2, switch to 0.0.1
const script = `npm run switchLibVersion Y 0.0.1 NoAbout --prefix ../../..`;
const { stdout, stderr } = await exec(script);
expect(stdout).toContain('Switched to Pega_DXIL/0.0.1!');
}, 30000);
it('npm run list of original version', async () => {
const script = 'npm run list --prefix ../../..';
const { stdout, stderr } = await exec(script);
expect(stderr).not.toBeNull();
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stdout).toContain('Pega_DXIL_MyText');
expect(stdout).toContain('Pega_DXIL_MyTextInput');
expect(stdout).toContain('Pega_DXIL_MyParagraph');
expect(stdout).toContain('Pega_DXIL_MyEmail');
expect(stdout).toContain('Pega_DXIL_MyPhone');
expect(stdout).toContain('Pega_DXIL_MyURL');
expect(stdout).toContain('Pega_DXIL_MyInteger');
expect(stdout).toContain('Pega_DXIL_MyDecimal');
expect(stdout).toContain('Pega_DXIL_MyCurrency');
expect(stdout).toContain('Pega_DXIL_MyPercentage');
expect(stdout).toContain('Pega_DXIL_MyBoolean');
expect(stdout).toContain('Pega_DXIL_MyDate');
expect(stdout).toContain('Pega_DXIL_MyDateTime');
expect(stdout).toContain('Pega_DXIL_MyTimeOfDay');
expect(stdout).toContain('Pega_DXIL_MyPicklist');
expect(stdout).toContain('Pega_DXIL_MySearchbox');
expect(stdout).toContain('Pega_DXIL_MyRadiobuttons');
expect(stdout).toContain('Pega_DXIL_MyDetails');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnDetails');
expect(stdout).toContain('Pega_DXIL_MyForm');
expect(stdout).toContain('Pega_DXIL_MyTwoColumnForm');
expect(stdout).toContain('Pega_DXIL_MyPage');
expect(stdout).toContain('Pega_DXIL_MyCaseWidget');
expect(stdout).toContain('Pega_DXIL_MyPageWidget');
expect(stdout).toContain('Pega_DXIL_MyPageCaseWidget');
// done();
}, 10000);
it('compare created to default', async () => {
const compList = [
'Pega_DXIL_MyText',
'Pega_DXIL_MyTextInput',
'Pega_DXIL_MyParagraph',
'Pega_DXIL_MyEmail',
'Pega_DXIL_MyPhone',
'Pega_DXIL_MyURL',
'Pega_DXIL_MyInteger',
'Pega_DXIL_MyDecimal',
'Pega_DXIL_MyCurrency',
'Pega_DXIL_MyPercentage',
'Pega_DXIL_MyBoolean',
'Pega_DXIL_MyDate',
'Pega_DXIL_MyDateTime',
'Pega_DXIL_MyTimeOfDay',
'Pega_DXIL_MyPicklist',
'Pega_DXIL_MySearchbox',
'Pega_DXIL_MyRadiobuttons',
'Pega_DXIL_MyDetails',
'Pega_DXIL_MyTwoColumnDetails',
'Pega_DXIL_MyForm',
'Pega_DXIL_MyTwoColumnForm',
'Pega_DXIL_MyPage',
'Pega_DXIL_MyCaseWidget',
'Pega_DXIL_MyPageWidget',
'Pega_DXIL_MyPageCaseWidget'
];
compList.forEach(component => {
const componentDir = path.resolve('../../..', `src/components/${component}`);
const assetDir = path.resolve(`tests/assets/${compType}/components/createAll/${serverDir}/${component}`);
// get files of directory
const componentFiles = fs.readdirSync(componentDir);
// get files of assets
// const assetFiles = fs.readdirSync(assetDir);
// compare
componentFiles.forEach(file => {
const componentFilePath = path.join(componentDir, file);
const assetFilePath = path.join(assetDir, file);
let componentFileData = fs.readFileSync(componentFilePath, { encoding: 'utf8' });
let assetFileData = fs.readFileSync(assetFilePath, { encoding: 'utf8' });
// so that we don't have to generate all new assets, change "version"
// from 0.0.1 to 0.0.1 for now
if (file === "config.json") {
expect(componentFileData).toContain("0.0.1");
// componentFileData = componentFileData.replace("0.0.1", "0.0.1");
// normalize
componentFileData = JSON.stringify(JSON.parse(componentFileData));
assetFileData = JSON.stringify(JSON.parse(assetFileData));
}
expect(componentFileData).toEqual(assetFileData);
});
});
}, 10000);
it(`npm run deleteLibVersion ALL - ${isLibraryBasedCL}`, async() => {
const script = `npm run deleteLibVersion Pega_DXIL ALL Y --prefix ../../..`;
const { stdout, stderr } = await exec(script);
expect(stdout).toContain('Pega_DXIL is deleted from Local.');
}, 30000);
});