This repository has been archived by the owner on Aug 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
160 lines (126 loc) · 4.13 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import path from 'path';
import fs from 'fs';
import tempWrite from 'temp-write';
import {get} from 'dot-prop';
import test from 'ava';
import m from './';
function run(pkg) {
const filepath = tempWrite.sync(JSON.stringify(pkg), 'package.json');
return m({
cwd: path.dirname(filepath),
skipInstall: true
}).then(() => JSON.parse(fs.readFileSync(filepath, 'utf8')));
}
test('empty package.json', async t => {
const pkg = await run({});
t.deepEqual(pkg.ava, {
require: ['babel-register'],
babel: {
presets: ['es2015-node4', 'stage-2'],
plugins: [['transform-react-jsx', {pragma: 'h'}]]
}
});
});
test('has existing babel-register', async t => {
const pkg = await run({
ava: {
babel: {
require: ['babel-register']
}
}
});
t.deepEqual(get(pkg, 'ava.babel.require'), ['babel-register']);
});
test('has existing jsx plugin', async t => {
const pkg = await run({
ava: {
babel: {
plugins: [['transform-react-jsx']]
}
}
});
t.deepEqual(get(pkg, 'ava.babel.plugins.0'), ['transform-react-jsx', {pragma: 'h'}]);
});
test('has existing es2015-node4 preset', async t => {
const pkg = await run({
ava: {
babel: {
presets: ['es2015-node4']
}
}
});
t.deepEqual(get(pkg, 'ava.babel.presets'), ['es2015-node4', 'stage-2']);
});
test('has existing es2015 preset', async t => {
const pkg = await run({
ava: {
babel: {
presets: ['es2015']
}
}
});
t.deepEqual(get(pkg, 'ava.babel.presets'), ['es2015', 'stage-2']);
});
test('has existing stage-2 preset', async t => {
const pkg = await run({
ava: {
babel: {
presets: ['stage-2']
}
}
});
t.deepEqual(get(pkg, 'ava.babel.presets'), ['stage-2', 'es2015-node4']);
});
const isNode4 = process.version[1] === '4';
if (!isNode4) {
test.serial('installs all dependencies', async t => {
const filepath = tempWrite.sync(JSON.stringify({}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.truthy(get(pkg, 'devDependencies.babel-register'));
t.truthy(get(pkg, 'devDependencies.babel-plugin-transform-react-jsx'));
t.truthy(get(pkg, 'devDependencies.babel-preset-es2015-node4'));
t.truthy(get(pkg, 'devDependencies.babel-preset-stage-2'));
});
test.serial('skip babel-register dependency', async t => {
const filepath = tempWrite.sync(JSON.stringify({
devDependencies: {'babel-register': '*'}
}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.is(get(pkg, 'devDependencies.babel-register'), '*');
});
test.serial('skip babel-plugin-transform-react-jsx dependency', async t => {
const filepath = tempWrite.sync(JSON.stringify({
devDependencies: {'babel-plugin-transform-react-jsx': '*'}
}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.is(get(pkg, 'devDependencies.babel-plugin-transform-react-jsx'), '*');
});
test.serial('skip babel-preset-es2015-node4 dependency', async t => {
const filepath = tempWrite.sync(JSON.stringify({
devDependencies: {'babel-preset-es2015-node4': '*'}
}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.is(get(pkg, 'devDependencies.babel-preset-es2015-node4'), '*');
});
test.serial('skip babel-preset-es2015-node4 dependency if es2015 preset is installed', async t => {
const filepath = tempWrite.sync(JSON.stringify({
devDependencies: {'babel-preset-es2015': '*'}
}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.falsy(get(pkg, 'devDependencies.babel-preset-es2015-node4'));
t.is(get(pkg, 'devDependencies.babel-preset-es2015'), '*');
});
test.serial('skip babel-preset-stage-2 dependency', async t => {
const filepath = tempWrite.sync(JSON.stringify({
devDependencies: {'babel-preset-stage-2': '*'}
}), 'package.json');
await m({cwd: path.dirname(filepath)});
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
t.is(get(pkg, 'devDependencies.babel-preset-stage-2'), '*');
});
}