Skip to content

Commit 53c3ad7

Browse files
committed
docs: reference GraalVM as default JavaScript engine.
1 parent 25a4298 commit 53c3ad7

File tree

4 files changed

+78
-36
lines changed

4 files changed

+78
-36
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ To begin, check out the [Getting started](getting_started.md) guide. See the _Co
3838
- [Generating fake data](fake_data.md)
3939
- [CORS](cors.md)
4040
- [Groovy scripting tips](groovy_tips.md)
41+
- [JavaScript compatibility](scripting_modern_js.md)
4142
- [Examples](https://github.com/outofcoffee/imposter/tree/main/examples)
4243

4344
### Data capture and storage

docs/scripting_legacy_js.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Using legacy JavaScript engine (Nashorn)
2+
3+
The [default JavaScript engine is GraalVM](./scripting_modern_js.md), which is based on ECMAScript 2022 (more formally, [ECMA-262, 13th edition](https://262.ecma-international.org/13.0/)). Whilst GraalVM provides support for modern JavaScript features, it is more resource intensive than the legacy Nashorn JavaScript engine, which only supports ECMAScript 5 (ES5). You can switch to the Nashorn JavaScript engine using its plugin.
4+
5+
To use the Nashorn JavaScript engine, you need to be running Imposter v4.0.0 or later, and install the `js-nashorn` plugin.
6+
7+
## Install plugin
8+
9+
### Option 1: Using the CLI
10+
11+
> **Note**
12+
> This option requires the [Imposter CLI](./run_imposter_cli.md) version 0.37.0 or later.
13+
14+
To use this plugin, install it with the Imposter CLI:
15+
16+
imposter plugin install -d js-nashorn
17+
18+
This will install the plugin version matching the current engine version used by the CLI. The next time you run `imposter up`, the plugin will be available.
19+
20+
### Option 2: Install the plugin manually
21+
22+
To use this plugin, download the `imposter-plugin-js-nashorn.jar` JAR file from the [Releases page](https://github.com/outofcoffee/imposter/releases).
23+
24+
Enable it with the following environment variable:
25+
26+
IMPOSTER_PLUGIN_DIR="/path/to/dir/containing/plugin"
27+
28+
## Using the plugin
29+
30+
To use Nashorn, you need to specify the `js-nashorn` engine as the JavaScript plugin. You can do this by setting the environment variable `IMPOSTER_JS_PLUGIN` to `js-nashorn`:
31+
32+
```bash
33+
export IMPOSTER_JS_PLUGIN=js-nashorn
34+
```
35+
36+
---
37+
38+
## Example
39+
40+
> **Note**
41+
> Complete the prerequisites first.
42+
43+
Start the mock server with the `js-nashorn` engine:
44+
45+
```bash
46+
imposter up examples/rest/conditional-scripted -e IMPOSTER_JS_PLUGIN=js-nashorn
47+
```
48+
49+
Send a request to the mock server:
50+
51+
```bash
52+
curl -i http://localhost:8080/pets
53+
54+
[
55+
{
56+
"id": 1,
57+
"name": "Fluffy"
58+
},
59+
{
60+
"id": 2,
61+
"name": "Paws"
62+
}
63+
]
64+
```
65+
66+
* See the `examples/rest/conditional-scripted` directory [in GitHub](https://github.com/outofcoffee/imposter/blob/main/examples/rest/conditional-scripted).

docs/scripting_modern_js.md

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using modern JavaScript features in scripts
22

3-
The default JavaScript engine is Nashorn, which is based on ECMAScript 5.1. However, you can use modern JavaScript features by switching to the GraalVM JavaScript engine.
3+
The default JavaScript engine is GraalVM, which is based on ECMAScript 2022 (more formally, [ECMA-262, 13th edition](https://262.ecma-international.org/13.0/)). This means you can use modern JavaScript features from ECMAScript 2022 in your scripts.
44

55
### Features
66

@@ -12,52 +12,20 @@ GraalVM enables you to use modern JavaScript features such as:
1212
- Destructuring
1313
- Classes
1414

15-
To use the GraalVM JavaScript engine, you need to be running Imposter v3.35.0 or later, and install the `js-graal` plugin.
16-
17-
## Install plugin
18-
19-
### Option 1: Using the CLI
20-
21-
> **Note**
22-
> This option requires the [Imposter CLI](./run_imposter_cli.md) version 0.37.0 or later.
23-
24-
To use this plugin, install it with the Imposter CLI:
25-
26-
imposter plugin install -d js-graal:zip
27-
28-
This will install the plugin version matching the current engine version used by the CLI. The next time you run `imposter up`, the plugin will be available.
29-
30-
### Option 2: Install the plugin manually
31-
32-
To use this plugin, download the `imposter-plugin-js-graal.zip` ZIP file from the [Releases page](https://github.com/outofcoffee/imposter/releases).
33-
34-
Enable it with the following environment variable:
35-
36-
IMPOSTER_PLUGIN_DIR="/path/to/dir/containing/plugin"
37-
38-
## Using the plugin
39-
40-
To use GraalVM, you need to specify the `js-graal` engine as the JavaScript plugin. You can do this by setting the environment variable `IMPOSTER_JS_PLUGIN` to `js-graal`:
41-
42-
```bash
43-
export IMPOSTER_JS_PLUGIN=js-graal
44-
```
15+
To use the GraalVM JavaScript engine, you need to be running Imposter v4.0.0 or later.
4516

4617
---
4718

4819
## Examples
4920

5021
For examples, see the `examples/graal` directory [in GitHub](https://github.com/outofcoffee/imposter/blob/main/examples/graal).
5122

52-
> **Note**
53-
> Complete the prerequisites first.
54-
5523
### Simple example
5624

57-
Start the mock server with the `js-graal` engine:
25+
Start the mock server:
5826

5927
```bash
60-
imposter up examples/graal/simple -e IMPOSTER_JS_PLUGIN=js-graal
28+
imposter up examples/graal/simple
6129
```
6230

6331
Send a request to the mock server:
@@ -71,3 +39,9 @@ Hello Ada
7139
### Advanced example
7240

7341
See the `examples/graal/es6` [directory](https://github.com/outofcoffee/imposter/blob/main/examples/graal) for an example of using modern JavaScript features in a script.
42+
43+
---
44+
45+
## Further reading
46+
47+
- [Using legacy JavaScript engine (Nashorn)](scripting_legacy_js.md)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ nav:
4242
- Generating fake data: 'fake_data.md'
4343
- CORS: 'cors.md'
4444
- Groovy scripting tips: 'groovy_tips.md'
45+
- JavaScript compatibility: 'scripting_modern_js.md'
4546
- Examples: 'https://github.com/outofcoffee/imposter/tree/main/examples'
4647

4748
- Data capture and storage:

0 commit comments

Comments
 (0)