# K6Resource.WithScript

- Module: [CommunityToolkit.Aspire.Hosting.k6](/reference/api/go/communitytoolkit.aspire.hosting.k6.md)
- Defined on: [K6Resource](/reference/api/go/communitytoolkit.aspire.hosting.k6/k6resource.md)
- Version: `13.6.1`
- Kind: `method`

Runs a k6 JS script when starting the Grafana k6 container resource.

## Remarks

`--vus` and `--duration` are the k6 CLI shorthand for a single constant-VU scenario and take precedence over the script's `options.scenarios`.
Leave them `null` when the script defines its own scenarios or executors.
Add a Grafana k6 container to the application model and reference it in a .NET project.
Additionally, in this example a script runs when the container starts.
```
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.Api>("api");
var k6 = builder.AddK6("k6")
.WithBindMount("scripts", "/scripts", true)
.WithScript("/scripts/main.js")
.WithReference(api)
.WaitFor(api);
builder.Build().Run();
```

## Definition

```go
type K6Resource interface {
    // ... omitted for brevity
    WithScript(
        scriptPath string,
        options ...*WithScriptOptions,
    ) K6Resource
}
```

## Signature

```go
WithScript(
    scriptPath string,
    options ...*WithScriptOptions,
) K6Resource
```

## Parameters

- `scriptPath` (`string`) -- The path to the JS script to run.
- `options` (`...*WithScriptOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithScriptOptions` argument.

- `VirtualUsers` (`*float64`) -- The number of virtual users for the test..
- `Duration` (`*string`) -- The duration of the test, e.g. `30s`.
- `SummaryMode` ([`*K6SummaryMode`](/reference/api/go/communitytoolkit.aspire.hosting.k6/k6summarymode.md)) -- The summary mode of the test execution.

## Returns

[`K6Resource`](/reference/api/go/communitytoolkit.aspire.hosting.k6/k6resource.md) -- The `IResourceBuilder`.

Returns a handle; failures surface later via `Err()`.

## Defined on

- [K6Resource](/reference/api/go/communitytoolkit.aspire.hosting.k6/k6resource.md) -- `handle`
