Skip to content

Commit 5fdf7a2

Browse files
committed
also add some smoke tests, and update from node v12
1 parent 71f5ccf commit 5fdf7a2

File tree

7 files changed

+122
-55
lines changed

7 files changed

+122
-55
lines changed

tests/smoke/autodownload.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@ use test_support::matchers::execs;
77
static PACKAGE_JSON_WITH_PINNED_NODE: &str = r#"{
88
"name": "test-package",
99
"volta": {
10-
"node": "12.13.0"
10+
"node": "14.15.5"
1111
}
1212
}"#;
1313

1414
static PACKAGE_JSON_WITH_PINNED_NODE_NPM: &str = r#"{
1515
"name": "test-package",
1616
"volta": {
17-
"node": "13.0.1",
18-
"npm": "6.13.4"
17+
"node": "17.3.0",
18+
"npm": "8.5.1"
1919
}
2020
}"#;
2121

22-
static PACKAGE_JSON_WITH_PINNED_NODE_YARN: &str = r#"{
22+
static PACKAGE_JSON_WITH_PINNED_NODE_YARN_1: &str = r#"{
2323
"name": "test-package",
2424
"volta": {
25-
"node": "12.10.0",
26-
"yarn": "1.22.0"
25+
"node": "16.11.1",
26+
"yarn": "1.22.16"
27+
}
28+
}"#;
29+
30+
static PACKAGE_JSON_WITH_PINNED_NODE_YARN_3: &str = r#"{
31+
"name": "test-package",
32+
"volta": {
33+
"node": "16.14.0",
34+
"yarn": "3.1.0"
2735
}
2836
}"#;
2937

@@ -35,7 +43,7 @@ fn autodownload_node() {
3543

3644
assert_that!(
3745
p.node("--version"),
38-
execs().with_status(0).with_stdout_contains("v12.13.0")
46+
execs().with_status(0).with_stdout_contains("v14.15.5")
3947
);
4048
}
4149

@@ -47,18 +55,31 @@ fn autodownload_npm() {
4755

4856
assert_that!(
4957
p.npm("--version"),
50-
execs().with_status(0).with_stdout_contains("6.13.4")
58+
execs().with_status(0).with_stdout_contains("8.5.1")
59+
);
60+
}
61+
62+
#[test]
63+
fn autodownload_yarn_1() {
64+
let p = temp_project()
65+
.package_json(PACKAGE_JSON_WITH_PINNED_NODE_YARN_1)
66+
.build();
67+
68+
assert_that!(
69+
p.yarn("--version"),
70+
execs().with_status(0).with_stdout_contains("1.22.16")
5171
);
5272
}
5373

5474
#[test]
55-
fn autodownload_yarn() {
75+
fn autodownload_yarn_3() {
5676
let p = temp_project()
57-
.package_json(PACKAGE_JSON_WITH_PINNED_NODE_YARN)
77+
.package_json(PACKAGE_JSON_WITH_PINNED_NODE_YARN_3)
78+
.env("VOLTA_FEATURE_YARN_3", "true")
5879
.build();
5980

6081
assert_that!(
6182
p.yarn("--version"),
62-
execs().with_status(0).with_stdout_contains("1.22.0")
83+
execs().with_status(0).with_stdout_contains("3.1.0")
6384
);
6485
}

tests/smoke/npm_link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn link_global_into_current_project() {
4949
let p = temp_project().package_json(PACKAGE_JSON).build();
5050

5151
assert_that!(
52-
p.volta("install node@12.19.1 [email protected]"),
52+
p.volta("install node@14.19.0 [email protected]"),
5353
execs().with_status(0)
5454
);
5555

tests/smoke/package_migration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LEGACY_PACKAGE_CONFIG: &str = r#"{
99
"version": "1.1.7",
1010
"platform": {
1111
"node": {
12-
"runtime": "12.18.3",
12+
"runtime": "14.18.2",
1313
"npm": null
1414
},
1515
"yarn": null
@@ -27,7 +27,7 @@ const LEGACY_BIN_CONFIG: &str = r#"{
2727
"path": "./cli.js",
2828
"platform": {
2929
"node": {
30-
"runtime": "12.18.3",
30+
"runtime": "14.18.2",
3131
"npm": null
3232
},
3333
"yarn": null

tests/smoke/support/temp_project.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ impl FileBuilder {
4040
}
4141
}
4242

43+
pub struct EnvVar {
44+
name: String,
45+
value: String,
46+
}
47+
48+
impl EnvVar {
49+
pub fn new(name: &str, value: &str) -> Self {
50+
EnvVar {
51+
name: name.to_string(),
52+
value: value.to_string(),
53+
}
54+
}
55+
}
56+
4357
#[must_use]
4458
pub struct TempProjectBuilder {
4559
root: TempProject,
@@ -57,6 +71,7 @@ impl TempProjectBuilder {
5771
root: TempProject {
5872
root: root.clone(),
5973
path: OsString::new(),
74+
env_vars: vec![],
6075
},
6176
files: vec![],
6277
}
@@ -83,6 +98,12 @@ impl TempProjectBuilder {
8398
self
8499
}
85100

101+
/// Set an environment variable (chainable)
102+
pub fn env(mut self, name: &str, value: &str) -> Self {
103+
self.root.env_vars.push(EnvVar::new(name, value));
104+
self
105+
}
106+
86107
/// Create the project
87108
pub fn build(mut self) -> TempProject {
88109
// First, clean the temporary project directory if it already exists
@@ -248,6 +269,7 @@ fn package_distro_file_name(name: &str, version: &str) -> String {
248269
pub struct TempProject {
249270
root: PathBuf,
250271
path: OsString,
272+
env_vars: Vec<EnvVar>,
251273
}
252274

253275
impl TempProject {
@@ -273,6 +295,11 @@ impl TempProject {
273295
.env_remove("VOLTA_NODE_VERSION")
274296
.env_remove("MSYSTEM"); // assume cmd.exe everywhere on windows
275297

298+
// overrides for env vars
299+
for env_var in &self.env_vars {
300+
p.env(&env_var.name, &env_var.value);
301+
}
302+
276303
p
277304
}
278305

tests/smoke/volta_fetch.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,34 @@ use test_support::matchers::execs;
88
fn fetch_node() {
99
let p = temp_project().build();
1010

11-
assert_that!(p.volta("fetch node@12.16.0"), execs().with_status(0));
12-
assert!(p.node_version_is_fetched("12.16.0"));
13-
assert!(p.node_version_is_unpacked("12.16.0"));
11+
assert_that!(p.volta("fetch node@14.17.6"), execs().with_status(0));
12+
assert!(p.node_version_is_fetched("14.17.6"));
13+
assert!(p.node_version_is_unpacked("14.17.6"));
1414
}
1515

1616
#[test]
17-
fn fetch_yarn() {
17+
fn fetch_yarn_1() {
1818
let p = temp_project().build();
1919

2020
assert_that!(p.volta("fetch [email protected]"), execs().with_status(0));
2121
assert!(p.yarn_version_is_fetched("1.22.1"));
2222
assert!(p.yarn_version_is_unpacked("1.22.1"));
2323
}
2424

25+
#[test]
26+
fn fetch_yarn_3() {
27+
let p = temp_project().env("VOLTA_FEATURE_YARN_3", "yes").build();
28+
29+
assert_that!(p.volta("fetch [email protected]"), execs().with_status(0));
30+
assert!(p.yarn_version_is_fetched("3.2.0"));
31+
assert!(p.yarn_version_is_unpacked("3.2.0"));
32+
}
33+
2534
#[test]
2635
fn fetch_npm() {
2736
let p = temp_project().build();
2837

29-
assert_that!(p.volta("fetch npm@6.14.2"), execs().with_status(0));
30-
assert!(p.npm_version_is_fetched("6.14.2"));
31-
assert!(p.npm_version_is_unpacked("6.14.2"));
38+
assert_that!(p.volta("fetch npm@8.3.1"), execs().with_status(0));
39+
assert!(p.npm_version_is_fetched("8.3.1"));
40+
assert!(p.npm_version_is_unpacked("8.3.1"));
3241
}

tests/smoke/volta_install.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use test_support::matchers::execs;
99
fn install_node() {
1010
let p = temp_project().build();
1111

12-
assert_that!(p.volta("install node@12.16.2"), execs().with_status(0));
12+
assert_that!(p.volta("install node@14.15.4"), execs().with_status(0));
1313

1414
assert_that!(
1515
p.node("--version"),
16-
execs().with_status(0).with_stdout_contains("v12.16.2")
16+
execs().with_status(0).with_stdout_contains("v14.15.4")
1717
);
1818

19-
assert!(p.node_version_is_fetched("12.16.2"));
20-
assert!(p.node_version_is_unpacked("12.16.2"));
21-
p.assert_node_version_is_installed("12.16.2");
19+
assert!(p.node_version_is_fetched("14.15.4"));
20+
assert!(p.node_version_is_unpacked("14.15.4"));
21+
p.assert_node_version_is_installed("14.15.4");
2222
}
2323

2424
#[test]
@@ -34,15 +34,15 @@ fn install_node_lts() {
3434
fn install_node_concurrent() {
3535
let p = temp_project().build();
3636

37-
let install = p.volta("install node@12.14.0");
37+
let install = p.volta("install node@14.17.2");
3838
let run = p.node("--version");
3939

4040
let concurrent_thread = thread::spawn(move || {
4141
assert_that!(install, execs().with_status(0));
4242
assert_that!(run, execs().with_status(0));
4343
});
4444

45-
assert_that!(p.volta("install node@12.14.0"), execs().with_status(0));
45+
assert_that!(p.volta("install node@14.17.2"), execs().with_status(0));
4646
assert_that!(p.node("--version"), execs().with_status(0));
4747

4848
assert!(concurrent_thread.join().is_ok());
@@ -52,7 +52,7 @@ fn install_node_concurrent() {
5252
fn install_yarn() {
5353
let p = temp_project().build();
5454

55-
assert_that!(p.volta("install node@12.16.3"), execs().with_status(0));
55+
assert_that!(p.volta("install node@14.15.2"), execs().with_status(0));
5656
assert_that!(p.volta("install [email protected]"), execs().with_status(0));
5757

5858
assert_that!(
@@ -69,7 +69,7 @@ fn install_yarn() {
6969
fn install_old_yarn() {
7070
let p = temp_project().build();
7171

72-
assert_that!(p.volta("install node@10.21.0"), execs().with_status(0));
72+
assert_that!(p.volta("install node@14.11.0"), execs().with_status(0));
7373
// Yarn 1.9.2 is old enough that it is no longer on the first page of results from the GitHub API
7474
assert_that!(p.volta("install [email protected]"), execs().with_status(0));
7575

@@ -87,7 +87,7 @@ fn install_old_yarn() {
8787
fn install_yarn_concurrent() {
8888
let p = temp_project().build();
8989

90-
assert_that!(p.volta("install node@12.14.0"), execs().with_status(0));
90+
assert_that!(p.volta("install node@14.19.0"), execs().with_status(0));
9191

9292
let install = p.volta("install [email protected]");
9393
let run = p.yarn("--version");
@@ -107,30 +107,30 @@ fn install_yarn_concurrent() {
107107
fn install_npm() {
108108
let p = temp_project().build();
109109

110-
// node 13.10.0 is bundled with npm 6.13.7
111-
assert_that!(p.volta("install node@13.10.0"), execs().with_status(0));
110+
// node 17.6.0 is bundled with npm 8.5.1
111+
assert_that!(p.volta("install node@17.6.0"), execs().with_status(0));
112112
assert_that!(
113113
p.npm("--version"),
114-
execs().with_status(0).with_stdout_contains("6.13.7")
114+
execs().with_status(0).with_stdout_contains("8.5.1")
115115
);
116116

117117
// install npm 6.8.0 and verify that is installed correctly
118-
assert_that!(p.volta("install npm@6.14.3"), execs().with_status(0));
119-
assert!(p.npm_version_is_fetched("6.14.3"));
120-
assert!(p.npm_version_is_unpacked("6.14.3"));
121-
p.assert_npm_version_is_installed("6.14.3");
118+
assert_that!(p.volta("install npm@8.5.5"), execs().with_status(0));
119+
assert!(p.npm_version_is_fetched("8.5.5"));
120+
assert!(p.npm_version_is_unpacked("8.5.5"));
121+
p.assert_npm_version_is_installed("8.5.5");
122122

123123
assert_that!(
124124
p.npm("--version"),
125-
execs().with_status(0).with_stdout_contains("6.14.3")
125+
execs().with_status(0).with_stdout_contains("8.5.5")
126126
);
127127
}
128128

129129
#[test]
130130
fn install_npm_concurrent() {
131131
let p = temp_project().build();
132132

133-
assert_that!(p.volta("install node@12.14.0"), execs().with_status(0));
133+
assert_that!(p.volta("install node@14.5.0"), execs().with_status(0));
134134

135135
let install = p.volta("install [email protected]");
136136
let run = p.npm("--version");
@@ -160,7 +160,7 @@ fn install_package() {
160160
let p = temp_project().build();
161161

162162
// have to install node first, because we need npm
163-
assert_that!(p.volta("install node@12.11.1"), execs().with_status(0));
163+
assert_that!(p.volta("install node@14.11.0"), execs().with_status(0));
164164

165165
assert_that!(p.volta("install [email protected]"), execs().with_status(0));
166166
assert!(p.shim_exists("cowsay"));
@@ -176,7 +176,7 @@ fn install_package() {
176176
fn install_package_concurrent() {
177177
let p = temp_project().build();
178178

179-
assert_that!(p.volta("install node@12.14.0"), execs().with_status(0));
179+
assert_that!(p.volta("install node@14.14.0"), execs().with_status(0));
180180

181181
let install = p.volta("install [email protected]");
182182
let run = p.exec_shim("cowsay", "hello");
@@ -197,7 +197,7 @@ fn install_scoped_package() {
197197
let p = temp_project().build();
198198

199199
// have to install node first, because we need npm
200-
assert_that!(p.volta("install node@12.14.1"), execs().with_status(0));
200+
assert_that!(p.volta("install node@14.15.0"), execs().with_status(0));
201201

202202
assert_that!(p.volta("install @wdio/[email protected]"), execs().with_status(0));
203203
assert!(p.shim_exists("wdio"));
@@ -214,7 +214,7 @@ fn install_package_tag_version() {
214214
let p = temp_project().build();
215215

216216
// have to install node first, because we need npm
217-
assert_that!(p.volta("install node@12.12.0"), execs().with_status(0));
217+
assert_that!(p.volta("install node@14.8.0"), execs().with_status(0));
218218

219219
assert_that!(p.volta("install [email protected]"), execs().with_status(0));
220220
assert!(p.shim_exists("elm"));

0 commit comments

Comments
 (0)