-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest.cjs
More file actions
57 lines (49 loc) · 1.53 KB
/
test.cjs
File metadata and controls
57 lines (49 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* CJS Require Test Fixture
*
* This file validates that the SDK can be required using CommonJS syntax.
* This is critical for:
* - Node.js < 22.12.0 (where require(ESM) is not enabled by default)
* - AWS Lambda (intentionally disables require(ESM))
* - Legacy Node.js applications
*/
// Test main export
const sdk = require("@trigger.dev/sdk");
// Test /v3 subpath
const sdkV3 = require("@trigger.dev/sdk/v3");
// Validate exports exist
const checks = [
["task", typeof sdk.task === "function"],
["taskV3", typeof sdkV3.task === "function"],
["logger", typeof sdk.logger === "object" && typeof sdk.logger.info === "function"],
["schedules", typeof sdk.schedules === "object"],
["runs", typeof sdk.runs === "object"],
["configure", typeof sdk.configure === "function"],
["queue", typeof sdk.queue === "function"],
["retry", typeof sdk.retry === "object"],
["wait", typeof sdk.wait === "object"],
["metadata", typeof sdk.metadata === "object"],
["tags", typeof sdk.tags === "object"],
];
let failed = false;
for (const [name, passed] of checks) {
if (!passed) {
console.error(`FAIL: ${name} export check failed`);
failed = true;
}
}
// Test task definition works
const myTask = sdk.task({
id: "cjs-test-task",
run: async (payload) => {
return { received: payload };
},
});
if (myTask.id !== "cjs-test-task") {
console.error(`FAIL: task.id mismatch: expected "cjs-test-task", got "${myTask.id}"`);
failed = true;
}
if (failed) {
process.exit(1);
}
console.log("SUCCESS: All CJS requires validated");