Skip to content

Commit 00a06ea

Browse files
committed
refactor(test): dedupe installer npm fixtures
1 parent af21bd7 commit 00a06ea

3 files changed

Lines changed: 78 additions & 136 deletions

File tree

test/scripts/install-cli.test.ts

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
import { tmpdir } from "node:os";
1515
import { join } from "node:path";
1616
import { describe, expect, it } from "vitest";
17+
import {
18+
writeNpmBeforePolicyFixture,
19+
writeNpmFreshnessConflictFixture,
20+
} from "./install-npm-fixtures.js";
1721

1822
const SCRIPT_PATH = "scripts/install-cli.sh";
1923

@@ -34,74 +38,6 @@ function linkRequiredShellTools(bin: string) {
3438
}
3539
}
3640

37-
function writeNpmFreshnessConflictFixture(path: string, argsLog: string) {
38-
writeFileSync(
39-
path,
40-
[
41-
"#!/usr/bin/env bash",
42-
"set -euo pipefail",
43-
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
44-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
45-
" printf 'null\\n'",
46-
" exit 0",
47-
"fi",
48-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
49-
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
50-
" exit 0",
51-
"fi",
52-
'for arg in "$@"; do',
53-
' if [[ "$arg" == --before=* ]]; then',
54-
" printf '%s\\n' 'Exit prior to config file resolving' >&2",
55-
" printf '%s\\n' 'cause' >&2",
56-
" printf '%s\\n' '--min-release-age cannot be provided when using --before' >&2",
57-
" exit 64",
58-
" fi",
59-
"done",
60-
'for arg in "$@"; do',
61-
' if [[ "$arg" == "--min-release-age=0" ]]; then',
62-
" exit 0",
63-
" fi",
64-
"done",
65-
"exit 65",
66-
"",
67-
].join("\n"),
68-
);
69-
chmodSync(path, 0o755);
70-
}
71-
72-
function writeNpmBeforePolicyFixture(path: string, argsLog: string) {
73-
writeFileSync(
74-
path,
75-
[
76-
"#!/usr/bin/env bash",
77-
"set -euo pipefail",
78-
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
79-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
80-
" printf 'null\\n'",
81-
" exit 0",
82-
"fi",
83-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
84-
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
85-
" exit 0",
86-
"fi",
87-
'for arg in "$@"; do',
88-
' if [[ "$arg" == "--min-release-age=0" ]]; then',
89-
" printf '%s\\n' 'min-release-age should not be selected for project-only npmrc' >&2",
90-
" exit 64",
91-
" fi",
92-
"done",
93-
'for arg in "$@"; do',
94-
' if [[ "$arg" == --before=* ]]; then',
95-
" exit 0",
96-
" fi",
97-
"done",
98-
"exit 65",
99-
"",
100-
].join("\n"),
101-
);
102-
chmodSync(path, 0o755);
103-
}
104-
10541
describe("install-cli.sh", () => {
10642
const script = readFileSync(SCRIPT_PATH, "utf8");
10743

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// NPM CLI fixture writers used by installer shell-script tests.
2+
import { chmodSync, writeFileSync } from "node:fs";
3+
4+
export function writeNpmFreshnessConflictFixture(path: string, argsLog: string) {
5+
writeFileSync(
6+
path,
7+
[
8+
"#!/usr/bin/env bash",
9+
"set -euo pipefail",
10+
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
11+
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
12+
" printf 'null\\n'",
13+
" exit 0",
14+
"fi",
15+
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
16+
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
17+
" exit 0",
18+
"fi",
19+
'for arg in "$@"; do',
20+
' if [[ "$arg" == --before=* ]]; then',
21+
" printf '%s\\n' 'Exit prior to config file resolving' >&2",
22+
" printf '%s\\n' 'cause' >&2",
23+
" printf '%s\\n' '--min-release-age cannot be provided when using --before' >&2",
24+
" exit 64",
25+
" fi",
26+
"done",
27+
'for arg in "$@"; do',
28+
' if [[ "$arg" == "--min-release-age=0" ]]; then',
29+
" exit 0",
30+
" fi",
31+
"done",
32+
"exit 65",
33+
"",
34+
].join("\n"),
35+
);
36+
chmodSync(path, 0o755);
37+
}
38+
39+
export function writeNpmBeforePolicyFixture(path: string, argsLog: string) {
40+
writeFileSync(
41+
path,
42+
[
43+
"#!/usr/bin/env bash",
44+
"set -euo pipefail",
45+
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
46+
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
47+
" printf 'null\\n'",
48+
" exit 0",
49+
"fi",
50+
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
51+
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
52+
" exit 0",
53+
"fi",
54+
'for arg in "$@"; do',
55+
' if [[ "$arg" == "--min-release-age=0" ]]; then',
56+
" printf '%s\\n' 'min-release-age should not be selected for project-only npmrc' >&2",
57+
" exit 64",
58+
" fi",
59+
"done",
60+
'for arg in "$@"; do',
61+
' if [[ "$arg" == --before=* ]]; then',
62+
" exit 0",
63+
" fi",
64+
"done",
65+
"exit 65",
66+
"",
67+
].join("\n"),
68+
);
69+
chmodSync(path, 0o755);
70+
}

test/scripts/install-sh.test.ts

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { chmodSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync
44
import { tmpdir } from "node:os";
55
import { join } from "node:path";
66
import { describe, expect, it } from "vitest";
7+
import {
8+
writeNpmBeforePolicyFixture,
9+
writeNpmFreshnessConflictFixture,
10+
} from "./install-npm-fixtures.js";
711

812
const SCRIPT_PATH = "scripts/install.sh";
913

@@ -26,74 +30,6 @@ function runInstallShell(script: string, env: NodeJS.ProcessEnv = {}) {
2630
}
2731
}
2832

29-
function writeNpmFreshnessConflictFixture(path: string, argsLog: string) {
30-
writeFileSync(
31-
path,
32-
[
33-
"#!/usr/bin/env bash",
34-
"set -euo pipefail",
35-
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
36-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
37-
" printf 'null\\n'",
38-
" exit 0",
39-
"fi",
40-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
41-
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
42-
" exit 0",
43-
"fi",
44-
'for arg in "$@"; do',
45-
' if [[ "$arg" == --before=* ]]; then',
46-
" printf '%s\\n' 'Exit prior to config file resolving' >&2",
47-
" printf '%s\\n' 'cause' >&2",
48-
" printf '%s\\n' '--min-release-age cannot be provided when using --before' >&2",
49-
" exit 64",
50-
" fi",
51-
"done",
52-
'for arg in "$@"; do',
53-
' if [[ "$arg" == "--min-release-age=0" ]]; then',
54-
" exit 0",
55-
" fi",
56-
"done",
57-
"exit 65",
58-
"",
59-
].join("\n"),
60-
);
61-
chmodSync(path, 0o755);
62-
}
63-
64-
function writeNpmBeforePolicyFixture(path: string, argsLog: string) {
65-
writeFileSync(
66-
path,
67-
[
68-
"#!/usr/bin/env bash",
69-
"set -euo pipefail",
70-
`printf '%s\\n' "$*" >> ${JSON.stringify(argsLog)}`,
71-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "min-release-age" ]]; then',
72-
" printf 'null\\n'",
73-
" exit 0",
74-
"fi",
75-
'if [[ "$1" == "config" && "$2" == "get" && "$3" == "before" ]]; then',
76-
" printf 'Wed May 13 2026 21:25:20 GMT-0300 (Brasilia Standard Time)\\n'",
77-
" exit 0",
78-
"fi",
79-
'for arg in "$@"; do',
80-
' if [[ "$arg" == "--min-release-age=0" ]]; then',
81-
" printf '%s\\n' 'min-release-age should not be selected for project-only npmrc' >&2",
82-
" exit 64",
83-
" fi",
84-
"done",
85-
'for arg in "$@"; do',
86-
' if [[ "$arg" == --before=* ]]; then',
87-
" exit 0",
88-
" fi",
89-
"done",
90-
"exit 65",
91-
"",
92-
].join("\n"),
93-
);
94-
chmodSync(path, 0o755);
95-
}
96-
9733
describe("install.sh", () => {
9834
const script = readFileSync(SCRIPT_PATH, "utf8");
9935

0 commit comments

Comments
 (0)