Give the e2e steps one place to build their fixtures
Steps 18 and 20 both hand-rolled the same object-plus-behavior scaffold, down to lane offsets that nothing kept distinct. Step 19 claimed in a comment that it cleaned up after itself but never checked it – the only one of the four that did not. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6ac6b69388
commit
787a19d525
7 files changed
+140
-125
No files matched your search
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* Steps 17–20 each need the same throwaway rig in the fixture scene: a behavior asset cloned off
|
||||
* `mover` carrying the step's own graph, a crate to hold it, and a logic child that runs it.
|
||||
* Spelled out per step it drifted four ways – `push` vs `unshift`, three different `make`
|
||||
* signatures, and y-offsets nothing kept apart.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Where each step parks its box. The fixture scene is shared, so two steps at the same y would
|
||||
* overlap and each would fail for reasons belonging to the other.
|
||||
*/
|
||||
export const LANES = {
|
||||
editorRun: 400,
|
||||
editorRunContainer: 800,
|
||||
editorRunEdits: 1200,
|
||||
pause: 300,
|
||||
nested: 700,
|
||||
keyRepeat: -300,
|
||||
};
|
||||
|
||||
/**
|
||||
* Source for a `make(id, assetId, parentId, y, name)` factory, to paste inside a `mutate()`
|
||||
* string. It clones `scene.objects[0]`, so a new object carries whatever shape the fixture has.
|
||||
*/
|
||||
export const MAKE_OBJECT = `
|
||||
const make = (id, assetId, parentId, y, name = '') => {
|
||||
const o = structuredClone(scene.objects[0]);
|
||||
Object.assign(o, {
|
||||
id,
|
||||
assetId,
|
||||
name,
|
||||
position: { x: 0, y, z: 0 },
|
||||
parentId,
|
||||
overrides: {},
|
||||
instanceEdits: {},
|
||||
});
|
||||
return o;
|
||||
};`;
|
||||
|
||||
/**
|
||||
* Builds the rig and hands back the ids it created, plus `remove()` which takes them out again
|
||||
* and returns what is left – so a step's cleanup cannot fall out of step with what it made.
|
||||
*
|
||||
* `front` puts the asset at the head of the project list: the asset panel is long by this point
|
||||
* in the suite, and a row appended at the end scrolls out of reach of `dragAsset`.
|
||||
*/
|
||||
export async function scaffoldBehavior(t, options) {
|
||||
const {
|
||||
assetId,
|
||||
name,
|
||||
graph,
|
||||
boxId,
|
||||
boxName = 'Box',
|
||||
logicId,
|
||||
y,
|
||||
front = false,
|
||||
props = { enabled: true, runInEditor: false },
|
||||
} = options;
|
||||
|
||||
await t.mutate(`
|
||||
const p = __gm.state.project;
|
||||
const scene = __gm.state.activeScene;
|
||||
const asset = structuredClone(p.assets.find((a) => a.id === 'mover'));
|
||||
Object.assign(asset, {
|
||||
id: ${JSON.stringify(assetId)},
|
||||
name: ${JSON.stringify(name)},
|
||||
props: ${JSON.stringify(props)},
|
||||
variables: [],
|
||||
graph: ${JSON.stringify(graph)},
|
||||
});
|
||||
p.assets.${front ? 'unshift' : 'push'}(asset);
|
||||
${MAKE_OBJECT}
|
||||
scene.objects.push(
|
||||
make(${JSON.stringify(boxId)}, 'crate', '', ${y}, ${JSON.stringify(boxName)}),
|
||||
make(${JSON.stringify(logicId)}, ${JSON.stringify(assetId)}, ${JSON.stringify(boxId)}, 0, ${JSON.stringify(name)}),
|
||||
);
|
||||
`);
|
||||
await t.sleep(400);
|
||||
|
||||
return {
|
||||
assetId,
|
||||
boxId,
|
||||
logicId,
|
||||
/** Removes everything this rig added and reports what survived (should be all zeroes). */
|
||||
async remove() {
|
||||
await t.evaluate('__gm.state.select(null)');
|
||||
await t.mutate(`
|
||||
const p = __gm.state.project;
|
||||
const scene = __gm.state.activeScene;
|
||||
const objects = ${JSON.stringify([boxId, logicId])};
|
||||
const assets = ${JSON.stringify([assetId])};
|
||||
scene.objects = scene.objects.filter((o) => !objects.includes(o.id));
|
||||
p.assets = p.assets.filter((a) => !assets.includes(a.id));
|
||||
`);
|
||||
await t.sleep(300);
|
||||
return t.json(`{
|
||||
objects: __gm.sceneObjects().filter((o) => ${JSON.stringify([boxId, logicId])}.includes(o.id)).length,
|
||||
assets: __gm.state.project.assets.filter((a) => a.id === ${JSON.stringify(assetId)}).length,
|
||||
}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user