@pega/custom-dx-components
Version:
Utility for building custom UI components
220 lines (161 loc) • 7.3 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(`create buildAll deleteAll local: ${serverDir} - ${compType}`, () => {
beforeAll( async() => {
// make non libraryBased
isLibraryBasedCL = false;
tasksConfigJSON['libraryModeCL'] = isLibraryBasedCL;
// delete if exists
delete tasksConfigJSON['libraryMode'];
compType = isLibraryBasedCL ? "library" : "original";
fs.writeFileSync(tasksConfigDir, JSON.stringify(tasksConfigJSON, null, 4), { encoding: 'utf8' });
// 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 });
}
await new Promise((r) => setTimeout(r, 2000));
});
it('npm run create Local text', async () => {
const fileName = 'MyTestText';
const newFileName = `Pega_DXIL_${fileName}`;
const script = `npm run create Field Text ${fileName} "My Test Text" 0.0.1 DXIL "My Test Text Description" Pega --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(newFileName);
// don't want message with already exists
expect(stdout).not.toContain('already exists');
// check to see file exists
// 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 });
// }
}, 10000);
it('npm run create Local page', async () => {
const fileName = 'MyTestPage';
const newFileName = `Pega_DXIL_${fileName}`;
const script = `npm run create Widget PAGE ${fileName} "My Test Page" 0.0.1 DXIL "My Test Page Description" Pega --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(newFileName);
// don't want message with already exists
expect(stdout).not.toContain('already exists');
// check to see file exists
// 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 });
// }
}, 10000);
it('npm run create Local details', async () => {
const fileName = 'MyTestDetails';
const newFileName = `Pega_DXIL_${fileName}`;
const script = `npm run create Template DETAILS ${fileName} "My Test Details" 0.0.1 DXIL "My Test Details Description" Pega --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(newFileName);
// don't want message with already exists
expect(stdout).not.toContain('already exists');
// check to see file exists
// 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 });
// }
}, 10000);
it('npm run buildAllComponents', async () => {
const script = `npm run buildAllComponents N --prefix ../../..`;
const { stdout, stderr } = await exec(script);
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stderr).not.toBeNull();
// expect(stdout).toContain('Compiled successfully.');
// expect(stdout).not.toContain('Compiled with warnings.');
expect(stdout).not.toContain('error');
expect(stdout).not.toContain('Error');
expect(stdout).toContain('Pega_DXIL_MyTestText');
expect(stdout).toContain('Pega_DXIL_MyTestPage');
expect(stdout).toContain('Pega_DXIL_MyTestDetails');
// done();
}, 70000);
it('npm run deleteAll Local', async () => {
const script = `npm run deleteAll Local Y --prefix ../../..`;
const { stdout, stderr } = await exec(script);
// console.log(stdout);
expect(stdout).not.toBeNull();
expect(stderr).not.toBeNull();
// pick one
const newFileName = 'Pega_DXIL_MyTestText';
// want message to contain component name
expect(stdout).toContain(newFileName);
// message deleted
expect(stdout).toContain('is deleted');
// check to see file exists
// I think run through a map of them here
// 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).not.toBeTruthy();
}, 20000);
});