-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal
transition extracting (#369)
* Parse internal keyword on transitions * Add test for parsing internal property on transitions * changeset * Only add internal property if transitions is explicitly internal * Parse -> Extract Co-authored-by: Mateusz Burzyński <[email protected]> * Keep explicitly provided `internal` property regardless of its value Co-authored-by: Mateusz Burzyński <[email protected]> * Keep explicitly provided `internal` property regardless of its value Co-authored-by: Mateusz Burzyński <[email protected]> * Update tests according to new internal extraction * update snapshot * update snapshots again --------- Co-authored-by: Mateusz Burzyński <[email protected]>
- Loading branch information
Showing
5 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xstate/machine-extractor': minor | ||
--- | ||
|
||
Extract `internal` property on transitions |
116 changes: 116 additions & 0 deletions
116
packages/machine-extractor/src/__tests__/transitions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { extractMachinesFromFile } from '..'; | ||
|
||
describe('Internal transitions', () => { | ||
it('Should keep explicitly provied internal property on transitions', () => { | ||
const result = extractMachinesFromFile(` | ||
createMachine({ | ||
initial: 'a', | ||
states: { | ||
a: { | ||
on: { | ||
move: { | ||
target: 'b', | ||
internal: true | ||
} | ||
}, | ||
invoke: { | ||
src: 'actor', | ||
onDone: { | ||
internal: false | ||
}, | ||
onError: {internal: true} | ||
} | ||
}, | ||
b: { | ||
after: { | ||
100: { | ||
target: 'c', | ||
internal: true | ||
} | ||
}, | ||
always: {target: 'a', internal: false}, | ||
onDone: { | ||
internal: true | ||
} | ||
} | ||
} | ||
}) | ||
`); | ||
|
||
expect(result?.machines[0]?.toConfig()).toMatchInlineSnapshot(` | ||
{ | ||
"initial": "a", | ||
"states": { | ||
"a": { | ||
"invoke": { | ||
"onDone": { | ||
"internal": false, | ||
}, | ||
"onError": { | ||
"internal": true, | ||
}, | ||
"src": "actor", | ||
}, | ||
"on": { | ||
"move": { | ||
"internal": true, | ||
"target": "b", | ||
}, | ||
}, | ||
}, | ||
"b": { | ||
"after": { | ||
"100": { | ||
"internal": true, | ||
"target": "c", | ||
}, | ||
}, | ||
"always": { | ||
"internal": false, | ||
"target": "a", | ||
}, | ||
"onDone": { | ||
"internal": true, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
|
||
it('Should leave out internal property if transition is missing internal property', () => { | ||
const result = extractMachinesFromFile(` | ||
createMachine({ | ||
initial: 'a', | ||
states: { | ||
a: { | ||
on: { | ||
foo: { | ||
target: 'b' | ||
}, | ||
bar: 'c', | ||
} | ||
} | ||
} | ||
}) | ||
`); | ||
|
||
expect(result?.machines[0]?.toConfig()).toMatchInlineSnapshot(` | ||
{ | ||
"initial": "a", | ||
"states": { | ||
"a": { | ||
"on": { | ||
"bar": { | ||
"target": "c", | ||
}, | ||
"foo": { | ||
"target": "b", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters