Skip to content

Commit 27ae00a

Browse files
authored
New Components - testlocally (#16901)
* new components * pnpm-lock.yaml * fix browser & viewport props
1 parent 9f6508a commit 27ae00a

File tree

9 files changed

+563
-8
lines changed

9 files changed

+563
-8
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import testlocally from "../../testlocally.app.mjs";
2+
3+
export default {
4+
key: "testlocally-get-test",
5+
name: "Get Test",
6+
description: "Get details of a specific test in TestLocally. [See the documentation](https://testlocally.readme.io/reference/api_v0_test_results)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
testlocally,
11+
testId: {
12+
propDefinition: [
13+
testlocally,
14+
"testId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.testlocally.getTest({
20+
$,
21+
testId: this.testId,
22+
});
23+
$.export("$summary", `Retrieved test with ID ${this.testId}`);
24+
return response;
25+
},
26+
};
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import testlocally from "../../testlocally.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
name: "List Tests",
6+
description: "Returns a list of tests in TestLocally. [See the documentation](https://testlocally.readme.io/reference/api_v0_recent_tests)",
7+
key: "testlocally-list-tests",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
testlocally,
12+
start: {
13+
type: "string",
14+
label: "Start",
15+
description: "The start time specification. Example: `1 month ago`",
16+
optional: true,
17+
},
18+
end: {
19+
type: "string",
20+
label: "End",
21+
description: "The end time specification. Example: `now`",
22+
optional: true,
23+
},
24+
owners: {
25+
propDefinition: [
26+
testlocally,
27+
"owners",
28+
],
29+
},
30+
locations: {
31+
propDefinition: [
32+
testlocally,
33+
"locations",
34+
],
35+
},
36+
target: {
37+
propDefinition: [
38+
testlocally,
39+
"target",
40+
],
41+
},
42+
scheduled: {
43+
propDefinition: [
44+
testlocally,
45+
"scheduled",
46+
],
47+
},
48+
browser: {
49+
propDefinition: [
50+
testlocally,
51+
"browser",
52+
],
53+
},
54+
viewport: {
55+
propDefinition: [
56+
testlocally,
57+
"viewport",
58+
],
59+
},
60+
maxResults: {
61+
type: "integer",
62+
label: "Max Results",
63+
description: "The maximum number of tests to retrieve",
64+
default: 100,
65+
optional: true,
66+
},
67+
},
68+
async run({ $ }) {
69+
const results = this.testlocally.paginate({
70+
fn: this.testlocally.listTests,
71+
args: {
72+
$,
73+
params: {
74+
start: this.start,
75+
end: this.end,
76+
owners: parseObject(this.owners),
77+
locations: parseObject(this.locations),
78+
target: this.target,
79+
scheduled: this.scheduled,
80+
browser: this.browser,
81+
viewport: this.viewport,
82+
},
83+
},
84+
max: this.maxResults,
85+
});
86+
87+
const tests = [];
88+
for await (const test of results) {
89+
tests.push(test);
90+
}
91+
92+
$.export("$summary", `Retrieved ${tests.length || 0} test${tests.length === 1
93+
? ""
94+
: "s"}`);
95+
return tests;
96+
},
97+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import testlocally from "../../testlocally.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "testlocally-run-test",
6+
name: "Run Test",
7+
description: "Create and run a new test in TestLocally. [See the documentation](https://testlocally.readme.io/reference/api_v0_request_test)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
testlocally,
12+
target: {
13+
type: "string",
14+
label: "Target",
15+
description: "The URL to test",
16+
},
17+
browser: {
18+
propDefinition: [
19+
testlocally,
20+
"browser",
21+
],
22+
description: "The browser to use for the test",
23+
},
24+
viewport: {
25+
propDefinition: [
26+
testlocally,
27+
"viewport",
28+
],
29+
description: "The viewport to use for the test",
30+
},
31+
servers: {
32+
propDefinition: [
33+
testlocally,
34+
"servers",
35+
],
36+
},
37+
headers: {
38+
type: "object",
39+
label: "Headers",
40+
description: "Additional headers to send with the request",
41+
optional: true,
42+
},
43+
skipCompression: {
44+
type: "boolean",
45+
label: "Skip Compression",
46+
description: "Whether to skip compression for the test",
47+
optional: true,
48+
},
49+
clicks: {
50+
type: "string[]",
51+
label: "Clicks",
52+
description: "Define CSS selector to click before the screenshot is taken. Example: `.cookie-banner button`",
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
const response = await this.testlocally.runTest({
58+
$,
59+
data: {
60+
target: this.target,
61+
browser: this.browser,
62+
viewport: this.viewport,
63+
servers: parseObject(this.servers),
64+
headers: parseObject(this.headers),
65+
skipCompression: this.skipCompression,
66+
clicks: parseObject(this.clicks),
67+
},
68+
});
69+
$.export("$summary", `Created test with ID ${response.id}`);
70+
return response;
71+
},
72+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function parseObject(obj) {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
return obj;
13+
}
14+

components/testlocally/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/testlocally",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream TestLocally Components",
55
"main": "testlocally.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import testlocally from "../../testlocally.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
import { parseObject } from "../../common/utils.mjs";
4+
import sampleEmit from "./test-event.mjs";
5+
6+
export default {
7+
key: "testlocally-new-test-run",
8+
name: "New Test Run",
9+
description: "Emit new event when a new test is run or completed in TestLocally. [See the documentation](https://testlocally.readme.io/reference/api_v0_recent_tests)",
10+
version: "0.0.1",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
testlocally,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
owners: {
23+
propDefinition: [
24+
testlocally,
25+
"owners",
26+
],
27+
},
28+
locations: {
29+
propDefinition: [
30+
testlocally,
31+
"locations",
32+
],
33+
},
34+
target: {
35+
propDefinition: [
36+
testlocally,
37+
"target",
38+
],
39+
},
40+
scheduled: {
41+
propDefinition: [
42+
testlocally,
43+
"scheduled",
44+
],
45+
},
46+
browser: {
47+
propDefinition: [
48+
testlocally,
49+
"browser",
50+
],
51+
},
52+
viewport: {
53+
propDefinition: [
54+
testlocally,
55+
"viewport",
56+
],
57+
},
58+
},
59+
methods: {
60+
_getLastTs() {
61+
return this.db.get("lastTs") || 0;
62+
},
63+
_setLastTs(ts) {
64+
this.db.set("lastTs", ts);
65+
},
66+
generateMeta(test) {
67+
return {
68+
id: test.id,
69+
summary: `New Test Run ID: ${test.id}`,
70+
ts: test.created,
71+
};
72+
},
73+
async processEvent(max) {
74+
const lastTs = this._getLastTs();
75+
const results = this.testlocally.paginate({
76+
fn: this.testlocally.listTests,
77+
args: {
78+
params: {
79+
owners: parseObject(this.owners),
80+
locations: parseObject(this.locations),
81+
target: this.target,
82+
scheduled: this.scheduled,
83+
browser: this.browser,
84+
viewport: this.viewport,
85+
},
86+
},
87+
max,
88+
});
89+
90+
const tests = [];
91+
for await (const test of results) {
92+
if (test.created > lastTs) {
93+
tests.push(test);
94+
} else {
95+
break;
96+
}
97+
}
98+
99+
if (!tests.length) {
100+
return;
101+
}
102+
103+
this._setLastTs(tests[0].created);
104+
105+
tests.reverse().forEach((test) => {
106+
const meta = this.generateMeta(test);
107+
this.$emit(test, meta);
108+
});
109+
},
110+
},
111+
hooks: {
112+
async deploy() {
113+
await this.processEvent(25);
114+
},
115+
},
116+
async run() {
117+
await this.processEvent();
118+
},
119+
sampleEmit,
120+
};

0 commit comments

Comments
 (0)