@ac-kit/integration-test-util 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # @ac-kit/integration-test-util
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0b4fe43: `isCommandAvailable(command, args)` answers, synchronously, whether a program
8
+ can be started at all, whatever its exit status, so a suite that checks its
9
+ output against an independent program (ffmpeg, Python, 7-Zip) can skip where it
10
+ is absent.
11
+ - 0b4fe43: `isolatedGitEnvironment(directory, options?)` returns the environment for a
12
+ `git` a test runs in `directory`, so that it only ever sees repositories inside
13
+ `directory`, even when the suite runs from a git hook that exports `GIT_DIR`,
14
+ `GIT_WORK_TREE` and `GIT_INDEX_FILE` for the hook's own repository. It is
15
+ `@ac-kit/cmd-git`'s `gitIsolatedEnvironment(directory, options)` with the
16
+ author and committer set to `ISOLATED_GIT_IDENTITY`
17
+ (`Test <test@example.invalid>`), so a commit needs no configuration; `options`
18
+ are that function's (`baseEnvironment`, `home`, `platform`) less `identity`.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [0b4fe43]
23
+ - Updated dependencies [0b4fe43]
24
+ - Updated dependencies [0b4fe43]
25
+ - Updated dependencies [0b4fe43]
26
+ - Updated dependencies [0b4fe43]
27
+ - Updated dependencies [0b4fe43]
28
+ - Updated dependencies [0b4fe43]
29
+ - Updated dependencies [0b4fe43]
30
+ - Updated dependencies [0b4fe43]
31
+ - Updated dependencies [0b4fe43]
32
+ - Updated dependencies [0b4fe43]
33
+ - Updated dependencies [0b4fe43]
34
+ - Updated dependencies [0b4fe43]
35
+ - Updated dependencies [0b4fe43]
36
+ - Updated dependencies [0b4fe43]
37
+ - Updated dependencies [0b4fe43]
38
+ - Updated dependencies [0b4fe43]
39
+ - Updated dependencies [0b4fe43]
40
+ - Updated dependencies [0b4fe43]
41
+ - Updated dependencies [0b4fe43]
42
+ - Updated dependencies [0b4fe43]
43
+ - Updated dependencies [0b4fe43]
44
+ - @ac-kit/cmd-git@0.2.0
45
+ - @ac-kit/core@0.13.0
46
+ - @ac-kit/node@0.12.0
47
+ - @ac-kit/crypto-random@0.2.5
48
+ - @ac-kit/cmd-docker@0.2.10
49
+
50
+ ## 0.5.1
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies [34e8cfa]
55
+ - Updated dependencies [34e8cfa]
56
+ - Updated dependencies [34e8cfa]
57
+ - Updated dependencies [34e8cfa]
58
+ - Updated dependencies [34e8cfa]
59
+ - Updated dependencies [34e8cfa]
60
+ - Updated dependencies [34e8cfa]
61
+ - Updated dependencies [34e8cfa]
62
+ - Updated dependencies [34e8cfa]
63
+ - Updated dependencies [34e8cfa]
64
+ - Updated dependencies [34e8cfa]
65
+ - Updated dependencies [34e8cfa]
66
+ - Updated dependencies [34e8cfa]
67
+ - Updated dependencies [34e8cfa]
68
+ - Updated dependencies [34e8cfa]
69
+ - Updated dependencies [34e8cfa]
70
+ - Updated dependencies [34e8cfa]
71
+ - Updated dependencies [34e8cfa]
72
+ - @ac-kit/core@0.12.0
73
+ - @ac-kit/node@0.11.0
74
+ - @ac-kit/crypto-random@0.2.4
75
+ - @ac-kit/cmd-docker@0.2.9
76
+
3
77
  ## 0.5.0
4
78
 
5
79
  ### Minor Changes
package/README.md CHANGED
@@ -56,6 +56,34 @@ await fetch(`http://127.0.0.1:${server.port}/a.yml`);
56
56
  server.requests; // ["/a.yml", "/b.yml"]
57
57
  ```
58
58
 
59
+ `isolatedGitEnvironment(directory)` is the `env` for every `git` a test
60
+ spawns: it drops the `GIT_*` variables a git hook exports (a suite run from a
61
+ `pre-push` hook would otherwise commit into the repository being pushed), stops
62
+ repository discovery at `directory`, and replaces the system, global and user
63
+ configuration with nothing, under a fixed identity.
64
+
65
+ ```ts
66
+ await using fixture = await createFileTreeFixture({ "a.txt": "a\n" });
67
+ const execOptions = { cwd: fixture.root, env: isolatedGitEnvironment(fixture.root) };
68
+ await execFileAsync("git", ["init", "--quiet"], execOptions);
69
+ await execFileAsync("git", ["add", "-A"], execOptions);
70
+ await execFileAsync("git", ["commit", "--quiet", "-m", "a"], execOptions);
71
+ ```
72
+
73
+ `isCommandAvailable(command, args)` answers whether a program can be started,
74
+ synchronously, so a suite checking its output against an independent program
75
+ can skip where that program is absent:
76
+
77
+ ```ts
78
+ import { isCommandAvailable } from "@ac-kit/integration-test-util";
79
+
80
+ const hasFfmpeg = isCommandAvailable("ffmpeg", ["-version"]);
81
+
82
+ it.skipIf(!hasFfmpeg)("is read back by ffmpeg", () => {
83
+ // …
84
+ });
85
+ ```
86
+
59
87
  Separate from `@ac-kit/test-util` on purpose: this package is free to take
60
88
  heavier dependencies because only a handful of suites need it, while
61
89
  `test-util` must stay light enough for every suite in the tree.
@@ -0,0 +1,39 @@
1
+ import { type GitIdentity, type GitIsolatedEnvironmentOptions } from "@ac-kit/cmd-git";
2
+ export type IsolatedGitEnvironmentOptions = Omit<GitIsolatedEnvironmentOptions, "identity">;
3
+ /** The author and committer identity {@link isolatedGitEnvironment} sets. */
4
+ export declare const ISOLATED_GIT_IDENTITY: GitIdentity;
5
+ /**
6
+ * Builds the environment for a `git` child process a test runs in `directory`,
7
+ * so that it only ever sees repositories inside `directory`, whatever the
8
+ * environment the test itself runs in: `@ac-kit/cmd-git`'s
9
+ * `gitIsolatedEnvironment` with {@link ISOLATED_GIT_IDENTITY} as author and
10
+ * committer, so a commit needs no configuration.
11
+ *
12
+ * A test suite run from a git hook (a `pre-push` running `yarn test`, say)
13
+ * inherits `GIT_DIR`, `GIT_WORK_TREE`, `GIT_INDEX_FILE` and friends pointing at
14
+ * the repository being pushed; a `git` spawned with them, whatever its `cwd`,
15
+ * commits, configures and checks out in that repository. Pass the result as the
16
+ * `env` of every `git` a test spawns, `cwd` inside `directory`.
17
+ *
18
+ * Every `GIT_*` variable is dropped; repository discovery stops at `directory`
19
+ * (`GIT_CEILING_DIRECTORIES`); the system configuration is ignored and the
20
+ * global one is `<home>/.gitconfig`, `HOME` and `XDG_CONFIG_HOME` pointing at
21
+ * `options.home` (default `directory`); `GIT_TERMINAL_PROMPT=0`. Names compare
22
+ * case-insensitively on Windows. Touches nothing on disk.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * await using fixture = await createFileTreeFixture({ "a.txt": "a\n" });
27
+ * const env = isolatedGitEnvironment(fixture.root);
28
+ * const execOptions = { cwd: fixture.root, env };
29
+ * await execFileAsync("git", ["init", "--quiet"], execOptions);
30
+ * await execFileAsync("git", ["add", "-A"], execOptions);
31
+ * await execFileAsync("git", ["commit", "--quiet", "-m", "a"], execOptions);
32
+ * ```;
33
+ *
34
+ * @param directory The directory every repository of the test lives in; a
35
+ * relative one resolves against `process.cwd()`.
36
+ * @returns A new environment record.
37
+ */
38
+ export declare function isolatedGitEnvironment(directory: string, options?: IsolatedGitEnvironmentOptions): Record<string, string>;
39
+ //# sourceMappingURL=isolated-git-environment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolated-git-environment.d.ts","sourceRoot":"","sources":["../../src/git/isolated-git-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,6BAA6B,EAElC,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC/C,6BAA6B,EAC7B,UAAU,CACV,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,qBAAqB,EAAE,WAGlC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,sBAAsB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,6BAA6B,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKxB"}
@@ -0,0 +1,46 @@
1
+ import { gitIsolatedEnvironment, } from "@ac-kit/cmd-git";
2
+ /** The author and committer identity {@link isolatedGitEnvironment} sets. */
3
+ export const ISOLATED_GIT_IDENTITY = Object.freeze({
4
+ name: "Test",
5
+ email: "test@example.invalid",
6
+ });
7
+ /**
8
+ * Builds the environment for a `git` child process a test runs in `directory`,
9
+ * so that it only ever sees repositories inside `directory`, whatever the
10
+ * environment the test itself runs in: `@ac-kit/cmd-git`'s
11
+ * `gitIsolatedEnvironment` with {@link ISOLATED_GIT_IDENTITY} as author and
12
+ * committer, so a commit needs no configuration.
13
+ *
14
+ * A test suite run from a git hook (a `pre-push` running `yarn test`, say)
15
+ * inherits `GIT_DIR`, `GIT_WORK_TREE`, `GIT_INDEX_FILE` and friends pointing at
16
+ * the repository being pushed; a `git` spawned with them, whatever its `cwd`,
17
+ * commits, configures and checks out in that repository. Pass the result as the
18
+ * `env` of every `git` a test spawns, `cwd` inside `directory`.
19
+ *
20
+ * Every `GIT_*` variable is dropped; repository discovery stops at `directory`
21
+ * (`GIT_CEILING_DIRECTORIES`); the system configuration is ignored and the
22
+ * global one is `<home>/.gitconfig`, `HOME` and `XDG_CONFIG_HOME` pointing at
23
+ * `options.home` (default `directory`); `GIT_TERMINAL_PROMPT=0`. Names compare
24
+ * case-insensitively on Windows. Touches nothing on disk.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * await using fixture = await createFileTreeFixture({ "a.txt": "a\n" });
29
+ * const env = isolatedGitEnvironment(fixture.root);
30
+ * const execOptions = { cwd: fixture.root, env };
31
+ * await execFileAsync("git", ["init", "--quiet"], execOptions);
32
+ * await execFileAsync("git", ["add", "-A"], execOptions);
33
+ * await execFileAsync("git", ["commit", "--quiet", "-m", "a"], execOptions);
34
+ * ```;
35
+ *
36
+ * @param directory The directory every repository of the test lives in; a
37
+ * relative one resolves against `process.cwd()`.
38
+ * @returns A new environment record.
39
+ */
40
+ export function isolatedGitEnvironment(directory, options) {
41
+ return gitIsolatedEnvironment(directory, {
42
+ ...options,
43
+ identity: ISOLATED_GIT_IDENTITY,
44
+ });
45
+ }
46
+ //# sourceMappingURL=isolated-git-environment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isolated-git-environment.js","sourceRoot":"","sources":["../../src/git/isolated-git-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,sBAAsB,GACtB,MAAM,iBAAiB,CAAC;AAOzB,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAgB,MAAM,CAAC,MAAM,CAAC;IAC/D,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,sBAAsB;CAC7B,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,sBAAsB,CACrC,SAAiB,EACjB,OAAuC;IAEvC,OAAO,sBAAsB,CAAC,SAAS,EAAE;QACxC,GAAG,OAAO;QACV,QAAQ,EAAE,qBAAqB;KAC/B,CAAC,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from "./docker/init-docker-suite.js";
2
2
  export * from "./fs/create-file-tree-fixture.js";
3
+ export * from "./git/isolated-git-environment.js";
3
4
  export * from "./http/start-http-test-server.js";
4
5
  export * from "./net/is-tcp-port-open.js";
5
6
  export * from "./net/try-tcp-connect-n-read-banner.js";
6
7
  export * from "./net/try-tls-connect-n-read-banner.js";
8
+ export * from "./process/is-command-available.js";
7
9
  export * from "./tls/create-self-signed-certificate.js";
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yCAAyC,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from "./docker/init-docker-suite.js";
2
2
  export * from "./fs/create-file-tree-fixture.js";
3
+ export * from "./git/isolated-git-environment.js";
3
4
  export * from "./http/start-http-test-server.js";
4
5
  export * from "./net/is-tcp-port-open.js";
5
6
  export * from "./net/try-tcp-connect-n-read-banner.js";
6
7
  export * from "./net/try-tls-connect-n-read-banner.js";
8
+ export * from "./process/is-command-available.js";
7
9
  export * from "./tls/create-self-signed-certificate.js";
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yCAAyC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether `command` can be run, by running it once with `args` — something
3
+ * cheap that exits at once, such as `["-version"]` — and answering `true`
4
+ * unless it could not be started at all, whatever its exit status. For a suite
5
+ * that checks its output against an independent program (ffmpeg, Python, 7-Zip)
6
+ * and skips where the program is absent: `it.skipIf(!hasFfmpeg)`.
7
+ *
8
+ * Synchronous, so a suite can call it at the top level of its module, where the
9
+ * skip conditions are evaluated. The command's output is discarded.
10
+ */
11
+ export declare function isCommandAvailable(command: string, args: readonly string[]): boolean;
12
+ //# sourceMappingURL=is-command-available.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-command-available.d.ts","sourceRoot":"","sources":["../../src/process/is-command-available.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,GACrB,OAAO,CAET"}
@@ -0,0 +1,15 @@
1
+ import { spawnSync } from "node:child_process";
2
+ /**
3
+ * Whether `command` can be run, by running it once with `args` — something
4
+ * cheap that exits at once, such as `["-version"]` — and answering `true`
5
+ * unless it could not be started at all, whatever its exit status. For a suite
6
+ * that checks its output against an independent program (ffmpeg, Python, 7-Zip)
7
+ * and skips where the program is absent: `it.skipIf(!hasFfmpeg)`.
8
+ *
9
+ * Synchronous, so a suite can call it at the top level of its module, where the
10
+ * skip conditions are evaluated. The command's output is discarded.
11
+ */
12
+ export function isCommandAvailable(command, args) {
13
+ return spawnSync(command, args, { stdio: "ignore" }).error === undefined;
14
+ }
15
+ //# sourceMappingURL=is-command-available.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-command-available.js","sourceRoot":"","sources":["../../src/process/is-command-available.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAe,EACf,IAAuB;IAEvB,OAAO,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC;AAC1E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-kit/integration-test-util",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Test helpers that reach for the machine — Docker containers, TCP and TLS banner checks, temporary file trees, a loopback HTTP server — from a package's integration tests.",
5
5
  "keywords": [
6
6
  "docker",
@@ -40,23 +40,24 @@
40
40
  "prepack": "yarn build"
41
41
  },
42
42
  "dependencies": {
43
- "@ac-kit/cmd-docker": "^0.2.8",
44
- "@ac-kit/core": "^0.11.0",
45
- "@ac-kit/crypto-random": "^0.2.3",
46
- "@ac-kit/node": "^0.10.0",
43
+ "@ac-kit/cmd-docker": "^0.2.10",
44
+ "@ac-kit/cmd-git": "^0.2.0",
45
+ "@ac-kit/core": "^0.13.0",
46
+ "@ac-kit/crypto-random": "^0.2.5",
47
+ "@ac-kit/node": "^0.12.0",
47
48
  "type-fest": "^6.0.0"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@ac-kit/tsconfig": "0.1.0",
51
52
  "@ac-kit/typedoc-config": "0.1.0",
52
- "@ac-kit/vitest-config": "0.1.1",
53
- "@types/node": "26.6.6",
53
+ "@ac-kit/vitest-config": "0.2.0",
54
+ "@types/node": "26.6.11",
54
55
  "@typescript/native": "typescript@7.0.2",
55
56
  "rimraf": "6.1.4",
56
57
  "typedoc": "0.28.20",
57
58
  "typescript": "@typescript/typescript6@6.0.2",
58
- "vite": "8.3.8",
59
- "vitest": "5.1.1"
59
+ "vite": "8.4.0",
60
+ "vitest": "5.1.2"
60
61
  },
61
62
  "peerDependencies": {
62
63
  "vitest": ">=4.0.0"