-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
87 lines (77 loc) · 2.73 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
/* eslint-env mocha */
/* eslint-disable func-names, no-extra-bind */
var R = require('ramda');
var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');
var depsObject = require('deps-object');
var mapPrefixPreset = require('./generators/app/map-babel').mapPrefixPreset;
var mapPrefixPlugin = require('./generators/app/map-babel').mapPrefixPlugin;
var generator = function() {
return helpers.run(path.join(__dirname, './generators/app'));
};
it('creates files', function(done) {
generator().on('end', function() {
assert.file('.babelrc');
done();
});
});
it('uses presets from options.config', function(done) {
var config = { presets: ['es2015', 'stage-0'] };
generator().withOptions({ config: config }).on('end', function() {
assert.jsonFileContent('.babelrc', config);
done();
});
});
it('uses presets from arguments', function(done) {
var presets = ['es2015', 'stage-0'];
generator().withArguments(presets).on('end', function() {
assert.jsonFileContent('.babelrc', { presets: presets });
done();
});
});
it('uses plugins from options.config', function(done) {
var plugins = ['transform-strict-mode', 'transform-object-assign'];
generator().withOptions({ config: { plugins: plugins }}).on('end', function() {
assert.jsonFileContent('.babelrc', { plugins: plugins });
done();
});
});
it('uses plugins from options.plugins', function(done) {
var plugins = ['transform-strict-mode', 'transform-object-assign'];
generator().withOptions({ plugins: ['transform-strict-mode', 'transform-object-assign'] }).on('end', function() {
assert.jsonFileContent('.babelrc', { plugins: plugins });
done();
});
});
it('uses any other option from options.config', function(done) {
var config = { sourceMaps: true };
generator().withOptions({ config: config }).on('end', function() {
assert.jsonFileContent('.babelrc', config);
done();
});
});
it('add presets and plugins with proper prefixes', function(done) {
var presets = ['es2015', 'stage-0'];
var plugins = ['transform-strict-mode', 'transform-object-assign'];
var deps = R.concat(mapPrefixPreset(presets), mapPrefixPlugin(plugins));
depsObject(deps).then(function(devDeps) {
generator()
.withOptions({ config: {
presets: presets,
plugins: plugins,
sourceMaps: true,
}})
.on('end', function() {
assert.jsonFileContent('package.json', { devDependencies: devDeps });
done();
});
});
});
it('not adding es2015 if config.presets are specified', function(done) {
var config = { presets: ['es2016'] };
generator().withOptions({ config: config }).on('end', function() {
assert.noFileContent('.babelrc', /es2015/);
done();
});
});