From cf231c8e4c7f5e9367263562ef38a586df4d2356 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 | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) 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..fba30b0f89d8 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -168,7 +168,7 @@ describe('app-generator with --applicationName', () => { }); /** For testing the support of tilde path as the input of project path */ -describe('app-generator with tilde rpoject path', () => { +describe('app-generator with tilde project path', () => { const rootDir = path.join(__dirname, '../../../..'); const projPath = path.join(rootDir, 'sandbox/tilde-path-app'); @@ -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() {