UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

242 lines (170 loc) 8.23 kB
// 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 isLibraryBased = tasksConfigJSON['libraryMode']; const savedLibraryBased = isLibraryBased; const savedOrganization = packageJSON.organization; const serverType = tasksConfigJSON['server-config'].serverType; const serverDir = serverType === 'launchpad' ? 'Launchpad' : 'Constellation'; let compType = isLibraryBased ? "library" : "original"; describe(`createLib create buildLib deleteLib deletePublishedLib: ${serverDir} - ${compType}` , () => { beforeAll( async() => { // make libraryBased isLibraryBased = true; tasksConfigJSON['libraryMode'] = isLibraryBased; compType = isLibraryBased ? "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 isLibraryBased = savedLibraryBased tasksConfigJSON['libraryMode'] = isLibraryBased; 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('initial delete/cleanup', async () => { // const storePath = join(path.resolve('../../..'), 'store'); // if (fs.existsSync(storePath)) { // fs.rmSync(storePath, { recursive: true, force: true, maxRetries: 2 }); // } // }); it(`npm run createLib - ${isLibraryBased}`, async() => { const script = `npm run createLib DXIL 0.0.1 N Original --prefix ../../..`; const compConf = path.join("store", "Pega_DXIL","0.0.1-dev", "componentsconfig.json"); const { stdout, stderr } = await exec(script); expect(stdout).toContain('Library Pega_DXIL/0.0.1-dev has been created!'); const doesExist = fs.existsSync(path.resolve('../../..', compConf)); expect(doesExist).toBeTruthy(); }, 30000); 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 buildLib (internal) - ${isLibraryBased}`, async() => { const script = `npm run _internal-buildLibrary 0.0.1 Y --prefix ../../..`; const { stdout, stderr } = await exec(script); expect(stdout).toContain('Pega_DXIL_MyTestText schema is valid'); expect(stdout).toContain('Pega_DXIL_MyTestPage schema is valid'); expect(stdout).toContain('Pega_DXIL_MyTestDetails schema is valid'); expect(stdout).toContain('Building Library...'); // expect(stdout).toContain('Compile check...'); expect(stdout).toContain('Webpacked library Pega_DXIL:0.0.1-dev successfully!!'); expect(stdout).toContain('== Creating manifest for the library version - completed =='); }, 200000); it(`npm run deleteLib - ${isLibraryBased}`, async() => { const script = `npm run deleteLib Pega_DXIL 0.0.1-dev Y --prefix ../../..`; const { stdout, stderr } = await exec(script); expect(stdout).toContain('Pega_DXIL is deleted from Local.'); }, 30000); it(`npm run deletePublishedLib - ${isLibraryBased}`, async() => { const script = `npm run deletePublishedLib Local ALL --prefix ../../..`; const { stdout, stderr } = await exec(script); expect(stdout).toContain('Library: Pega_DXIL is deleted from Local'); const localLib = path.resolve('../../..', `Pega_DXIL`); expect(fs.existsSync(localLib)).not.toBeTruthy(); }, 30000); });