UNPKG

st-cc

Version:

Stencil create component cli

119 lines 6.79 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const os_1 = __importDefault(require("os")); const index_1 = require("./index"); function buildPath(testDir, componentsPath, componentName, fileName) { return path_1.default.join(testDir, componentsPath, componentName, fileName); } function createTestFileNames({ componentName, TEST_DIR, styleExtension }) { return { componentPath: buildPath(TEST_DIR, index_1.COMPONENTS_PATH, componentName, `${componentName}.tsx`), componentStylePath: buildPath(TEST_DIR, index_1.COMPONENTS_PATH, componentName, `${componentName}.${styleExtension || 'css'}`), componentUnitTestPath: buildPath(TEST_DIR, index_1.COMPONENTS_PATH, componentName, `${componentName}.spec.tsx`), componente2eTestPath: buildPath(TEST_DIR, index_1.COMPONENTS_PATH, componentName, `${componentName}-e2e.tsx`) }; } describe('When running stencil-cli', () => { let TEST_DIR; beforeEach(() => __awaiter(void 0, void 0, void 0, function* () { TEST_DIR = path_1.default.join(os_1.default.tmpdir(), 'stencil-cli', 'integration'); yield fs_extra_1.default.emptyDir(TEST_DIR); })); afterEach(() => __awaiter(void 0, void 0, void 0, function* () { return yield fs_extra_1.default.remove(TEST_DIR); })); it('can create component without style or tests', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-no-css'; yield index_1.create({ componentName, currentDir: TEST_DIR, styleExtension: 'none', createTestFile: false }); const { componentPath, componentStylePath, componentUnitTestPath, componente2eTestPath } = createTestFileNames({ componentName, TEST_DIR }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeFalsy(); expect(yield fs_extra_1.default.pathExists(componentUnitTestPath)).toBeFalsy(); expect(yield fs_extra_1.default.pathExists(componente2eTestPath)).toBeFalsy(); })); it('can create component with style', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-with-css-no-test'; yield index_1.create({ componentName, currentDir: TEST_DIR, styleExtension: 'css', createTestFile: false }); const { componentPath, componentStylePath, componentUnitTestPath } = createTestFileNames({ componentName, TEST_DIR }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeTruthy(); })); it('can create component with scss', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-with-scss'; const styleExtension = 'scss'; yield index_1.create({ componentName, styleExtension, currentDir: TEST_DIR, createTestFile: false }); const { componentPath, componentStylePath, componentUnitTestPath } = createTestFileNames({ componentName, TEST_DIR, styleExtension }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeTruthy(); })); it('can create component with less', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-with-less'; const styleExtension = 'less'; yield index_1.create({ componentName, styleExtension, currentDir: TEST_DIR, createTestFile: false }); const { componentPath, componentStylePath, componentUnitTestPath } = createTestFileNames({ componentName, TEST_DIR, styleExtension }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeTruthy(); })); it('can create component with style and test', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-with-css'; yield index_1.create({ componentName, currentDir: TEST_DIR, styleExtension: 'css', createTestFile: true }); const { componentPath, componentStylePath, componentUnitTestPath, componente2eTestPath } = createTestFileNames({ componentName, TEST_DIR }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentUnitTestPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componente2eTestPath)).toBeTruthy(); })); it('can create shadow component with style and test', () => __awaiter(void 0, void 0, void 0, function* () { const componentName = 'component-css-shadow'; yield index_1.create({ componentName, currentDir: TEST_DIR, styleExtension: 'css', createTestFile: true, styleType: 'shadow' }); const { componentPath, componentStylePath, componentUnitTestPath, componente2eTestPath } = createTestFileNames({ componentName, TEST_DIR }); expect(yield fs_extra_1.default.pathExists(componentPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentStylePath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componentUnitTestPath)).toBeTruthy(); expect(yield fs_extra_1.default.pathExists(componente2eTestPath)).toBeTruthy(); })); }); //# sourceMappingURL=creator.spec.js.map