-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
115 lines (97 loc) · 3.01 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import path from 'path';
import test from 'ava';
import helpers from 'yeoman-test';
import assert from 'yeoman-assert';
import pify from 'pify';
import utils from './app/utils';
let generator;
test.beforeEach(async () => {
await pify(helpers.testDirectory)(path.join(__dirname, 'temp'));
generator = helpers.createGenerator('ink-cli:app', ['../app'], null, {skipInstall: true});
});
test.serial('generates expected files', async () => {
helpers.mockPrompt(generator, {
moduleName: 'test',
githubUsername: 'test',
website: 'test.com'
});
await pify(generator.run.bind(generator))();
assert.file([
'.editorconfig',
'.git',
'.gitattributes',
'.gitignore',
'.travis.yml',
'cli.js',
'license',
'package.json',
'readme.md',
'test.js',
'ui.js',
'.npmrc'
]);
});
test.serial('nyc option', async () => {
helpers.mockPrompt(generator, {
moduleName: 'test',
githubUsername: 'test',
website: 'test.com',
nyc: true,
codecov: false
});
await pify(generator.run.bind(generator))();
assert.fileContent('.gitignore', /\.nyc_output/);
assert.fileContent('.gitignore', /coverage/);
assert.fileContent('package.json', /"xo && nyc ava"/);
assert.fileContent('package.json', /"nyc": "/);
assert.noFileContent('package.json', /"codecov":/);
assert.noFileContent('package.json', /"lcov"/);
assert.noFileContent('.travis.yml', /codecov/);
});
test.serial('codecov option', async () => {
helpers.mockPrompt(generator, {
moduleName: 'test',
githubUsername: 'test',
website: 'test.com',
nyc: true,
codecov: true
});
await pify(generator.run.bind(generator))();
assert.fileContent('.gitignore', /\.nyc_output/);
assert.fileContent('.gitignore', /coverage/);
assert.fileContent('package.json', /"xo && nyc ava"/);
assert.fileContent('package.json', /"nyc": "/);
assert.fileContent('package.json', /"codecov":/);
assert.fileContent('package.json', /"lcov"/);
assert.fileContent('.travis.yml', /codecov/);
});
test('parse scoped package names', t => {
t.is(utils.slugifyPackageName('author/thing'), 'author-thing', 'slugify non-scoped packages');
t.is(utils.slugifyPackageName('@author/thing'), '@author/thing', 'accept scoped packages');
t.is(utils.slugifyPackageName('@author/hi/there'), 'author-hi-there', 'fall back to regular slugify if invalid scoped name');
});
test.serial('prompts for description', async () => {
helpers.mockPrompt(generator, {
moduleName: 'test',
moduleDescription: 'foo',
githubUsername: 'test',
website: 'test.com',
nyc: true,
codecov: true
});
await pify(generator.run.bind(generator))();
assert.fileContent('package.json', /"description": "foo",/);
assert.fileContent('readme.md', /> foo/);
});
test.serial('defaults to superb description', async () => {
helpers.mockPrompt(generator, {
moduleName: 'test',
githubUsername: 'test',
website: 'test.com',
nyc: true,
codecov: true
});
await pify(generator.run.bind(generator))();
assert.fileContent('package.json', /"description": "My .+ module",/);
assert.fileContent('readme.md', /> My .+ module/);
});