You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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).
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.
4
4
5
5
### Features
6
6
@@ -12,52 +12,20 @@ GraalVM enables you to use modern JavaScript features such as:
12
12
- Destructuring
13
13
- Classes
14
14
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:
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.
45
16
46
17
---
47
18
48
19
## Examples
49
20
50
21
For examples, see the `examples/graal` directory [in GitHub](https://github.com/outofcoffee/imposter/blob/main/examples/graal).
51
22
52
-
> **Note**
53
-
> Complete the prerequisites first.
54
-
55
23
### Simple example
56
24
57
-
Start the mock server with the `js-graal` engine:
25
+
Start the mock server:
58
26
59
27
```bash
60
-
imposter up examples/graal/simple -e IMPOSTER_JS_PLUGIN=js-graal
28
+
imposter up examples/graal/simple
61
29
```
62
30
63
31
Send a request to the mock server:
@@ -71,3 +39,9 @@ Hello Ada
71
39
### Advanced example
72
40
73
41
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.
0 commit comments