From 8783ac76b6b2c9f432a9cf41d23f03f90e34dce3 Mon Sep 17 00:00:00 2001 From: Agnes Lin Date: Wed, 10 Jul 2019 11:55:56 -0400 Subject: [PATCH] fix(cli): fix how app generates default project name. relevant test added --- packages/cli/lib/project-generator.js | 4 ++- .../integration/generators/app.integration.js | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/cli/lib/project-generator.js b/packages/cli/lib/project-generator.js index deacd86d5c62..87ba9c167baa 100644 --- a/packages/cli/lib/project-generator.js +++ b/packages/cli/lib/project-generator.js @@ -7,6 +7,7 @@ const BaseGenerator = require('./base-generator'); const utils = require('./utils'); const chalk = require('chalk'); +const path = require('path'); module.exports = class ProjectGenerator extends BaseGenerator { // Note: arguments and options should be defined in the constructor. @@ -131,7 +132,8 @@ module.exports = class ProjectGenerator extends BaseGenerator { name: 'name', message: 'Project name:', when: this.projectInfo.name == null, - default: this.options.name || this.appname, + default: + this.options.name || utils.toFileName(path.basename(process.cwd())), validate: utils.validate, }, { diff --git a/packages/cli/test/integration/generators/app.integration.js b/packages/cli/test/integration/generators/app.integration.js index c4f1e6bd24e8..23317681afe6 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -212,6 +212,41 @@ describe('app-generator with tilde rpoject path', () => { }); }); +/** For testing if the generator handles default values properly */ +describe('app-generator with default values', () => { + const rootDir = path.join(__dirname, '../../../..'); + const defaultValProjPath = path.join(rootDir, 'sandbox/default-value-app'); + const sandbox = path.join(rootDir, 'sandbox'); + const pathToDefValApp = path.join(defaultValProjPath, 'default-value-app'); + const defaultValProps = { + name: '', + description: 'An app to test out tilde project path', + outdir: '', + }; + + before(async () => { + // default-value-app should not exist at this point + assert.equal(fs.existsSync(defaultValProjPath), false); + assert.equal(fs.existsSync(pathToDefValApp), false); + return ( + helpers + .run(generator) + .inDir(defaultValProjPath) + // Mark it private to prevent accidental npm publication + .withOptions({private: true}) + .withPrompts(defaultValProps) + ); + }); + it('scaffold a new app for default-value-app', async () => { + // default-value-app should be created at this point + assert.equal(fs.existsSync(pathToDefValApp), true); + }); + after(() => { + process.chdir(sandbox); + build.clean(['node', 'run-clean', defaultValProjPath]); + }); +}); + // The test takes about 1 min to install dependencies function testFormat() { before(function() {