Skip to content

Commit

Permalink
Enter pre mode for @xstate/test@alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed May 30, 2022
1 parent 8a101dc commit 252a824
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"mode": "pre",
"tag": "alpha",
"initialVersions": {
"xstate": "4.32.1",
"@xstate/analytics": "0.0.1",
"@xstate/fsm": "2.0.0",
"@xstate/graph": "2.0.0-alpha.0",
"@xstate/immer": "0.3.1",
"@xstate/inspect": "0.7.0",
"@xstate/react": "3.0.0",
"@xstate/scxml": "0.2.1",
"@xstate/svelte": "2.0.0",
"@xstate/test": "1.0.0-alpha.0",
"@xstate/vue": "2.0.0"
},
"changesets": [
"curly-windows-burn",
"curly-windows-learn",
"great-lions-buy",
"lazy-turtles-brand",
"lazy-turtles-bread",
"lazy-turtles-grand",
"lazy-turtles-grate",
"lazy-turtles-great",
"lazy-turtles-mate",
"lazy-turtles-trade"
]
}
14 changes: 14 additions & 0 deletions packages/xstate-graph/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @xstate/graph

## 2.0.0-alpha.0

### Major Changes

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @davidkpiano

Renamed `getAdjacencyMap` to `getValueAdjacencyMap`.

* [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @davidkpiano

Changed `getSimplePaths` to `getSimplePlans`, and `getShortestPaths` to `getShortestPlans`. Both of these functions can be passed a machine, and return `StatePlan[]`.

Added functions `traverseSimplePlans`, `traverseShortestPlans`,`traverseShortestPlansFromTo`, `traverseSimplePlansTo` and `traverseSimplePlansFromTo`, which can be passed a `Behavior` and return `StatePlan[]`.

## 1.4.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/xstate-graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xstate/graph",
"version": "1.4.2",
"version": "2.0.0-alpha.0",
"description": "XState graph utilities",
"keywords": [
"state",
Expand Down
149 changes: 149 additions & 0 deletions packages/xstate-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,154 @@
# @xstate/test

## 1.0.0-alpha.0

### Major Changes

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @mattpocock
@author: @davidkpiano

Substantially simplified how paths and plans work in `TestModel`. Changed `getShortestPlans` and `getSimplePlans` to `getShortestPaths` and `getSimplePaths`. These functions now return an array of paths, instead of an array of plans which contain paths.

Also added `getPaths`, which defaults to `getShortestPaths`. This can be passed a `pathGenerator` to customize how paths are generated.

* [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @mattpocock

Moved event cases out of `events`, and into their own attribute called `eventCases`:

```ts
const model = createTestModel(machine, {
eventCases: {
CHOOSE_CURRENCY: [
{
currency: 'GBP'
},
{
currency: 'USD'
}
]
}
});

model.getPaths().forEach((path) => {
it(path.description, async () => {
await path.test({
events: {
CHOOSE_CURRENCY: ({ event }) => {
console.log(event.currency);
}
}
});
});
});
```

`eventCases` will also now always produce a new path, instead of only creating a path for the first case which matches.

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @davidkpiano

Removed `.testCoverage()`, and instead made `getPlans`, `getShortestPlans` and `getSimplePlans` cover all states and transitions enabled by event cases by default.

* [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @davidkpiano

Added validation on `createTestModel` to ensure that you don't include invalid machine configuration in your test machine. Invalid machine configs include `invoke`, `after`, and any actions with a `delay`.

Added `createTestMachine`, which provides a slimmed-down API for creating machines which removes these types from the config type signature.

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @davidkpiano

`getShortestPaths()` and `getPaths()` will now traverse all _transitions_ by default, not just all events.

Take this machine:

```ts
const machine = createTestMachine({
initial: 'toggledOn',
states: {
toggledOn: {
on: {
TOGGLE: 'toggledOff'
}
},
toggledOff: {
on: {
TOGGLE: 'toggledOn'
}
}
}
});
```

In `@xstate/test` version 0.x, this would run this path by default:

```txt
toggledOn -> TOGGLE -> toggledOff
```

This is because it satisfies two conditions:

1. Covers all states
2. Covers all events

But this a complete test - it doesn't test if going from `toggledOff` to `toggledOn` works.

Now, we seek to cover all transitions by default. So the path would be:

```txt
toggledOn -> TOGGLE -> toggledOff -> TOGGLE -> toggledOn
```

* [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @mattpocock @davidkpiano

Moved `events` from `createTestModel` to `path.test`.

Old:

```ts
const model = createTestModel(machine, {
events: {}
});
```

New:

```ts
const paths = model.getPaths().forEach((path) => {
path.test({
events: {}
});
});
```

This allows for easier usage of per-test mocks and per-test context.

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @mattpocock @davidkpiano

Added `states` to `path.test()`:

```ts
const paths = model.getPaths().forEach((path) => {
path.test({
states: {
myState: () => {},
'myState.deep': () => {}
}
});
});
```

This allows you to define your tests outside of your machine, keeping the machine itself easy to read.

### Minor Changes

- [#3036](https://github.com/statelyai/xstate/pull/3036) Thanks [@davidkpiano](https://github.com/davidkpiano)! - @author: @mattpocock @davidkpiano

Added `path.testSync(...)` to allow for testing paths in sync-only environments, such as Cypress.

### Patch Changes

- Updated dependencies [[`ae673e443`](https://github.com/statelyai/xstate/commit/ae673e443aab1e42e26fbe16ea1e9dab784d99be), [`ae673e443`](https://github.com/statelyai/xstate/commit/ae673e443aab1e42e26fbe16ea1e9dab784d99be)]:
- @xstate/graph@2.0.0-alpha.0

## 0.5.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/xstate-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xstate/test",
"version": "0.5.1",
"version": "1.0.0-alpha.0",
"description": "XState test utilities",
"keywords": [
"state",
Expand Down Expand Up @@ -51,6 +51,6 @@
"xstate": "*"
},
"dependencies": {
"@xstate/graph": "^1.4.2"
"@xstate/graph": "^2.0.0-alpha.0"
}
}

0 comments on commit 252a824

Please sign in to comment.