UNPKG

@cuba-platform/front-generator

Version:
106 lines 8.63 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const assert = require("assert"); const init_1 = require("../../../init"); const path = require("path"); const util_1 = require("util"); const fs = require("fs"); const test_commons_1 = require("../../test-commons"); const rimraf = (0, util_1.promisify)(require('rimraf')); // let's test both absolute and relative path usage const absoluteModelPath = require.resolve('../../fixtures/mpg-projectModel.json'); const modelPathScr = require.resolve('../../fixtures/project-model--scr.json'); const componentRelativeModelPath = './src/test/fixtures/mpg-projectModel.json'; const answers = require('../../fixtures/answers.json'); const stringIdAnswers = require('../../fixtures/answers/string-id-management-table.json'); const hooksEMTable = require('../../fixtures/answers/hooks-management-table.json'); const hooksEMCards = require('../../fixtures/answers/hooks-management-cards.json'); const hooksEMList = require('../../fixtures/answers/hooks-management-list.json'); const REACT_DIR = path.join(process.cwd(), `src/test/generated/react-client`); const COMPONENT_DIR = path.join(REACT_DIR, 'src/app/component'); const CARDS_DIR = path.join(REACT_DIR, 'src/app/entity-cards'); const EM_DIR = path.join(REACT_DIR, 'src/app/entity-management'); const FIXTURES_DIR = path.join(process.cwd(), `src/test/fixtures/react-client`); const TEST_RUN_DIR = path.join(__dirname, '../../../../'); // run each generator test from the same directory - we need it to test relative cli paths beforeEach(() => process.chdir(TEST_RUN_DIR)); describe('react generator test', () => { it('should generates React client app', function () { return __awaiter(this, void 0, void 0, function* () { yield rimraf(`${REACT_DIR}/*`); yield (0, init_1.generate)('react-typescript', 'app', (0, test_commons_1.opts)(REACT_DIR, null, 'src/test/fixtures/mpg-projectModel.json')); assert.ok(fs.existsSync(`entities/base`)); assert.ok(fs.existsSync(`enums/enums.ts`)); (0, test_commons_1.assertFilesPlain)('src/index.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('.env.development.local', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('.env.production.local', REACT_DIR, FIXTURES_DIR); }); }); it('should generate React client blank-component', function () { return __awaiter(this, void 0, void 0, function* () { yield rimraf(`${COMPONENT_DIR}/*`); yield (0, init_1.generate)('react-typescript', 'blank-component', (0, test_commons_1.opts)(COMPONENT_DIR, answers.blankComponent, componentRelativeModelPath)); (0, test_commons_1.assertFilesPlain)('src/app/component/BlankComponent.tsx', REACT_DIR, FIXTURES_DIR); yield rimraf(`${COMPONENT_DIR}/*`); yield (0, init_1.generate)('react-typescript', 'blank-component', (0, test_commons_1.opts)(COMPONENT_DIR, answers.blankComponentLowCase, absoluteModelPath)); (0, test_commons_1.assertFilesPlain)('src/app/component/BlankComponent.tsx', REACT_DIR, FIXTURES_DIR); }); }); it('should generate React client entity-cards', function () { return __awaiter(this, void 0, void 0, function* () { yield rimraf(`${CARDS_DIR}/*`); yield (0, init_1.generate)('react-typescript', 'entity-cards', (0, test_commons_1.opts)(CARDS_DIR, answers.entityCards, componentRelativeModelPath)); (0, test_commons_1.assertFilesPlain)('src/app/entity-cards/MpgFavoriteCarCards.tsx', REACT_DIR, FIXTURES_DIR); }); }); it('should generate React client entity-management', function () { return __awaiter(this, void 0, void 0, function* () { yield rimraf(`${EM_DIR}/*`); yield (0, init_1.generate)('react-typescript', 'entity-management', (0, test_commons_1.opts)(EM_DIR, answers.entityManagement, componentRelativeModelPath)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management', (0, test_commons_1.opts)(EM_DIR, answers.entityManagement2, absoluteModelPath)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management', (0, test_commons_1.opts)(EM_DIR, answers.entityManagement3, componentRelativeModelPath)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management', (0, test_commons_1.opts)(EM_DIR, answers.entityManagementLowCase, absoluteModelPath)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management', (0, test_commons_1.opts)(EM_DIR, stringIdAnswers, modelPathScr)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management-hooks', (0, test_commons_1.opts)(EM_DIR, hooksEMCards, modelPathScr)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management-hooks', (0, test_commons_1.opts)(EM_DIR, hooksEMList, modelPathScr)); process.chdir(TEST_RUN_DIR); yield (0, init_1.generate)('react-typescript', 'entity-management-hooks', (0, test_commons_1.opts)(EM_DIR, hooksEMTable, modelPathScr)); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarCards.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarEdit.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarList.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarTable.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarManagement.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarManagementLowCase.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarEditLowCase.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/CarTableLowCase.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/StringIdMgtTableManagement.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/StringIdMgtTableEdit.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/StringIdMgtTableBrowse.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMCardsEdit.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMCardsBrowse.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMCardsMgt.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMListEdit.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMListBrowse.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMListMgt.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMTableEdit.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMTableBrowse.tsx', REACT_DIR, FIXTURES_DIR); (0, test_commons_1.assertFilesPlain)('src/app/entity-management/HooksEMTableMgt.tsx', REACT_DIR, FIXTURES_DIR); }); }); }); //# sourceMappingURL=react-generator.test.js.map