@durable-streams/server-conformance-tests 0.1.1 → 0.1.3
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/dist/chunk-BCwAaXi7.cjs +31 -0
- package/dist/cli.cjs +223 -0
- package/dist/cli.d.cts +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.js +1 -1
- package/dist/src-DK3GDgwo.cjs +2480 -0
- package/dist/{src-DRIMnUPk.js → src-DcbQ_SIQ.js} +147 -0
- package/dist/test-runner.cjs +9 -0
- package/dist/test-runner.d.cts +1 -0
- package/dist/test-runner.js +1 -1
- package/package.json +20 -11
- package/src/index.ts +254 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
|
|
26
|
+
Object.defineProperty(exports, '__toESM', {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return __toESM;
|
|
30
|
+
}
|
|
31
|
+
});
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
const require_chunk = require('./chunk-BCwAaXi7.cjs');
|
|
4
|
+
const node_child_process = require_chunk.__toESM(require("node:child_process"));
|
|
5
|
+
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
6
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
7
|
+
const node_url = require_chunk.__toESM(require("node:url"));
|
|
8
|
+
|
|
9
|
+
//#region src/cli.ts
|
|
10
|
+
const __dirname$1 = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
11
|
+
function printUsage() {
|
|
12
|
+
console.log(`
|
|
13
|
+
Durable Streams Conformance Test Runner
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
npx @durable-streams/server-conformance-tests --run <url>
|
|
17
|
+
npx @durable-streams/server-conformance-tests --watch <path> [path...] <url>
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--run Run tests once and exit (for CI)
|
|
21
|
+
--watch <paths> Watch source paths and rerun tests on changes (for development)
|
|
22
|
+
--help, -h Show this help message
|
|
23
|
+
|
|
24
|
+
Arguments:
|
|
25
|
+
<url> Base URL of the Durable Streams server to test against
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
# Run tests once in CI
|
|
29
|
+
npx @durable-streams/server-conformance-tests --run http://localhost:4473
|
|
30
|
+
|
|
31
|
+
# Watch src directory and rerun tests on changes
|
|
32
|
+
npx @durable-streams/server-conformance-tests --watch src http://localhost:4473
|
|
33
|
+
|
|
34
|
+
# Watch multiple directories
|
|
35
|
+
npx @durable-streams/server-conformance-tests --watch src lib http://localhost:4473
|
|
36
|
+
`);
|
|
37
|
+
}
|
|
38
|
+
function parseArgs(args) {
|
|
39
|
+
const result = {
|
|
40
|
+
mode: `run`,
|
|
41
|
+
watchPaths: [],
|
|
42
|
+
baseUrl: ``,
|
|
43
|
+
help: false
|
|
44
|
+
};
|
|
45
|
+
let i = 0;
|
|
46
|
+
while (i < args.length) {
|
|
47
|
+
const arg = args[i];
|
|
48
|
+
if (arg === `--help` || arg === `-h`) {
|
|
49
|
+
result.help = true;
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
if (arg === `--run`) {
|
|
53
|
+
result.mode = `run`;
|
|
54
|
+
i++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (arg === `--watch`) {
|
|
58
|
+
result.mode = `watch`;
|
|
59
|
+
i++;
|
|
60
|
+
while (i < args.length - 1) {
|
|
61
|
+
const next = args[i];
|
|
62
|
+
if (next.startsWith(`--`) || next.startsWith(`-`)) break;
|
|
63
|
+
result.watchPaths.push(next);
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!arg.startsWith(`-`)) result.baseUrl = arg;
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function validateArgs(args) {
|
|
74
|
+
if (!args.baseUrl) return `Error: Base URL is required`;
|
|
75
|
+
try {
|
|
76
|
+
new URL(args.baseUrl);
|
|
77
|
+
} catch {
|
|
78
|
+
return `Error: Invalid URL "${args.baseUrl}"`;
|
|
79
|
+
}
|
|
80
|
+
if (args.mode === `watch` && args.watchPaths.length === 0) return `Error: --watch requires at least one path to watch`;
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function getTestRunnerPath() {
|
|
84
|
+
const runnerInDist = (0, node_path.join)(__dirname$1, `test-runner.js`);
|
|
85
|
+
const runnerInSrc = (0, node_path.join)(__dirname$1, `test-runner.ts`);
|
|
86
|
+
if ((0, node_fs.existsSync)(runnerInDist)) return runnerInDist;
|
|
87
|
+
return runnerInSrc;
|
|
88
|
+
}
|
|
89
|
+
function runTests(baseUrl) {
|
|
90
|
+
return new Promise((resolvePromise) => {
|
|
91
|
+
const runnerPath = getTestRunnerPath();
|
|
92
|
+
const vitestBin = (0, node_path.join)(__dirname$1, `..`, `node_modules`, `.bin`, `vitest`);
|
|
93
|
+
const vitestBinAlt = (0, node_path.join)(__dirname$1, `..`, `..`, `..`, `node_modules`, `.bin`, `vitest`);
|
|
94
|
+
let vitestPath = `vitest`;
|
|
95
|
+
if ((0, node_fs.existsSync)(vitestBin)) vitestPath = vitestBin;
|
|
96
|
+
else if ((0, node_fs.existsSync)(vitestBinAlt)) vitestPath = vitestBinAlt;
|
|
97
|
+
const args = [
|
|
98
|
+
`run`,
|
|
99
|
+
runnerPath,
|
|
100
|
+
`--no-coverage`,
|
|
101
|
+
`--reporter=default`,
|
|
102
|
+
`--passWithNoTests=false`
|
|
103
|
+
];
|
|
104
|
+
const child = (0, node_child_process.spawn)(vitestPath, args, {
|
|
105
|
+
stdio: `inherit`,
|
|
106
|
+
env: {
|
|
107
|
+
...process.env,
|
|
108
|
+
CONFORMANCE_TEST_URL: baseUrl,
|
|
109
|
+
FORCE_COLOR: `1`
|
|
110
|
+
},
|
|
111
|
+
shell: true
|
|
112
|
+
});
|
|
113
|
+
child.on(`close`, (code) => {
|
|
114
|
+
resolvePromise(code ?? 1);
|
|
115
|
+
});
|
|
116
|
+
child.on(`error`, (err) => {
|
|
117
|
+
console.error(`Failed to run tests: ${err.message}`);
|
|
118
|
+
resolvePromise(1);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function runOnce(baseUrl) {
|
|
123
|
+
console.log(`Running conformance tests against ${baseUrl}\n`);
|
|
124
|
+
const exitCode = await runTests(baseUrl);
|
|
125
|
+
process.exit(exitCode);
|
|
126
|
+
}
|
|
127
|
+
async function runWatch(baseUrl, watchPaths) {
|
|
128
|
+
let runningProcess = null;
|
|
129
|
+
let debounceTimer = null;
|
|
130
|
+
const DEBOUNCE_MS = 300;
|
|
131
|
+
const spawnTests = () => {
|
|
132
|
+
const runnerPath = getTestRunnerPath();
|
|
133
|
+
const vitestBin = (0, node_path.join)(__dirname$1, `..`, `node_modules`, `.bin`, `vitest`);
|
|
134
|
+
const vitestBinAlt = (0, node_path.join)(__dirname$1, `..`, `..`, `..`, `node_modules`, `.bin`, `vitest`);
|
|
135
|
+
let vitestPath = `vitest`;
|
|
136
|
+
if ((0, node_fs.existsSync)(vitestBin)) vitestPath = vitestBin;
|
|
137
|
+
else if ((0, node_fs.existsSync)(vitestBinAlt)) vitestPath = vitestBinAlt;
|
|
138
|
+
const args = [
|
|
139
|
+
`run`,
|
|
140
|
+
runnerPath,
|
|
141
|
+
`--no-coverage`,
|
|
142
|
+
`--reporter=default`,
|
|
143
|
+
`--passWithNoTests=false`
|
|
144
|
+
];
|
|
145
|
+
return (0, node_child_process.spawn)(vitestPath, args, {
|
|
146
|
+
stdio: `inherit`,
|
|
147
|
+
env: {
|
|
148
|
+
...process.env,
|
|
149
|
+
CONFORMANCE_TEST_URL: baseUrl,
|
|
150
|
+
FORCE_COLOR: `1`
|
|
151
|
+
},
|
|
152
|
+
shell: true
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const runTestsDebounced = () => {
|
|
156
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
157
|
+
debounceTimer = setTimeout(() => {
|
|
158
|
+
if (runningProcess) {
|
|
159
|
+
runningProcess.kill(`SIGTERM`);
|
|
160
|
+
runningProcess = null;
|
|
161
|
+
}
|
|
162
|
+
console.clear();
|
|
163
|
+
console.log(`Running conformance tests against ${baseUrl}\n`);
|
|
164
|
+
runningProcess = spawnTests();
|
|
165
|
+
runningProcess.on(`close`, (code) => {
|
|
166
|
+
if (code === 0) console.log(`\nAll tests passed`);
|
|
167
|
+
else console.log(`\nTests failed (exit code: ${code})`);
|
|
168
|
+
console.log(`\nWatching for changes in: ${watchPaths.join(`, `)}`);
|
|
169
|
+
console.log(`Press Ctrl+C to exit\n`);
|
|
170
|
+
runningProcess = null;
|
|
171
|
+
});
|
|
172
|
+
}, DEBOUNCE_MS);
|
|
173
|
+
};
|
|
174
|
+
const watchers = [];
|
|
175
|
+
for (const watchPath of watchPaths) {
|
|
176
|
+
const absPath = (0, node_path.resolve)(process.cwd(), watchPath);
|
|
177
|
+
try {
|
|
178
|
+
const watcher = (0, node_fs.watch)(absPath, { recursive: true }, (eventType, filename) => {
|
|
179
|
+
if (filename && !filename.includes(`node_modules`)) {
|
|
180
|
+
console.log(`\nChange detected: ${filename}`);
|
|
181
|
+
runTestsDebounced();
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
watchers.push(watcher);
|
|
185
|
+
console.log(`Watching: ${absPath}`);
|
|
186
|
+
} catch (err) {
|
|
187
|
+
console.error(`Warning: Could not watch "${watchPath}": ${err.message}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (watchers.length === 0) {
|
|
191
|
+
console.error(`Error: No valid paths to watch`);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
process.on(`SIGINT`, () => {
|
|
195
|
+
console.log(`\n\nStopping watch mode...`);
|
|
196
|
+
watchers.forEach((w) => w.close());
|
|
197
|
+
if (runningProcess) runningProcess.kill(`SIGTERM`);
|
|
198
|
+
process.exit(0);
|
|
199
|
+
});
|
|
200
|
+
runTestsDebounced();
|
|
201
|
+
await new Promise(() => {});
|
|
202
|
+
}
|
|
203
|
+
async function main() {
|
|
204
|
+
const args = parseArgs(process.argv.slice(2));
|
|
205
|
+
if (args.help) {
|
|
206
|
+
printUsage();
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
const error = validateArgs(args);
|
|
210
|
+
if (error) {
|
|
211
|
+
console.error(error);
|
|
212
|
+
console.error(`\nRun with --help for usage information`);
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
215
|
+
if (args.mode === `watch`) await runWatch(args.baseUrl, args.watchPaths);
|
|
216
|
+
else await runOnce(args.baseUrl);
|
|
217
|
+
}
|
|
218
|
+
main().catch((err) => {
|
|
219
|
+
console.error(`Fatal error: ${err.message}`);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface ConformanceTestOptions {
|
|
3
|
+
/** Base URL of the server to test */
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run the full conformance test suite against a server
|
|
8
|
+
*/
|
|
9
|
+
declare function runConformanceTests(options: ConformanceTestOptions): void; //#endregion
|
|
10
|
+
export { ConformanceTestOptions, runConformanceTests };
|
package/dist/index.js
CHANGED