inspec/docs/resources/npm.md.erb

76 lines
1.5 KiB
Text
Raw Normal View History

2016-09-22 12:43:57 +00:00
---
title: About the npm Resource
---
# npm
Use the `npm` InSpec audit resource to test if a global NPM package is installed. NPM is the the package manager for Node.js packages (https://docs.npmjs.com), such as Bower and StatsD.
## Syntax
2016-09-22 12:43:57 +00:00
A `npm` resource block declares a package and (optionally) a package version:
describe gem('npm_package_name') do
it { should be_installed }
end
where
* `('npm_package_name')` must specify an NPM package, such as `'bower'` or `'statsd'`
* `be_installed` is a valid matcher for this resource
## Matchers
2016-09-22 12:43:57 +00:00
This InSpec audit resource has the following matchers:
### be
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_be" %>
### be_installed
2016-09-22 12:43:57 +00:00
The `be_installed` matcher tests if the named Gem package and package version (if specified) is installed:
it { should be_installed }
### cmp
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_cmp" %>
### eq
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_eq" %>
### include
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_include" %>
### match
2016-09-22 12:43:57 +00:00
<%= partial "/shared/matcher_match" %>
### version
2016-09-22 12:43:57 +00:00
The `version` matcher tests if the named package version is on the system:
its('version') { should eq '1.2.3' }
## Examples
2016-09-22 12:43:57 +00:00
The following examples show how to use this InSpec audit resource.
### Verify that bower is installed, with a specific version
2016-09-22 12:43:57 +00:00
describe npm('bower') do
it { should be_installed }
its('version') { should eq '1.4.1' }
end
### Verify that statsd is not installed
2016-09-22 12:43:57 +00:00
describe npm('statsd') do
it { should_not be_installed }
end