UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

81 lines (80 loc) 3.32 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 path_1 = require("path"); const framework_detection_1 = require("../../lib/framework-detection"); /** * Create a new server */ const NewCommand = { alias: ['t'], description: 'Creates a new test file', hidden: false, name: 'test', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { // Retrieve the tools we need const { filesystem, helper, parameters, print: { error, info, spin, success }, strings: { camelCase, kebabCase, pascalCase }, system, template, } = toolbox; // Start timer const timer = system.startTimer(); // Info info('Create a new test file'); // Get name const name = yield helper.getInput(parameters.first, { name: 'test name', }); if (!name) { return; } // Set up initial props (to pass into templates) const nameCamel = camelCase(name); const nameKebab = kebabCase(name); const namePascal = pascalCase(name); // Check if directory const cwd = filesystem.cwd(); const path = cwd.substr(0, cwd.lastIndexOf('src')); if (!filesystem.exists((0, path_1.join)(path, 'tests'))) { info(''); error(`No tests directory in "${path}".`); return; } const testsDir = (0, path_1.join)(path, 'tests'); const filePath = (0, path_1.join)(testsDir, `${nameKebab}.e2e-spec.ts`); // Check if file already exists if (filesystem.exists(filePath)) { info(''); error(`There's already a file named "${filePath}"`); return; } const generateSpinner = spin('Generate test file'); // nest-server-tests/tests.e2e-spec.ts.ejs yield template.generate({ props: { frameworkImport: (0, framework_detection_1.getFrameworkImportSpecifier)(path, filePath), nameCamel, nameKebab, namePascal, }, target: filePath, template: 'nest-server-tests/tests.e2e-spec.ts.ejs', }); generateSpinner.succeed('Generate test file'); // We're done, so show what to do next info(''); success(`Generated ${namePascal} test file in ${helper.msToMinutesAndSeconds(timer())}m.`); info(''); if (!toolbox.parameters.options.fromGluegunMenu) { process.exit(); } // For tests return `new test ${name}`; }), }; exports.default = NewCommand;