Browse Source

add test for default alias for system node (#858)

* Add a test that verifies that the system Node.js version can be aliased as default

* Remove unnecessary dependencies
remotes/origin/clean-multishell-on-shell-exit
Gal Schlezinger 2 years ago committed by GitHub
parent
commit
6ee5022c66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 179
      Cargo.lock
  2. 3
      Cargo.toml
  3. 2
      e2e/shellcode/script.ts
  4. 3
      e2e/shellcode/test-tmp-dir.ts
  5. 42
      e2e/system-node.test.ts

179
Cargo.lock generated

@ -297,19 +297,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "console"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
]
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.1.5" version = "0.1.5"
@ -479,19 +466,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "dashmap"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if",
"hashbrown",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]] [[package]]
name = "diff" name = "diff"
version = "0.1.13" version = "0.1.13"
@ -560,12 +534,6 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.31" version = "0.8.31"
@ -645,7 +613,6 @@ dependencies = [
"encoding_rs_io", "encoding_rs_io",
"env_logger", "env_logger",
"indoc", "indoc",
"insta",
"junction", "junction",
"log", "log",
"pretty_assertions", "pretty_assertions",
@ -653,8 +620,6 @@ dependencies = [
"semver", "semver",
"serde", "serde",
"serde_json", "serde_json",
"serial_test",
"shell-escape",
"sysinfo", "sysinfo",
"tar", "tar",
"tempfile", "tempfile",
@ -680,21 +645,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "futures"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-channel" name = "futures-channel"
version = "0.3.24" version = "0.3.24"
@ -702,7 +652,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-sink",
] ]
[[package]] [[package]]
@ -711,17 +660,6 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
[[package]]
name = "futures-executor"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.24" version = "0.3.24"
@ -746,10 +684,8 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
dependencies = [ dependencies = [
"futures-channel",
"futures-core", "futures-core",
"futures-io", "futures-io",
"futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
"pin-project-lite", "pin-project-lite",
@ -954,19 +890,6 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3" checksum = "adab1eaa3408fb7f0c777a73e7465fd5656136fc93b670eb6df3c88c2c1344e3"
[[package]]
name = "insta"
version = "1.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba1e75aa1530e7385af7b2685478dece08dafb9db3b4225c753286decea83bef"
dependencies = [
"console",
"lazy_static",
"linked-hash-map",
"similar",
"yaml-rust",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"
@ -1043,22 +966,6 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.17" version = "0.4.17"
@ -1211,29 +1118,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
]
[[package]] [[package]]
name = "password-hash" name = "password-hash"
version = "0.4.2" version = "0.4.2"
@ -1626,32 +1510,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serial_test"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92761393ee4dc3ff8f4af487bd58f4307c9329bbedea02cac0089ad9c411e153"
dependencies = [
"dashmap",
"futures",
"lazy_static",
"log",
"parking_lot",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b6f5d1c3087fb119617cff2966fe3808a80e5eb59a8c1601d5994d66f4346a5"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "sha1" name = "sha1"
version = "0.10.5" version = "0.10.5"
@ -1684,18 +1542,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "shell-escape"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
[[package]]
name = "similar"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62ac7f900db32bf3fd12e0117dd3dc4da74bc52ebaac97f39668446d89694803"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.7" version = "0.4.7"
@ -1705,12 +1551,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.4.7" version = "0.4.7"
@ -1799,16 +1639,6 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "test-log" name = "test-log"
version = "0.2.11" version = "0.2.11"
@ -2267,15 +2097,6 @@ dependencies = [
"lzma-sys", "lzma-sys",
] ]
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]] [[package]]
name = "yansi" name = "yansi"
version = "0.5.1" version = "0.5.1"

3
Cargo.toml

@ -35,9 +35,6 @@ anyhow = "1.0.66"
[dev-dependencies] [dev-dependencies]
pretty_assertions = "1.3.0" pretty_assertions = "1.3.0"
duct = "0.13.5" duct = "0.13.5"
shell-escape = "0.1.5"
insta = "1.21.1"
serial_test = "0.9.0"
test-log = "0.2.11" test-log = "0.2.11"
[build-dependencies] [build-dependencies]

2
e2e/shellcode/script.ts

@ -8,6 +8,7 @@ import path, { join } from "node:path"
import { writeFile } from "node:fs/promises" import { writeFile } from "node:fs/promises"
import chalk from "chalk" import chalk from "chalk"
import testBinDir from "./test-bin-dir.js" import testBinDir from "./test-bin-dir.js"
import { rmSync } from "node:fs"
class Script { class Script {
constructor( constructor(
@ -157,6 +158,7 @@ function write(writable: Writable, text: string): Promise<void> {
export function script(shell: Pick<Shell, "dieOnErrors">): Script { export function script(shell: Pick<Shell, "dieOnErrors">): Script {
const fnmDir = path.join(testTmpDir(), "fnm") const fnmDir = path.join(testTmpDir(), "fnm")
rmSync(join(fnmDir, "aliases"), { recursive: true, force: true })
return new Script({ fnmDir }, shell.dieOnErrors ? [shell.dieOnErrors()] : []) return new Script({ fnmDir }, shell.dieOnErrors ? [shell.dieOnErrors()] : [])
} }

3
e2e/shellcode/test-tmp-dir.ts

@ -1,4 +1,4 @@
import { mkdirSync, rmSync } from "node:fs" import { mkdirSync } from "node:fs"
import { tmpdir } from "node:os" import { tmpdir } from "node:os"
import { join } from "node:path" import { join } from "node:path"
@ -9,7 +9,6 @@ export default function testTmpDir(): string {
.replace(/_+/g, "_") .replace(/_+/g, "_")
const tmpDir = join(tmpdir(), `shellcode/${testName}`) const tmpDir = join(tmpdir(), `shellcode/${testName}`)
mkdirSync(tmpDir, { recursive: true }) mkdirSync(tmpDir, { recursive: true })
rmSync(join(tmpDir, "fnm/aliases"), { recursive: true, force: true })
return tmpDir return tmpDir
} }

42
e2e/system-node.test.ts

@ -12,18 +12,7 @@ for (const shell of [Bash, Fish, PowerShell, WinCmd, Zsh]) {
const t = process.platform === "darwin" && shell === Bash ? test.skip : test const t = process.platform === "darwin" && shell === Bash ? test.skip : test
t(`switches to system node`, async () => { t(`switches to system node`, async () => {
const customNode = path.join(testBinDir(), "node") await writeCustomNode()
if (
process.platform === "win32" &&
[WinCmd, PowerShell].includes(shell)
) {
await fs.writeFile(customNode + ".cmd", "@echo custom")
} else {
await fs.writeFile(customNode, `#!/bin/bash\n\necho "custom"\n`)
// set executable
await fs.chmod(customNode, 0o766)
}
await script(shell) await script(shell)
.then(shell.env({})) .then(shell.env({}))
@ -34,5 +23,34 @@ for (const shell of [Bash, Fish, PowerShell, WinCmd, Zsh]) {
.then(testNodeVersion(shell, "custom")) .then(testNodeVersion(shell, "custom"))
.execute(shell) .execute(shell)
}) })
t(`aliasing a system node`, async () => {
writeCustomNode()
const init = script(shell).then(shell.env({}))
await init
.then(shell.call("fnm", ["install", "v10.10.0"]))
.then(shell.call("fnm", ["use", "v10"]))
.then(shell.call("fnm", ["default", "10"]))
.execute(shell)
await init
.then(testNodeVersion(shell, "v10.10.0"))
.then(shell.call("fnm", ["default", "system"]))
.execute(shell)
await init.then(testNodeVersion(shell, "custom")).execute(shell)
})
}) })
async function writeCustomNode() {
const customNode = path.join(testBinDir(), "node")
if (process.platform === "win32" && [WinCmd, PowerShell].includes(shell)) {
await fs.writeFile(customNode + ".cmd", "@echo custom")
} else {
await fs.writeFile(customNode, `#!/bin/bash\n\necho "custom"\n`)
// set executable
await fs.chmod(customNode, 0o766)
}
}
} }

Loading…
Cancel
Save