Skip to content

Commit e14cac5

Browse files
committed
✅ test: Add test for normal operation
1 parent e0b8bec commit e14cac5

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

__tests__/normal.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const path = require('path');
2+
const assert = require('yeoman-assert');
3+
const helpers = require('yeoman-test');
4+
5+
describe('normal', () => {
6+
beforeAll(() => {
7+
return helpers
8+
.run(path.join(__dirname, '../app'))
9+
.withPrompts({
10+
packageName: `${process.cwd().replace(/(?:.*\/)(.+)/i, '$1')}`,
11+
description: 'Yet another generator to disrupt the world',
12+
homepage: 'https://github.com/awesome-next',
13+
repoUrl: '[email protected]:cashblack/awesome-next.git',
14+
authorName: 'Cash Black',
15+
authorEmail: '[email protected]',
16+
authorUrl: 'cash-black.com',
17+
gitName: 'cashblack',
18+
thisYear: new Date().getFullYear(),
19+
});
20+
});
21+
22+
it('creates files', () => {
23+
assert.file([
24+
'.editorconfig',
25+
'.gitattributes',
26+
'.gitignore',
27+
'.npmrc',
28+
29+
'LICENSE',
30+
'README.md',
31+
32+
'package.json',
33+
'tsconfig.json',
34+
'tsconfig.prod.json',
35+
'tslint.json',
36+
'tslint.prod.json',
37+
38+
'src/index.ts',
39+
]);
40+
});
41+
42+
});

app/index.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,35 @@ const ghUser = require('gh-user');
55

66
module.exports = class extends Generator {
77
initializing() {
8-
this.user.github.username().then(console.log).catch((e) => {
9-
console.log('haha', e);
10-
return [];
11-
});
12-
13-
const ghTask = this.user.github.username()
14-
.then(un => Promise.all([un, ghUser(un)]))
15-
.then(([un, info]) => {
16-
return [un, info.html_url];
17-
})
18-
.catch(() => []);
19-
20-
return ghTask.then(([ username, homepage ]) => {
21-
console.log(this.user.git.email());
8+
try {
9+
const ghTask = this.user.github.username()
10+
.then(un => Promise.all([un, ghUser(un)]))
11+
.then(([un, info]) => {
12+
return [un, info.html_url];
13+
})
14+
.catch(() => []);
2215

16+
return ghTask.then(([ username, homepage ]) => {
17+
this.user.info = {
18+
name: this.user.git.name(),
19+
email: this.user.git.email(),
20+
username,
21+
homepage,
22+
};
23+
});
24+
} catch (_) {
2325
this.user.info = {
24-
name: this.user.git.name(),
25-
email: this.user.git.email(),
26-
username,
27-
homepage,
26+
name: this.user.git.name() || '',
27+
email: this.user.git.email() || '',
28+
username: '',
29+
homepage: '',
2830
};
29-
});
31+
}
3032
}
3133

3234
prompting() {
33-
// Have Yeoman greet the user.
3435
this.log(yosay(`Welcome to the stunning ${chalk.red('generator-node-tsnext')}!`));
3536

36-
console.log(this.user.info);
37-
3837
const fallbackDescription =
3938
'Simple Node.js module to output greeting message, written in TypeScript';
4039
const prompts = [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"devDependencies": {
3636
"jest": "^24.8.0",
3737
"shx": "^0.3.2",
38-
"yeoman-assert": "^3.1.0",
38+
"yeoman-assert": "^3.1.1",
3939
"yeoman-test": "^2.0.0"
4040
},
4141
"engines": {

0 commit comments

Comments
 (0)