@zgeoff/testing 0.2.0 → 0.3.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.
Files changed (37) hide show
  1. package/dist/utils/create-stub-sudo.d.ts +1 -0
  2. package/dist/{helpers → utils}/index.d.ts +1 -0
  3. package/package.json +5 -5
  4. package/src/utils/create-stub-sudo.ts +25 -0
  5. package/src/{helpers → utils}/index.ts +1 -0
  6. /package/dist/{helpers → utils}/create-blocking-stub-kit.d.ts +0 -0
  7. /package/dist/{helpers → utils}/create-git-commit.d.ts +0 -0
  8. /package/dist/{helpers → utils}/env-originals.d.ts +0 -0
  9. /package/dist/{helpers → utils}/make-answer-queue.d.ts +0 -0
  10. /package/dist/{helpers → utils}/make-rejecting-stub.d.ts +0 -0
  11. /package/dist/{helpers → utils}/make-repeating-answer-queue.d.ts +0 -0
  12. /package/dist/{helpers → utils}/make-resolving-stub.d.ts +0 -0
  13. /package/dist/{helpers → utils}/read-git-env.d.ts +0 -0
  14. /package/dist/{helpers → utils}/read-git-head.d.ts +0 -0
  15. /package/dist/{helpers → utils}/read-run-folder-prefix.d.ts +0 -0
  16. /package/dist/{helpers → utils}/read-stream-until.d.ts +0 -0
  17. /package/dist/{helpers → utils}/remove-env-overrides.d.ts +0 -0
  18. /package/dist/{helpers → utils}/run-git.d.ts +0 -0
  19. /package/dist/{helpers → utils}/update-env.d.ts +0 -0
  20. /package/dist/{helpers → utils}/wait-for.d.ts +0 -0
  21. /package/dist/{helpers → utils}/write-tree-files.d.ts +0 -0
  22. /package/src/{helpers → utils}/create-blocking-stub-kit.ts +0 -0
  23. /package/src/{helpers → utils}/create-git-commit.ts +0 -0
  24. /package/src/{helpers → utils}/env-originals.ts +0 -0
  25. /package/src/{helpers → utils}/make-answer-queue.ts +0 -0
  26. /package/src/{helpers → utils}/make-rejecting-stub.ts +0 -0
  27. /package/src/{helpers → utils}/make-repeating-answer-queue.ts +0 -0
  28. /package/src/{helpers → utils}/make-resolving-stub.ts +0 -0
  29. /package/src/{helpers → utils}/read-git-env.ts +0 -0
  30. /package/src/{helpers → utils}/read-git-head.ts +0 -0
  31. /package/src/{helpers → utils}/read-run-folder-prefix.ts +0 -0
  32. /package/src/{helpers → utils}/read-stream-until.ts +0 -0
  33. /package/src/{helpers → utils}/remove-env-overrides.ts +0 -0
  34. /package/src/{helpers → utils}/run-git.ts +0 -0
  35. /package/src/{helpers → utils}/update-env.ts +0 -0
  36. /package/src/{helpers → utils}/wait-for.ts +0 -0
  37. /package/src/{helpers → utils}/write-tree-files.ts +0 -0
@@ -0,0 +1 @@
1
+ export declare function createStubSudo(directory: string, record: string): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  export { createBlockingStubKit } from './create-blocking-stub-kit.ts';
2
2
  export { createGitCommit } from './create-git-commit.ts';
3
+ export { createStubSudo } from './create-stub-sudo.ts';
3
4
  export { makeAnswerQueue } from './make-answer-queue.ts';
4
5
  export { makeRepeatingAnswerQueue } from './make-repeating-answer-queue.ts';
5
6
  export { makeRejectingStub } from './make-rejecting-stub.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/testing",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Drive a real program from a Bun test, in a pseudo-terminal or as a process with a ready check",
5
5
  "keywords": [
6
6
  "bun",
@@ -29,9 +29,9 @@
29
29
  "default": "./src/cli/index.ts"
30
30
  },
31
31
  "./helpers": {
32
- "types": "./dist/helpers/index.d.ts",
33
- "bun": "./src/helpers/index.ts",
34
- "default": "./src/helpers/index.ts"
32
+ "types": "./dist/utils/index.d.ts",
33
+ "bun": "./src/utils/index.ts",
34
+ "default": "./src/utils/index.ts"
35
35
  },
36
36
  "./process": {
37
37
  "types": "./dist/process/index.d.ts",
@@ -47,7 +47,7 @@
47
47
  "typecheck": "tsrs"
48
48
  },
49
49
  "dependencies": {
50
- "bun-pty": "0.5.2"
50
+ "bun-pty": "0.6.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/bun": "1.4.4",
@@ -0,0 +1,25 @@
1
+ import { chmod, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+
4
+ // Writes a stand-in for sudo into the folder. It answers the probe `sudo -n true` with success. Any
5
+ // other call appends a line per argument to the record, `file <argument>` when the argument names a
6
+ // file that exists and `text <argument>` otherwise, then fails as a command that never starts does.
7
+ export async function createStubSudo(directory: string, record: string): Promise<void> {
8
+ const path = join(directory, 'sudo');
9
+
10
+ await writeFile(
11
+ path,
12
+ [
13
+ '#!/bin/bash',
14
+ `[ "$*" = '-n true' ] && exit 0`,
15
+ 'for argument in "$@"; do',
16
+ ' if [ -f "$argument" ]; then kind=file; else kind=text; fi',
17
+ ` printf '%s %s\\n' "$kind" "$argument" >> '${record.replaceAll("'", String.raw`'\''`)}'`,
18
+ 'done',
19
+ 'exit 1',
20
+ '',
21
+ ].join('\n'),
22
+ );
23
+
24
+ await chmod(path, 0o755);
25
+ }
@@ -1,5 +1,6 @@
1
1
  export { createBlockingStubKit } from './create-blocking-stub-kit.ts';
2
2
  export { createGitCommit } from './create-git-commit.ts';
3
+ export { createStubSudo } from './create-stub-sudo.ts';
3
4
  export { makeAnswerQueue } from './make-answer-queue.ts';
4
5
  export { makeRepeatingAnswerQueue } from './make-repeating-answer-queue.ts';
5
6
  export { makeRejectingStub } from './make-rejecting-stub.ts';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes