Skip to content

Commit

Permalink
fix(cli): fix how app generates default project name. relevant test a…
Browse files Browse the repository at this point in the history
…dded
  • Loading branch information
Agnes Lin committed Jul 10, 2019
1 parent 461d306 commit cf231c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/cli/lib/project-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
},
{
Expand Down
37 changes: 36 additions & 1 deletion packages/cli/test/integration/generators/app.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit cf231c8

Please sign in to comment.