@lengmoxxl/wangcai-testkit 0.1.0 → 0.1.1
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/README.md +1 -1
- package/harness.cjs +27 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ body 收到 `{ home, env, page, errors }`:这一例的临时 home 与它的环
|
|
|
43
43
|
|
|
44
44
|
| 成员 | 作用 |
|
|
45
45
|
| --- | --- |
|
|
46
|
-
| `withWindow(prefix, lists, body)` | 一个用例:临时 home、按 `lists` 写的插件表、窗口、收尾 |
|
|
46
|
+
| `withWindow(prefix, lists, body)` | 一个用例:临时 home、Core、按 `lists` 写的插件表、窗口、收尾 |
|
|
47
47
|
| `openView(page, name)` | 在右侧栏里新开一个插件视图,需要时先把侧栏显示出来 |
|
|
48
48
|
| `viewTabs(page)` | 侧栏上显示着的那些标签页,可用来计数 |
|
|
49
49
|
| `closeView(page)` | 关掉当前选中的那个侧栏标签页 |
|
package/harness.cjs
CHANGED
|
@@ -43,28 +43,6 @@ const installCore = (home) => {
|
|
|
43
43
|
for (const entry of ['main', 'ui']) cpSync(join(source, entry), join(core, entry), { recursive: true });
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
/** The homes a case has launched and not yet cleaned up. */
|
|
47
|
-
const running = new Set();
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The app the tests drive: the checkout's own Electron, on a home that already holds a Core. The window never
|
|
51
|
-
* comes to the front, so a run does not take the focus of whoever works at the machine.
|
|
52
|
-
*/
|
|
53
|
-
const launchApp = async (home, env) => {
|
|
54
|
-
const app = wangcaiApp();
|
|
55
|
-
installCore(home);
|
|
56
|
-
const desktop = await electron.launch({
|
|
57
|
-
executablePath: require(join(app, 'node_modules/electron')),
|
|
58
|
-
args: [join(app, 'desktop'), '--unfocused', `--user-data-dir=${join(home, 'electron')}`],
|
|
59
|
-
cwd: app,
|
|
60
|
-
env,
|
|
61
|
-
});
|
|
62
|
-
// Steps here take seconds; a shorter default keeps a stuck run from holding the window on screen.
|
|
63
|
-
desktop.context().setDefaultTimeout(15000);
|
|
64
|
-
running.add(home);
|
|
65
|
-
return desktop;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
46
|
/**
|
|
69
47
|
* The app loads only what init.ts lists, so a case names the plugins and where to read them from: a sibling checkout
|
|
70
48
|
* for an id alone, or whatever `directory` says. `repo` is left as written, for what installs from git.
|
|
@@ -84,6 +62,27 @@ const writeInit = (home, lists) => {
|
|
|
84
62
|
writeFileSync(join(home, '.config/wangcai/init.ts'), `export default { workspaces: [${list(workspaces)}], tabs: [${list(tabs)}] };\n`);
|
|
85
63
|
};
|
|
86
64
|
|
|
65
|
+
/** The homes a case has launched and not yet cleaned up. */
|
|
66
|
+
const running = new Set();
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The app the tests drive: the checkout's own Electron. The window never comes to the front, so a run does not take
|
|
70
|
+
* the focus of whoever works at the machine.
|
|
71
|
+
*/
|
|
72
|
+
const launchApp = async (home, env) => {
|
|
73
|
+
const app = wangcaiApp();
|
|
74
|
+
const desktop = await electron.launch({
|
|
75
|
+
executablePath: require(join(app, 'node_modules/electron')),
|
|
76
|
+
args: [join(app, 'desktop'), '--unfocused', `--user-data-dir=${join(home, 'electron')}`],
|
|
77
|
+
cwd: app,
|
|
78
|
+
env,
|
|
79
|
+
});
|
|
80
|
+
// Steps here take seconds; a shorter default keeps a stuck run from holding the window on screen.
|
|
81
|
+
desktop.context().setDefaultTimeout(15000);
|
|
82
|
+
running.add(home);
|
|
83
|
+
return desktop;
|
|
84
|
+
};
|
|
85
|
+
|
|
87
86
|
/** Tears a home down: the agent it started, the Electron on it, and the files themselves. */
|
|
88
87
|
const cleanup = (home) => {
|
|
89
88
|
// The agent outlives the window that asked for it, so the home it ran on is what stops it here.
|
|
@@ -96,9 +95,10 @@ const cleanup = (home) => {
|
|
|
96
95
|
|
|
97
96
|
// A run that is interrupted never reaches its own teardown, so the windows it left are stopped here instead of being
|
|
98
97
|
// left for the next run to meet.
|
|
99
|
-
|
|
98
|
+
const stopAll = () => { for (const home of running) cleanup(home); };
|
|
99
|
+
process.once('exit', stopAll);
|
|
100
100
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
101
|
-
process.once(signal, () => {
|
|
101
|
+
process.once(signal, () => { stopAll(); process.exit(signal === 'SIGINT' ? 130 : 143); });
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/** The terminal of the workspace in front. */
|
|
@@ -136,12 +136,13 @@ const viewTabs = (page) => page.locator('.sidebar-tab:visible');
|
|
|
136
136
|
const closeView = async (page) => page.locator('.sidebar-tab:has([aria-selected=true]) .close-tab').click();
|
|
137
137
|
|
|
138
138
|
/**
|
|
139
|
-
* One case: a home of its own, the plugins it lists, the window on them, and the teardown that follows
|
|
140
|
-
* body did.
|
|
139
|
+
* One case: a home of its own, the Core and the plugins it lists, the window on them, and the teardown that follows
|
|
140
|
+
* whatever the body did.
|
|
141
141
|
*/
|
|
142
142
|
const withWindow = async (prefix, lists, body) => {
|
|
143
143
|
const home = realpathSync(mkdtempSync(join(tmpdir(), `${prefix}-`)));
|
|
144
144
|
const env = testEnv(home);
|
|
145
|
+
installCore(home);
|
|
145
146
|
writeInit(home, lists);
|
|
146
147
|
let desktop;
|
|
147
148
|
try {
|
package/package.json
CHANGED