@pipelab/test-utils 1.0.1-beta.14
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/.turbo/turbo-build.log +14 -0
- package/CHANGELOG.md +120 -0
- package/LICENSE +110 -0
- package/LICENSE.md +110 -0
- package/dist/index.d.mts +65 -0
- package/dist/index.mjs +140 -0
- package/package.json +43 -0
- package/src/index.ts +223 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @pipelab/test-utils@1.0.1-beta.12 build /run/media/armaldio/SSD/Projects/Pipelab/pipelab/packages/test-utils
|
|
4
|
+
> tsdown
|
|
5
|
+
|
|
6
|
+
[34mℹ[39m tsdown [2mv0.21.2[22m powered by rolldown [2mv1.0.0-rc.9[22m
|
|
7
|
+
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
|
+
[34mℹ[39m tsconfig: [34m../../tsconfig.json[39m
|
|
9
|
+
[34mℹ[39m Build start
|
|
10
|
+
[34mℹ[39m Cleaning 2 files
|
|
11
|
+
[34mℹ[39m [2mdist/[22m[1mindex.mjs[22m [2m4.87 kB[22m [2m│ gzip: 1.91 kB[22m
|
|
12
|
+
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.mts[22m[39m [2m1.80 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
13
|
+
[34mℹ[39m 2 files, total: 6.67 kB
|
|
14
|
+
[32m✔[39m Build complete in [32m2173ms[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @pipelab/test-utils
|
|
2
|
+
|
|
3
|
+
## 1.0.1-beta.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- azs
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @pipelab/plugin-core@1.0.1-beta.19
|
|
10
|
+
|
|
11
|
+
## 1.0.1-beta.13
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- sqqd
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @pipelab/plugin-core@1.0.1-beta.18
|
|
18
|
+
|
|
19
|
+
## 1.0.1-beta.12
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- sd
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
- @pipelab/plugin-core@1.0.1-beta.17
|
|
26
|
+
|
|
27
|
+
## 1.0.1-beta.11
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- sd
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
- @pipelab/plugin-core@1.0.1-beta.16
|
|
34
|
+
|
|
35
|
+
## 1.0.1-beta.10
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- wdf
|
|
40
|
+
- Updated dependencies
|
|
41
|
+
- @pipelab/plugin-core@1.0.1-beta.15
|
|
42
|
+
|
|
43
|
+
## 1.0.1-beta.9
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- sdf
|
|
48
|
+
- Updated dependencies
|
|
49
|
+
- @pipelab/plugin-core@1.0.1-beta.14
|
|
50
|
+
|
|
51
|
+
## 1.0.1-beta.8
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies
|
|
56
|
+
- @pipelab/plugin-core@1.0.1-beta.13
|
|
57
|
+
|
|
58
|
+
## 1.0.1-beta.7
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- sd
|
|
63
|
+
- Updated dependencies
|
|
64
|
+
- @pipelab/plugin-core@1.0.1-beta.12
|
|
65
|
+
|
|
66
|
+
## 1.0.1-beta.6
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- rfg
|
|
71
|
+
- Updated dependencies
|
|
72
|
+
- @pipelab/plugin-core@1.0.1-beta.11
|
|
73
|
+
|
|
74
|
+
## 1.0.1-beta.5
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- szd
|
|
79
|
+
- Updated dependencies
|
|
80
|
+
- @pipelab/plugin-core@1.0.1-beta.10
|
|
81
|
+
|
|
82
|
+
## 1.0.1-beta.4
|
|
83
|
+
|
|
84
|
+
### Patch Changes
|
|
85
|
+
|
|
86
|
+
- sd
|
|
87
|
+
- Updated dependencies
|
|
88
|
+
- @pipelab/plugin-core@1.0.1-beta.9
|
|
89
|
+
|
|
90
|
+
## 1.0.1-beta.3
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- sd
|
|
95
|
+
- Updated dependencies
|
|
96
|
+
- @pipelab/plugin-core@1.0.1-beta.8
|
|
97
|
+
|
|
98
|
+
## 1.0.1-beta.2
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- sd
|
|
103
|
+
- Updated dependencies
|
|
104
|
+
- @pipelab/plugin-core@1.0.1-beta.7
|
|
105
|
+
|
|
106
|
+
## 1.0.1-beta.1
|
|
107
|
+
|
|
108
|
+
### Patch Changes
|
|
109
|
+
|
|
110
|
+
- sd
|
|
111
|
+
- Updated dependencies
|
|
112
|
+
- @pipelab/plugin-core@1.0.1-beta.6
|
|
113
|
+
|
|
114
|
+
## 1.0.1-beta.0
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- test
|
|
119
|
+
- Updated dependencies
|
|
120
|
+
- @pipelab/plugin-core@1.0.1-beta.5
|
package/LICENSE
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 CynToolkit
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2024-present Quentin Goinaud - Armaldio
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as execa$1 from "execa";
|
|
2
|
+
import { Action, ActionRunner, ActionRunnerData } from "@pipelab/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Finds the monorepo root by looking for pnpm-workspace.yaml.
|
|
7
|
+
*/
|
|
8
|
+
declare function findProjectRoot(startDir: string): string;
|
|
9
|
+
declare const isWindows: boolean;
|
|
10
|
+
declare const isMac: boolean;
|
|
11
|
+
declare const isLinux: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a unique sandbox directory and returns a bundle containing its path
|
|
14
|
+
* and a pre-filled remove utility.
|
|
15
|
+
*/
|
|
16
|
+
declare const createSandbox: (prefix: string) => Promise<{
|
|
17
|
+
path: string;
|
|
18
|
+
paths: {
|
|
19
|
+
input: string;
|
|
20
|
+
output: string;
|
|
21
|
+
userData: string;
|
|
22
|
+
project: string;
|
|
23
|
+
thirdparty: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a mock binary/script in the sandbox.
|
|
27
|
+
*/
|
|
28
|
+
mockBinary: (relativePath: string, content?: string, options?: {
|
|
29
|
+
extension?: string | false;
|
|
30
|
+
}) => Promise<string>;
|
|
31
|
+
remove: () => Promise<void>;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Runs the Pipelab CLI out-of-process.
|
|
35
|
+
*/
|
|
36
|
+
declare const runCLI: (args: string[], options?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
env?: Record<string, string>;
|
|
39
|
+
}) => Promise<execa$1.Result<{
|
|
40
|
+
cwd: string;
|
|
41
|
+
env: {
|
|
42
|
+
PIPELAB_DISABLE_HISTORY: string;
|
|
43
|
+
};
|
|
44
|
+
}>>;
|
|
45
|
+
/**
|
|
46
|
+
* Runs a Pipelab action runner directly in-process for focused testing.
|
|
47
|
+
*/
|
|
48
|
+
declare const runAction: <A extends Action>(runner: ActionRunner<A>, options: {
|
|
49
|
+
inputs: ActionRunnerData<A>["inputs"];
|
|
50
|
+
sandboxPath: string;
|
|
51
|
+
extraEnv?: Record<string, string>;
|
|
52
|
+
}) => Promise<{
|
|
53
|
+
outputs: Record<string, unknown>;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Runs the packaged electron app (smoke test)
|
|
57
|
+
*/
|
|
58
|
+
declare const runElectronApp: (app_path: string, options?: {
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
}) => Promise<execa$1.Result<{
|
|
61
|
+
cleanup: true;
|
|
62
|
+
timeout: number;
|
|
63
|
+
}>>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { createSandbox, findProjectRoot, isLinux, isMac, isWindows, runAction, runCLI, runElectronApp };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { dirname, join, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { chmod, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { execa } from "execa";
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
/**
|
|
10
|
+
* Finds the monorepo root by looking for pnpm-workspace.yaml.
|
|
11
|
+
*/
|
|
12
|
+
function findProjectRoot(startDir) {
|
|
13
|
+
let curr = startDir;
|
|
14
|
+
while (curr !== dirname(curr)) {
|
|
15
|
+
if (existsSync(join(curr, "pnpm-workspace.yaml"))) return curr;
|
|
16
|
+
curr = dirname(curr);
|
|
17
|
+
}
|
|
18
|
+
throw new Error("Could not find project root (pnpm-workspace.yaml)");
|
|
19
|
+
}
|
|
20
|
+
const isWindows = process.platform === "win32";
|
|
21
|
+
const isMac = process.platform === "darwin";
|
|
22
|
+
const isLinux = process.platform === "linux";
|
|
23
|
+
/**
|
|
24
|
+
* Creates a unique sandbox directory and returns a bundle containing its path
|
|
25
|
+
* and a pre-filled remove utility.
|
|
26
|
+
*/
|
|
27
|
+
const createSandbox = async (prefix) => {
|
|
28
|
+
const sandboxPath = join(tmpdir(), `${prefix}-${Math.random().toString(36).substring(7)}`);
|
|
29
|
+
const paths = {
|
|
30
|
+
input: join(sandboxPath, "input"),
|
|
31
|
+
output: join(sandboxPath, "output"),
|
|
32
|
+
userData: join(sandboxPath, "user-data"),
|
|
33
|
+
project: join(sandboxPath, "project"),
|
|
34
|
+
thirdparty: join(sandboxPath, "thirdparty")
|
|
35
|
+
};
|
|
36
|
+
await mkdir(sandboxPath, { recursive: true });
|
|
37
|
+
await Promise.all([
|
|
38
|
+
mkdir(paths.input, { recursive: true }),
|
|
39
|
+
mkdir(paths.output, { recursive: true }),
|
|
40
|
+
mkdir(paths.userData, { recursive: true })
|
|
41
|
+
]);
|
|
42
|
+
return {
|
|
43
|
+
path: sandboxPath,
|
|
44
|
+
paths,
|
|
45
|
+
mockBinary: async (relativePath, content, options = {}) => {
|
|
46
|
+
const fullPath = join(sandboxPath, relativePath);
|
|
47
|
+
let platformPath = fullPath;
|
|
48
|
+
if (options.extension === false) {} else if (options.extension) platformPath = `${fullPath}.${options.extension}`;
|
|
49
|
+
else platformPath = /\.[a-z0-9]+$/i.test(relativePath) ? fullPath : isWindows ? `${fullPath}.cmd` : `${fullPath}.sh`;
|
|
50
|
+
const defaultContent = isWindows ? `@echo off\necho Mock Binary Execution: %*\nexit /b 0` : `#!/bin/bash\necho "Mock Binary Execution: $@"\nexit 0`;
|
|
51
|
+
await mkdir(dirname(platformPath), { recursive: true });
|
|
52
|
+
await writeFile(platformPath, content || defaultContent);
|
|
53
|
+
if (!isWindows) await chmod(platformPath, 493);
|
|
54
|
+
return platformPath;
|
|
55
|
+
},
|
|
56
|
+
remove: async () => {
|
|
57
|
+
await rm(sandboxPath, {
|
|
58
|
+
recursive: true,
|
|
59
|
+
force: true,
|
|
60
|
+
maxRetries: 20,
|
|
61
|
+
retryDelay: 500
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Runs the Pipelab CLI out-of-process.
|
|
68
|
+
*/
|
|
69
|
+
const runCLI = async (args, options = {}) => {
|
|
70
|
+
const projectRoot = findProjectRoot(__dirname);
|
|
71
|
+
return execa("tsx", [resolve(projectRoot, "apps/cli/src/index.ts"), ...args], {
|
|
72
|
+
cwd: options.cwd || projectRoot,
|
|
73
|
+
env: {
|
|
74
|
+
...process.env,
|
|
75
|
+
PIPELAB_DISABLE_HISTORY: "true",
|
|
76
|
+
...options.env
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Runs a Pipelab action runner directly in-process for focused testing.
|
|
82
|
+
*/
|
|
83
|
+
const runAction = async (runner, options) => {
|
|
84
|
+
const outputs = {};
|
|
85
|
+
const pnpmShimPath = join(options.sandboxPath, "pnpm-shim.cjs");
|
|
86
|
+
await writeFile(pnpmShimPath, `const { spawnSync } = require('child_process');
|
|
87
|
+
spawnSync('pnpm', process.argv.slice(2), { stdio: 'inherit', shell: true });`);
|
|
88
|
+
const context = {
|
|
89
|
+
inputs: options.inputs,
|
|
90
|
+
log: (...args) => {
|
|
91
|
+
console.log("[Runner Log]", ...args);
|
|
92
|
+
},
|
|
93
|
+
setOutput: (key, value) => {
|
|
94
|
+
console.log(`[Runner Output] ${key} = ${value}`);
|
|
95
|
+
outputs[key] = value;
|
|
96
|
+
},
|
|
97
|
+
cwd: options.sandboxPath,
|
|
98
|
+
paths: {
|
|
99
|
+
assets: join(options.sandboxPath, "assets"),
|
|
100
|
+
cache: join(options.sandboxPath, "cache"),
|
|
101
|
+
pnpm: pnpmShimPath,
|
|
102
|
+
node: process.execPath,
|
|
103
|
+
userData: join(options.sandboxPath, "user-data"),
|
|
104
|
+
modules: join(options.sandboxPath, "modules"),
|
|
105
|
+
thirdparty: join(options.sandboxPath, "thirdparty")
|
|
106
|
+
},
|
|
107
|
+
api: { fetchAsset: async (packageName) => {
|
|
108
|
+
const sandboxAssetPath = join(options.sandboxPath, "assets", packageName);
|
|
109
|
+
if (existsSync(sandboxAssetPath)) return sandboxAssetPath;
|
|
110
|
+
const folderName = packageName.startsWith("@pipelab/") ? packageName.replace("@pipelab/", "") : packageName;
|
|
111
|
+
return join(findProjectRoot(__dirname), "assets", folderName);
|
|
112
|
+
} },
|
|
113
|
+
browserWindow: void 0,
|
|
114
|
+
abortSignal: new AbortController().signal,
|
|
115
|
+
setMeta: () => {},
|
|
116
|
+
meta: {}
|
|
117
|
+
};
|
|
118
|
+
const originalEnv = { ...process.env };
|
|
119
|
+
if (options.extraEnv) Object.assign(process.env, options.extraEnv);
|
|
120
|
+
try {
|
|
121
|
+
await runner(context);
|
|
122
|
+
} finally {
|
|
123
|
+
if (options.extraEnv) {
|
|
124
|
+
for (const key in options.extraEnv) if (!(key in originalEnv)) delete process.env[key];
|
|
125
|
+
Object.assign(process.env, originalEnv);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { outputs };
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Runs the packaged electron app (smoke test)
|
|
132
|
+
*/
|
|
133
|
+
const runElectronApp = async (app_path, options = {}) => {
|
|
134
|
+
return execa(app_path, [], {
|
|
135
|
+
cleanup: true,
|
|
136
|
+
timeout: options.timeoutMs || 12e4
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
export { createSandbox, findProjectRoot, isLinux, isMac, isWindows, runAction, runCLI, runElectronApp };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipelab/test-utils",
|
|
3
|
+
"version": "1.0.1-beta.14",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Testing utilities for Pipelab plugins and monorepo",
|
|
6
|
+
"license": "FSL-1.1-MIT",
|
|
7
|
+
"author": "CynToolkit",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/CynToolkit/pipelab.git",
|
|
11
|
+
"directory": "packages/test-utils"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.mjs",
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"execa": "9.5.1",
|
|
30
|
+
"@pipelab/plugin-core": "1.0.1-beta.19"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "24.12.2",
|
|
34
|
+
"tsdown": "0.21.2",
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"@pipelab/tsconfig": "1.0.1-beta.19"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown",
|
|
40
|
+
"format": "oxfmt .",
|
|
41
|
+
"lint": "oxlint ."
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { resolve, dirname, join } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { mkdir, writeFile, chmod, rm } from "node:fs/promises";
|
|
4
|
+
import { existsSync as existsSyncSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { type ActionRunner, type ActionRunnerData, type Action, PipelabContext } from "@pipelab/plugin-core";
|
|
7
|
+
import { execa } from "execa";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Finds the monorepo root by looking for pnpm-workspace.yaml.
|
|
14
|
+
*/
|
|
15
|
+
export function findProjectRoot(startDir: string): string {
|
|
16
|
+
let curr = startDir;
|
|
17
|
+
while (curr !== dirname(curr)) {
|
|
18
|
+
if (existsSyncSync(join(curr, "pnpm-workspace.yaml"))) {
|
|
19
|
+
return curr;
|
|
20
|
+
}
|
|
21
|
+
curr = dirname(curr);
|
|
22
|
+
}
|
|
23
|
+
throw new Error("Could not find project root (pnpm-workspace.yaml)");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const isWindows = process.platform === "win32";
|
|
27
|
+
export const isMac = process.platform === "darwin";
|
|
28
|
+
export const isLinux = process.platform === "linux";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a unique sandbox directory and returns a bundle containing its path
|
|
32
|
+
* and a pre-filled remove utility.
|
|
33
|
+
*/
|
|
34
|
+
export const createSandbox = async (prefix: string) => {
|
|
35
|
+
const sandboxPath = join(tmpdir(), `${prefix}-${Math.random().toString(36).substring(7)}`);
|
|
36
|
+
|
|
37
|
+
const paths = {
|
|
38
|
+
input: join(sandboxPath, "input"),
|
|
39
|
+
output: join(sandboxPath, "output"),
|
|
40
|
+
userData: join(sandboxPath, "user-data"),
|
|
41
|
+
project: join(sandboxPath, "project"),
|
|
42
|
+
thirdparty: join(sandboxPath, "thirdparty"),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
await mkdir(sandboxPath, { recursive: true });
|
|
46
|
+
await Promise.all([
|
|
47
|
+
mkdir(paths.input, { recursive: true }),
|
|
48
|
+
mkdir(paths.output, { recursive: true }),
|
|
49
|
+
mkdir(paths.userData, { recursive: true }),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
path: sandboxPath,
|
|
54
|
+
paths,
|
|
55
|
+
/**
|
|
56
|
+
* Creates a mock binary/script in the sandbox.
|
|
57
|
+
*/
|
|
58
|
+
mockBinary: async (
|
|
59
|
+
relativePath: string,
|
|
60
|
+
content?: string,
|
|
61
|
+
options: { extension?: string | false } = {},
|
|
62
|
+
) => {
|
|
63
|
+
const fullPath = join(sandboxPath, relativePath);
|
|
64
|
+
let platformPath = fullPath;
|
|
65
|
+
|
|
66
|
+
if (options.extension === false) {
|
|
67
|
+
// Use exactly the path provided
|
|
68
|
+
} else if (options.extension) {
|
|
69
|
+
platformPath = `${fullPath}.${options.extension}`;
|
|
70
|
+
} else {
|
|
71
|
+
const hasExtension = /\.[a-z0-9]+$/i.test(relativePath);
|
|
72
|
+
platformPath = hasExtension ? fullPath : isWindows ? `${fullPath}.cmd` : `${fullPath}.sh`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const defaultContent = isWindows
|
|
76
|
+
? `@echo off\necho Mock Binary Execution: %*\nexit /b 0`
|
|
77
|
+
: `#!/bin/bash\necho "Mock Binary Execution: $@"\nexit 0`;
|
|
78
|
+
|
|
79
|
+
await mkdir(dirname(platformPath), { recursive: true });
|
|
80
|
+
await writeFile(platformPath, content || defaultContent);
|
|
81
|
+
|
|
82
|
+
if (!isWindows) {
|
|
83
|
+
await chmod(platformPath, 0o755);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return platformPath;
|
|
87
|
+
},
|
|
88
|
+
remove: async () => {
|
|
89
|
+
await rm(sandboxPath, {
|
|
90
|
+
recursive: true,
|
|
91
|
+
force: true,
|
|
92
|
+
maxRetries: 20,
|
|
93
|
+
retryDelay: 500,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Runs the Pipelab CLI out-of-process.
|
|
101
|
+
*/
|
|
102
|
+
export const runCLI = async (
|
|
103
|
+
args: string[],
|
|
104
|
+
options: {
|
|
105
|
+
cwd?: string;
|
|
106
|
+
env?: Record<string, string>;
|
|
107
|
+
} = {},
|
|
108
|
+
) => {
|
|
109
|
+
const projectRoot = findProjectRoot(__dirname);
|
|
110
|
+
const cliPath = resolve(projectRoot, "apps/cli/src/index.ts");
|
|
111
|
+
|
|
112
|
+
return execa("tsx", [cliPath, ...args], {
|
|
113
|
+
cwd: options.cwd || projectRoot,
|
|
114
|
+
env: {
|
|
115
|
+
...process.env,
|
|
116
|
+
PIPELAB_DISABLE_HISTORY: "true",
|
|
117
|
+
...options.env,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Runs a Pipelab action runner directly in-process for focused testing.
|
|
124
|
+
*/
|
|
125
|
+
export const runAction = async <A extends Action>(
|
|
126
|
+
runner: ActionRunner<A>,
|
|
127
|
+
options: {
|
|
128
|
+
inputs: ActionRunnerData<A>["inputs"];
|
|
129
|
+
sandboxPath: string;
|
|
130
|
+
extraEnv?: Record<string, string>;
|
|
131
|
+
},
|
|
132
|
+
): Promise<{ outputs: Record<string, unknown> }> => {
|
|
133
|
+
const outputs: Record<string, unknown> = {};
|
|
134
|
+
|
|
135
|
+
// Create a pnpm shim because ensureNPMPackage expects a JS file runnable by node
|
|
136
|
+
const pnpmShimPath = join(options.sandboxPath, "pnpm-shim.cjs");
|
|
137
|
+
await writeFile(
|
|
138
|
+
pnpmShimPath,
|
|
139
|
+
`const { spawnSync } = require('child_process');
|
|
140
|
+
spawnSync('pnpm', process.argv.slice(2), { stdio: 'inherit', shell: true });`,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const context: ActionRunnerData<A> = {
|
|
144
|
+
inputs: options.inputs,
|
|
145
|
+
log: (...args: any[]) => {
|
|
146
|
+
console.log("[Runner Log]", ...args);
|
|
147
|
+
},
|
|
148
|
+
setOutput: (key: any, value: any) => {
|
|
149
|
+
console.log(`[Runner Output] ${key} = ${value}`);
|
|
150
|
+
outputs[key] = value;
|
|
151
|
+
},
|
|
152
|
+
cwd: options.sandboxPath,
|
|
153
|
+
paths: {
|
|
154
|
+
assets: join(options.sandboxPath, "assets"),
|
|
155
|
+
cache: join(options.sandboxPath, "cache"),
|
|
156
|
+
pnpm: pnpmShimPath,
|
|
157
|
+
node: process.execPath,
|
|
158
|
+
userData: join(options.sandboxPath, "user-data"),
|
|
159
|
+
modules: join(options.sandboxPath, "modules"),
|
|
160
|
+
thirdparty: join(options.sandboxPath, "thirdparty"),
|
|
161
|
+
},
|
|
162
|
+
api: {
|
|
163
|
+
fetchAsset: async (packageName: string) => {
|
|
164
|
+
const sandboxAssetPath = join(options.sandboxPath, "assets", packageName);
|
|
165
|
+
if (existsSyncSync(sandboxAssetPath)) {
|
|
166
|
+
return sandboxAssetPath;
|
|
167
|
+
}
|
|
168
|
+
// Fallback to real monorepo assets
|
|
169
|
+
// Normalize: remove @pipelab/ prefix if present
|
|
170
|
+
const folderName = packageName.startsWith("@pipelab/")
|
|
171
|
+
? packageName.replace("@pipelab/", "")
|
|
172
|
+
: packageName;
|
|
173
|
+
|
|
174
|
+
const projectRoot = findProjectRoot(__dirname);
|
|
175
|
+
return join(projectRoot, "assets", folderName);
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
// @ts-ignore - Mocking BrowserWindow
|
|
179
|
+
browserWindow: undefined,
|
|
180
|
+
abortSignal: new AbortController().signal,
|
|
181
|
+
context: new PipelabContext({
|
|
182
|
+
userDataPath: join(options.sandboxPath, "user-data"),
|
|
183
|
+
}),
|
|
184
|
+
// @ts-ignore - Mocking setMeta
|
|
185
|
+
setMeta: () => {},
|
|
186
|
+
meta: {} as any,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// Set environment variables for the test if provided
|
|
190
|
+
const originalEnv = { ...process.env };
|
|
191
|
+
if (options.extraEnv) {
|
|
192
|
+
Object.assign(process.env, options.extraEnv);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
await runner(context);
|
|
197
|
+
} finally {
|
|
198
|
+
// Restore original environment
|
|
199
|
+
if (options.extraEnv) {
|
|
200
|
+
// Remove keys that were added
|
|
201
|
+
for (const key in options.extraEnv) {
|
|
202
|
+
if (!(key in originalEnv)) {
|
|
203
|
+
delete process.env[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Restore original values
|
|
207
|
+
Object.assign(process.env, originalEnv);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { outputs };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Runs the packaged electron app (smoke test)
|
|
216
|
+
*/
|
|
217
|
+
export const runElectronApp = async (app_path: string, options: { timeoutMs?: number } = {}) => {
|
|
218
|
+
const child = execa(app_path, [], {
|
|
219
|
+
cleanup: true,
|
|
220
|
+
timeout: options.timeoutMs || 120000,
|
|
221
|
+
});
|
|
222
|
+
return child;
|
|
223
|
+
};
|