diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index 635cfb3f..0a4e3c5b 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -45,7 +45,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { "style" => { let engines_version = get_engines_version(context); let in_engines_range = - check_engines_version(nodejs_version.deref().as_ref()?, engines_version); + check_engines_version(nodejs_version.as_deref(), engines_version); if in_engines_range { Some(Ok(config.style)) } else { @@ -92,11 +92,12 @@ fn get_engines_version(context: &Context) -> Option { Some(raw_version.to_string()) } -fn check_engines_version(nodejs_version: &str, engines_version: Option) -> bool { - if engines_version.is_none() { - return true; - } - let r = match VersionReq::parse(&engines_version.unwrap()) { +fn check_engines_version(nodejs_version: Option<&str>, engines_version: Option) -> bool { + let (nodejs_version, engines_version) = match (nodejs_version, engines_version) { + (Some(nv), Some(ev)) => (nv, ev), + _ => return true, + }; + let r = match VersionReq::parse(&engines_version) { Ok(r) => r, Err(_e) => return true, }; @@ -270,4 +271,16 @@ mod tests { assert_eq!(expected, actual); dir.close() } + #[test] + fn no_node_installed() -> io::Result<()> { + let dir = tempfile::tempdir()?; + File::create(dir.path().join("index.js"))?.sync_all()?; + let actual = ModuleRenderer::new("nodejs") + .path(dir.path()) + .cmd("node --version", None) + .collect(); + let expected = Some(format!("via {}", Color::Green.bold().paint(" "))); + assert_eq!(expected, actual); + dir.close() + } }