/
autoinstall.js
49 lines (39 loc) 路 1.63 KB
/
autoinstall.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
const assert = require('assert');
const install = require('../src/utils/installPackage');
const fs = require('../src/utils/fs');
const {ncp, rimraf} = require('./utils');
const inputDirPath = __dirname + '/input';
describe('autoinstall', function() {
beforeEach(async function() {
// Setup (clear the input dir and move integration test in)
await rimraf(inputDirPath, {});
await ncp(__dirname + '/integration/babel-default', inputDirPath);
});
it('should install lodash using npm and save dev dependency to package.json', async function() {
let pkgName = 'lodash';
await install([pkgName], inputDirPath + '/test.js', {
saveDev: true,
packageManager: 'npm'
});
let expectedModulePath = inputDirPath + '/node_modules/' + pkgName;
assert(await fs.exists(expectedModulePath), 'lodash is in node_modules');
let pkg = await fs.readFile(inputDirPath + '/package.json');
pkg = JSON.parse(pkg);
assert(pkg.devDependencies[pkgName], 'lodash is saved as a dev dep');
});
it('should install lodash using yarn and save dev dependency to package.json', async function() {
let pkgName = 'lodash';
await install([pkgName], inputDirPath + '/test.js', {
saveDev: true,
packageManager: 'yarn'
});
let expectedModulePath = inputDirPath + '/node_modules/' + pkgName;
assert(await fs.exists(expectedModulePath), 'lodash is in node_modules');
let pkg = await fs.readFile(inputDirPath + '/package.json');
pkg = JSON.parse(pkg);
assert(pkg.devDependencies[pkgName], 'lodash is saved as a dev dep');
});
afterEach(async function() {
await rimraf(inputDirPath);
});
});