Skip to content

Commit 52eaca9

Browse files
committed
feat: add typescript compilation on build
1 parent bb507ee commit 52eaca9

36 files changed

+591
-97
lines changed

.github/workflows/build.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ jobs:
3535
- name: Build JVM code samples
3636
run: sbt "all headerCheckAll scalafmtSbtCheck" "test"
3737

38-
- name: Setup Hugo
39-
uses: peaceiris/actions-hugo@v3
40-
with:
41-
hugo-version: '0.135.0'
42-
extended: true
43-
4438
- name: Setup Node
4539
uses: actions/setup-node@v4
4640
with:
4741
node-version: '20'
4842
cache: 'npm'
4943

44+
- name: Setup Hugo
45+
uses: peaceiris/actions-hugo@v3
46+
with:
47+
hugo-version: '0.135.0'
48+
extended: true
49+
5050
- name: Generate site
5151
run: ./bin/entrypoint.sh generate
52+
53+
- name: Build TypeScript code samples
54+
run: npm run test-ts-samples

config/_default/params.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ languages:
4646
default: java
4747
labels:
4848
- java: Java
49-
- js: JavaScript
49+
- ts: JavaScript
5050
- kt: Kotlin
5151
- scala: Scala
5252

content/guides/debugging/code/ComputerDatabaseSampleJS.js content/guides/debugging/code/ComputerDatabaseSampleJS.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { scenario } from "@gatling.io/core";
18+
19+
scenario("scenario")
1720
//#print-session-value
1821
.exec((session) => {
1922
console.log(session.get("addComputer"));

content/guides/passing-parameters/code/PassingParametersSampleJs.js content/guides/passing-parameters/code/PassingParametersSampleJs.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import { SetUpFunction, rampUsers, scenario } from "@gatling.io/core";
2+
3+
const scn = scenario("scenario");
4+
const setUp = null as unknown as SetUpFunction;
5+
16
//#injection-from-options
27
import { getParameter } from "@gatling.io/core";
38

content/guides/passing-parameters/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ npx gatling run users=500 ramp=3600
3232

3333
You can resolve these options directly in your code with the `getParameter` function:
3434

35-
{{< include-code "injection-from-options" js >}}
35+
{{< include-code "injection-from-options" ts >}}
3636

3737
We also provide a `getEnvironmentVariable` function to read environment variables:
3838

39-
{{< include-code "injection-from-env-vars" js >}}
39+
{{< include-code "injection-from-env-vars" ts >}}

content/reference/glossary/code/ConceptsIntroductionSampleJS.js content/reference/glossary/code/ConceptsIntroductionSampleJS.ts

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
SetUpFunction,
19+
atOnceUsers,
20+
nothingFor,
21+
pause,
22+
rampUsers,
23+
scenario,
24+
simulation
25+
} from "@gatling.io/core";
26+
import { http } from "@gatling.io/http";
27+
28+
const setUp = null as unknown as SetUpFunction;
29+
1730
//#dsl-bad
1831
for (let i = 0; i < 5; i++) {
1932
http("Access Github").get("https://github.com");

content/reference/script/core/assertions/code/AssertionSampleJS.js content/reference/script/core/assertions/code/AssertionSampleJS.ts

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
SetUpFunction,
19+
atOnceUsers,
20+
details,
21+
forAll,
22+
global,
23+
scenario,
24+
simulation,
25+
} from "@gatling.io/core";
26+
27+
const scn = scenario("scenario");
28+
const injectionProfile = atOnceUsers(1);
29+
30+
const setUp = null as unknown as SetUpFunction;
31+
1732
//#setUp
1833
setUp(scn.injectOpen(injectionProfile))
1934
.assertions(

content/reference/script/core/checks/code/CheckSampleJS.js content/reference/script/core/checks/code/CheckSampleJS.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
ElFileBody,
19+
RawFileBody,
20+
bodyBytes,
21+
bodyLength,
22+
bodyString,
23+
css,
24+
form,
25+
jmesPath,
26+
jsonPath,
27+
md5,
28+
regex,
29+
responseTimeInMillis,
30+
sha1,
31+
substring,
32+
xpath
33+
} from "@gatling.io/core";
34+
import { http, status } from "@gatling.io/http";
35+
1736
//#status-is-200
1837
http("Gatling").get("https://gatling.io")
1938
.check(status().is(200))
@@ -41,7 +60,7 @@ http("").get("")
4160

4261
//#bodyBytes
4362
.check(
44-
bodyBytes().is("{\"foo\": \"bar\"}".getBytes(StandardCharsets.UTF_8)),
63+
bodyBytes().is([123,34,102,111,111,34,58,32,34,98,97,114,34,125]), // Bytes array
4564
bodyBytes().is(RawFileBody("expected.json"))
4665
)
4766
//#bodyBytes
@@ -351,14 +370,18 @@ NOT SUPPORTED
351370
const prefix = session.get("prefix");
352371
if (actual == null) {
353372
throw Error("Value is missing");
354-
} else if (!actual.startsWith(prefix)) {
355-
throw Error("Value " + actual + " should start with " + prefix);
373+
} else {
374+
// @ts-ignore
375+
if (!actual.startsWith(prefix)) {
376+
throw Error("Value " + actual + " should start with " + prefix);
377+
}
356378
}
357379
return actual;
358380
})
359381
)
360382
//#validator
361383

384+
http("").get("")
362385
//#name
363386
.check(
364387
jmesPath("foo").name("My custom error message")

content/reference/script/core/injection/code/InjectionSampleJS.js content/reference/script/core/injection/code/InjectionSampleJS.ts

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
SetUpFunction,
19+
atOnceUsers,
20+
constantConcurrentUsers,
21+
constantUsersPerSec,
22+
incrementConcurrentUsers,
23+
incrementUsersPerSec,
24+
nothingFor,
25+
rampConcurrentUsers,
26+
rampUsers,
27+
rampUsersPerSec,
28+
scenario,
29+
stressPeakUsers
30+
} from "@gatling.io/core";
31+
import { http } from "@gatling.io/http";
32+
33+
const setUp = null as unknown as SetUpFunction;
1734

1835
const httpProtocol = http;
1936
const scn = scenario("scenario");

content/reference/script/core/scenario/code/ScenarioSampleJS.js content/reference/script/core/scenario/code/ScenarioSampleJS.ts

+40
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,46 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
asLongAs,
19+
asLongAsDuring,
20+
crashLoadGenerator,
21+
crashLoadGeneratorIf,
22+
doIf,
23+
doIfEquals,
24+
doIfEqualsOrElse,
25+
doIfOrElse,
26+
doWhile,
27+
doWhileDuring,
28+
doSwitch,
29+
doSwitchOrElse,
30+
dummy,
31+
during,
32+
exitBlockOnFail,
33+
exitHere,
34+
exitHereIf,
35+
exitHereIfFailed,
36+
foreach,
37+
forever,
38+
group,
39+
onCase,
40+
pace,
41+
pause,
42+
percent,
43+
exec,
44+
randomSwitch,
45+
randomSwitchOrElse,
46+
rendezVous,
47+
repeat,
48+
roundRobinSwitch,
49+
scenario,
50+
stopLoadGenerator,
51+
stopLoadGeneratorIf,
52+
tryMax,
53+
uniformRandomSwitch
54+
} from "@gatling.io/core";
55+
import { http } from "@gatling.io/http";
56+
1757
//#bootstrapping
1858
const scn = scenario("Scenario");
1959
//#bootstrapping

content/reference/script/core/session/api/code/SessionSampleJS.js content/reference/script/core/session/api/code/SessionSampleJS.ts

+30-22
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Session, exec } from "@gatling.io/core";
18+
19+
const session = null as unknown as Session;
20+
1721
//#sessions-are-immutable
1822
// wrong usage: result from Session#set is discarded
1923
exec((session) => {
@@ -28,18 +32,20 @@ exec((session) => {
2832
});
2933
//#sessions-are-immutable
3034

31-
//#set
32-
// set one single attribute
33-
const newSession1 = session.set("key", "whateverValue");
34-
// set multiple attributes
35-
const newSession2 = session.setAll({ "key": "value" });
36-
// remove one single attribute
37-
const newSession3 = session.remove("key");
38-
// remove multiple attributes
39-
const newSession4 = session.removeAll("key1", "key2");
40-
// remove all non Gatling internal attributes
41-
const newSession5 = session.reset();
42-
//#set
35+
const set = () => {
36+
//#set
37+
// set one single attribute
38+
const newSession1 = session.set("key", "whateverValue");
39+
// set multiple attributes
40+
const newSession2 = session.setAll({ "key": "value" });
41+
// remove one single attribute
42+
const newSession3 = session.remove("key");
43+
// remove multiple attributes
44+
const newSession4 = session.removeAll("key1", "key2");
45+
// remove all non Gatling internal attributes
46+
const newSession5 = session.reset();
47+
//#set
48+
};
4349

4450
//#get
4551
// check if an attribute is stored in the session
@@ -58,13 +64,15 @@ const scenario = session.scenario();
5864
const groups = session.groups();
5965
//#properties
6066

61-
//#state
62-
// return true if the virtual user has experienced a failure before this point
63-
const failed = session.isFailed();
64-
// reset the state to success
65-
// so that interrupt mechanisms such as exitHereIfFailed don't trigger
66-
const newSession1 = session.markAsSucceeded();
67-
// force the state to failure
68-
// so that interrupt mechanisms such as exitHereIfFailed do trigger
69-
const newSession2 = session.markAsFailed();
70-
//#state
67+
const state = () => {
68+
//#state
69+
// return true if the virtual user has experienced a failure before this point
70+
const failed = session.isFailed();
71+
// reset the state to success
72+
// so that interrupt mechanisms such as exitHereIfFailed don't trigger
73+
const newSession1 = session.markAsSucceeded();
74+
// force the state to failure
75+
// so that interrupt mechanisms such as exitHereIfFailed do trigger
76+
const newSession2 = session.markAsFailed();
77+
//#state
78+
};

content/reference/script/core/session/feeders/code/FeederSampleJS.js content/reference/script/core/session/feeders/code/FeederSampleJS.ts

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {
18+
FeederBuilder,
19+
arrayFeeder,
20+
csv,
21+
feed,
22+
jsonFile,
23+
jsonUrl,
24+
separatedValues,
25+
ssv,
26+
tsv
27+
} from "@gatling.io/core";
28+
29+
const feeder = null as unknown as FeederBuilder<string>;
30+
1731
/*
1832
//#random-mail-generator
1933
The `feeder(Iterator)` method is currently not supported by Gatling JS.

content/reference/script/core/session/functions/code/FunctionSampleJS.js content/reference/script/core/session/functions/code/FunctionSampleJS.ts

+4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { exec } from "@gatling.io/core";
18+
import { http } from "@gatling.io/http";
19+
1720
//#function-sample
1821
// inline usage with a lambda
1922
exec(http("name")
23+
// @ts-ignore
2024
.get((session) => "/foo/" + session.get("param").toLocaleLowerCase()));
2125

2226
// passing a reference to a function

0 commit comments

Comments
 (0)