-
Notifications
You must be signed in to change notification settings - Fork 20
/
check-npm-package.tests.js
58 lines (50 loc) · 1.89 KB
/
check-npm-package.tests.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
/* eslint-env node, mocha */
import checkNpmPackage from './check-npm-package';
import chai from 'chai';
import logger from './logger';
const expect = chai.expect;
describe('checkNpmPackage', function() {
it('should return false if the package is not installed', function() {
logger.test(function() {
expect(checkNpmPackage('fake-package')).to.be.false;
});
});
it('should output an error if the package is not installed', function(done) {
logger.test(function() {
let receivedErrorMessage = '';
logger.error.addHook(errorMessage => {
try {
receivedErrorMessage += errorMessage + '\n';
return false;
} catch (e) {
done(e);
}
});
checkNpmPackage('[email protected]');
expect(receivedErrorMessage).to.have.string('Error checking npm module: [email protected] (required by nathantreid:css-modules): module not found. Please ensure you have installed the module; here is the command:\n meteor npm install fake-package --save-dev\n');
done();
});
});
it('should return true if an invalid version of the package is installed', function() {
logger.test(function() {
expect(checkNpmPackage('[email protected]')).to.be.true;
});
});
it('should output a warning if an invalid version of the package is installed', function(done) {
logger.test(function() {
logger.warn.addHook(errorMessage => {
try {
expect(errorMessage).to.have.string('WARNING: version mismatch for eslint; installed version is 3.3.1, but version 1.0.0 is required by nathantreid:css-modules)');
done();
return false;
} catch (e) {
done(e);
}
});
checkNpmPackage('[email protected]');
});
});
it('should return true if a matching package version is installed', function() {
expect(checkNpmPackage('eslint@^3.3.1')).to.be.true;
});
});