Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: loadSources function #1957

Merged
merged 12 commits into from
Mar 21, 2022
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
### Changed
- Switch from `colors` to `chalk` for terminal coloring ([#1895](https://github.com/cucumber/cucumber-js/pull/1895))

### Deprecated

- `parseGherkinMessageStream` is deprecated in favour of `loadSources` ([#1957](https://github.com/cucumber/cucumber-js/pull/1957))

## [8.0.0-rc.2] - 2022-01-10
### Added
- Export cucumber version number. It is now possible to retrieve the current version
Expand Down
11 changes: 11 additions & 0 deletions docs/api/cucumber.iloadsourcesresult.errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ILoadSourcesResult](./cucumber.iloadsourcesresult.md) &gt; [errors](./cucumber.iloadsourcesresult.errors.md)

## ILoadSourcesResult.errors property

<b>Signature:</b>

```typescript
errors: ISourcesError[];
```
20 changes: 20 additions & 0 deletions docs/api/cucumber.iloadsourcesresult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ILoadSourcesResult](./cucumber.iloadsourcesresult.md)

## ILoadSourcesResult interface


<b>Signature:</b>

```typescript
export interface ILoadSourcesResult
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [errors](./cucumber.iloadsourcesresult.errors.md) | [ISourcesError](./cucumber.isourceserror.md)<!-- -->\[\] | |
| [plan](./cucumber.iloadsourcesresult.plan.md) | [IPlannedPickle](./cucumber.iplannedpickle.md)<!-- -->\[\] | |

11 changes: 11 additions & 0 deletions docs/api/cucumber.iloadsourcesresult.plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ILoadSourcesResult](./cucumber.iloadsourcesresult.md) &gt; [plan](./cucumber.iloadsourcesresult.plan.md)

## ILoadSourcesResult.plan property

<b>Signature:</b>

```typescript
plan: IPlannedPickle[];
```
14 changes: 14 additions & 0 deletions docs/api/cucumber.iplannedpickle.location.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [IPlannedPickle](./cucumber.iplannedpickle.md) &gt; [location](./cucumber.iplannedpickle.location.md)

## IPlannedPickle.location property

<b>Signature:</b>

```typescript
location: {
line: number;
column?: number;
};
```
21 changes: 21 additions & 0 deletions docs/api/cucumber.iplannedpickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [IPlannedPickle](./cucumber.iplannedpickle.md)

## IPlannedPickle interface


<b>Signature:</b>

```typescript
export interface IPlannedPickle
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [location](./cucumber.iplannedpickle.location.md) | { line: number; column?: number; } | |
| [name](./cucumber.iplannedpickle.name.md) | string | |
| [uri](./cucumber.iplannedpickle.uri.md) | string | |

11 changes: 11 additions & 0 deletions docs/api/cucumber.iplannedpickle.name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [IPlannedPickle](./cucumber.iplannedpickle.md) &gt; [name](./cucumber.iplannedpickle.name.md)

## IPlannedPickle.name property

<b>Signature:</b>

```typescript
name: string;
```
11 changes: 11 additions & 0 deletions docs/api/cucumber.iplannedpickle.uri.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [IPlannedPickle](./cucumber.iplannedpickle.md) &gt; [uri](./cucumber.iplannedpickle.uri.md)

## IPlannedPickle.uri property

<b>Signature:</b>

```typescript
uri: string;
```
14 changes: 14 additions & 0 deletions docs/api/cucumber.isourceserror.location.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ISourcesError](./cucumber.isourceserror.md) &gt; [location](./cucumber.isourceserror.location.md)

## ISourcesError.location property

<b>Signature:</b>

```typescript
location: {
line: number;
column?: number;
};
```
21 changes: 21 additions & 0 deletions docs/api/cucumber.isourceserror.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ISourcesError](./cucumber.isourceserror.md)

## ISourcesError interface


<b>Signature:</b>

```typescript
export interface ISourcesError
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [location](./cucumber.isourceserror.location.md) | { line: number; column?: number; } | |
| [message](./cucumber.isourceserror.message.md) | string | |
| [uri](./cucumber.isourceserror.uri.md) | string | |

11 changes: 11 additions & 0 deletions docs/api/cucumber.isourceserror.message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ISourcesError](./cucumber.isourceserror.md) &gt; [message](./cucumber.isourceserror.message.md)

## ISourcesError.message property

<b>Signature:</b>

```typescript
message: string;
```
11 changes: 11 additions & 0 deletions docs/api/cucumber.isourceserror.uri.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [ISourcesError](./cucumber.isourceserror.md) &gt; [uri](./cucumber.isourceserror.uri.md)

## ISourcesError.uri property

<b>Signature:</b>

```typescript
uri: string;
```
25 changes: 25 additions & 0 deletions docs/api/cucumber.loadsources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@cucumber/cucumber](./cucumber.md) &gt; [loadSources](./cucumber.loadsources.md)

## loadSources() function

Load and parse features, produce a filtered and ordered test plan and/or parse errors.

<b>Signature:</b>

```typescript
export declare function loadSources(coordinates: ISourcesCoordinates, environment?: IRunEnvironment): Promise<ILoadSourcesResult>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| coordinates | [ISourcesCoordinates](./cucumber.isourcescoordinates.md) | Coordinates required to find features |
| environment | [IRunEnvironment](./cucumber.irunenvironment.md) | Project environment. |

<b>Returns:</b>

Promise&lt;[ILoadSourcesResult](./cucumber.iloadsourcesresult.md)<!-- -->&gt;

4 changes: 4 additions & 0 deletions docs/api/cucumber.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ These docs cover the API used for running Cucumber programmatically. The entry p
| Function | Description |
| --- | --- |
| [loadConfiguration(options, environment)](./cucumber.loadconfiguration.md) | Load user-authored configuration to be used in a test run. |
| [loadSources(coordinates, environment)](./cucumber.loadsources.md) | Load and parse features, produce a filtered and ordered test plan and/or parse errors. |
| [loadSupport(options, environment)](./cucumber.loadsupport.md) | Load support code for use in test runs. |
| [runCucumber(configuration, environment, onMessage)](./cucumber.runcucumber.md) | Execute a Cucumber test run. |

Expand All @@ -23,7 +24,9 @@ These docs cover the API used for running Cucumber programmatically. The entry p
| Interface | Description |
| --- | --- |
| [ILoadConfigurationOptions](./cucumber.iloadconfigurationoptions.md) | |
| [ILoadSourcesResult](./cucumber.iloadsourcesresult.md) | |
| [ILoadSupportOptions](./cucumber.iloadsupportoptions.md) | |
| [IPlannedPickle](./cucumber.iplannedpickle.md) | |
| [IResolvedConfiguration](./cucumber.iresolvedconfiguration.md) | |
| [IRunConfiguration](./cucumber.irunconfiguration.md) | |
| [IRunEnvironment](./cucumber.irunenvironment.md) | Contextual data about the project environment. |
Expand All @@ -32,6 +35,7 @@ These docs cover the API used for running Cucumber programmatically. The entry p
| [IRunOptionsRuntime](./cucumber.irunoptionsruntime.md) | |
| [IRunResult](./cucumber.irunresult.md) | Result of a Cucumber test run. |
| [ISourcesCoordinates](./cucumber.isourcescoordinates.md) | |
| [ISourcesError](./cucumber.isourceserror.md) | |
| [ISupportCodeCoordinates](./cucumber.isupportcodecoordinates.md) | |

## Type Aliases
Expand Down
14 changes: 14 additions & 0 deletions docs/javascript_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ export async function runTests(directory, configFile, failFast) {
return success
}
```

## Sources example

You can use the `loadSources` function to load and parse your feature files, calculate the test plan (accounting for filtering and ordering) and report any parse errors:

```javascript
import { loadConfiguration, loadSources } from '@cucumber/cucumber/api'

export async function calculatePlan() {
const { runConfiguration } = await loadConfiguration()
const { plan } = await loadSources(runConfiguration.sources)
return plan
}
```
43 changes: 40 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"@cucumber/cucumber-expressions": "15.0.2",
"@cucumber/gherkin": "22.0.0",
"@cucumber/gherkin-streams": "4.0.0",
"@cucumber/gherkin-utils": "^7.0.0",
"@cucumber/html-formatter": "18.0.0",
"@cucumber/messages": "17.1.1",
"@cucumber/tag-expressions": "4.1.0",
Expand Down
37 changes: 37 additions & 0 deletions reports/cucumber.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export interface ILoadConfigurationOptions {
provided?: Partial<IConfiguration>;
}

// @public (undocumented)
export interface ILoadSourcesResult {
// (undocumented)
errors: ISourcesError[];
// (undocumented)
plan: IPlannedPickle[];
}

// @public (undocumented)
export interface ILoadSupportOptions {
// (undocumented)
Expand All @@ -32,6 +40,19 @@ export interface ILoadSupportOptions {
support: ISupportCodeCoordinates;
}

// @public (undocumented)
export interface IPlannedPickle {
// (undocumented)
location: {
line: number;
column?: number;
};
// (undocumented)
name: string;
// (undocumented)
uri: string;
}

// @public (undocumented)
export interface IResolvedConfiguration {
runConfiguration: IRunConfiguration;
Expand Down Expand Up @@ -119,6 +140,19 @@ export interface ISourcesCoordinates {
tagExpression: string;
}

// @public (undocumented)
export interface ISourcesError {
// (undocumented)
location: {
line: number;
column?: number;
};
// (undocumented)
message: string;
// (undocumented)
uri: string;
}

// @public (undocumented)
export interface ISupportCodeCoordinates {
// (undocumented)
Expand All @@ -135,6 +169,9 @@ export type ISupportCodeCoordinatesOrLibrary = ISupportCodeCoordinates | ISuppor
// @public
export function loadConfiguration(options?: ILoadConfigurationOptions, environment?: IRunEnvironment): Promise<IResolvedConfiguration>;

// @public
export function loadSources(coordinates: ISourcesCoordinates, environment?: IRunEnvironment): Promise<ILoadSourcesResult>;

// @public
export function loadSupport(options: ILoadSupportOptions, environment?: IRunEnvironment): Promise<ISupportCodeLibrary>;

Expand Down
Loading