-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
128 lines (108 loc) · 3.57 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
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
require('mocha');
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var generate = require('generate');
var del = require('delete');
var generator = require('./');
var app;
var cwd = path.resolve.bind(path, __dirname, 'actual');
function exists(name, cb) {
var filepath = cwd(name);
return function(err) {
if (err) return cb(err);
fs.stat(filepath, function(err, stat) {
assert(stat);
del(path.dirname(filepath), cb);
});
}
}
describe('generate-eslint', function() {
beforeEach(function() {
app = generate({silent: true});
app.cwd = cwd();
app.option('dest', cwd());
});
describe('plugin', function() {
it('should only register the plugin once', function(cb) {
var count = 0;
app.on('plugin', function(name) {
if (name === 'generate-eslint') {
count++;
}
});
app.use(generator);
app.use(generator);
app.use(generator);
assert.equal(count, 1);
cb();
});
it('should extend tasks onto the instance', function() {
app.use(generator);
assert(app.tasks.hasOwnProperty('default'));
assert(app.tasks.hasOwnProperty('eslintrc'));
assert(app.tasks.hasOwnProperty('ignore'));
});
it('should run the `default` task', function(cb) {
app.use(generator);
app.generate('default', exists('.eslintrc.json', cb));
});
it('should run the `ignore` task', function(cb) {
app.use(generator);
app.generate('ignore', exists('.eslintignore', cb));
});
it('should run the `eslintignore` (alias) task', function(cb) {
app.use(generator);
app.generate('eslintignore', exists('.eslintignore', cb));
});
});
describe('generator', function() {
it('should work as a generator', function(cb) {
app.register('eslint', generator);
app.generate('eslint', exists('.eslintrc.json', cb));
});
it('should run the `default` task', function(cb) {
app.register('eslint', generator);
app.generate('eslint:default', exists('.eslintrc.json', cb));
});
it('should run the `eslint` task', function(cb) {
app.register('eslint', generator);
app.generate('eslint:eslintrc', exists('.eslintrc.json', cb));
});
it('should run the `ignore` task', function(cb) {
app.register('eslint', generator);
app.generate('eslint:ignore', exists('.eslintignore', cb));
});
it('should run the `eslintignore` (alias) task', function(cb) {
app.register('eslint', generator);
app.generate('eslint:eslintignore', exists('.eslintignore', cb));
});
});
describe('sub-generator', function() {
it('should work as a sub-generator', function(cb) {
app.register('foo', function(foo) {
foo.register('eslint', generator);
});
app.generate('foo.eslint', exists('.eslintrc.json', cb));
});
it('should run the `default` task', function(cb) {
app.register('foo', function(foo) {
foo.register('eslint', generator);
});
app.generate('foo.eslint:default', exists('.eslintrc.json', cb));
});
it('should run the `ignore` task', function(cb) {
app.register('foo', function(foo) {
foo.register('eslint', generator);
});
app.generate('foo.eslint:ignore', exists('.eslintignore', cb));
});
it('should run the `eslintignore` (alias) task', function(cb) {
app.register('foo', function(foo) {
foo.register('eslint', generator);
});
app.generate('foo.eslint:eslintignore', exists('.eslintignore', cb));
});
});
});