UNPKG

@line/create-liff-app

Version:

Start developing LIFF application with a simple CLI command.

76 lines (75 loc) 2.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const execa_1 = __importDefault(require("execa")); const cliPath = path_1.default.join(__dirname, '../dist/index.js'); const templatePath = path_1.default.join(__dirname, '../templates/vanilla'); const projectName = 'test-app'; const projectPath = path_1.default.join(__dirname, projectName); const ENTER = '\x0D'; // Increase timeout jest.setTimeout(1000 * 60 * (process.env.RUNNER_OS === 'macOS' ? 10 : 5)); const rename = { '.gitignore.default': '.gitignore' }; const generatedFiles = [ '.env', 'node_modules', 'yarn.lock' ]; function removeProject() { fs_1.default.rmSync(projectPath, { recursive: true, force: true }); } function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function installProject({ args = [], inputs = [] }) { const result = (0, execa_1.default)('node', [cliPath, ...args], { cwd: __dirname }); result.stdout?.on('data', chunk => process.stdout.write(chunk.toString('utf8'))); for (const input of inputs) { result.stdin?.write(input); await timeout(500); } result.stdin?.end(); await result; const files = fs_1.default.existsSync(projectPath) ? fs_1.default.readdirSync(projectPath) : []; return { exitCode: result.exitCode, files }; } beforeEach(() => { removeProject(); }); afterEach(async () => { removeProject(); }); const commands = { vanilla: [projectName, ENTER, ENTER, ENTER, ENTER, ENTER], }; const flags = { vanilla: [projectName, '-t', 'vanilla', '-l', 'id', '--js', '--use-yarn'], }; describe('create-liff-app', () => { it('files properly created', async () => { const result = await installProject({ inputs: commands.vanilla }); const templateFiles = fs_1.default.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); const expectedFiles = templateFiles.concat(generatedFiles); expect(result.files.sort()).toEqual(expectedFiles.sort()); expect(result.exitCode).toBe(0); }); it('creates app using only flags', async () => { const result = await installProject({ args: flags.vanilla }); const templateFiles = fs_1.default.readdirSync(templatePath).map(f => rename[f] ? rename[f] : f); const expectedFiles = templateFiles.concat(generatedFiles); expect(result.files.sort()).toEqual(expectedFiles.sort()); expect(result.exitCode).toBe(0); }); });