Skip to content

Commit

Permalink
Update slayr example for before/after hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
deanrad committed Apr 18, 2024
1 parent 930696f commit 5d4d541
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ operators/gdocs
.yarn
assets/_private
examples/codegen
.parcel-cache
33 changes: 23 additions & 10 deletions examples/slayr/convert/jest-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@ import ts from "typescript";
import { SlayItem } from "../types";

export function getJestAST(spec: SlayItem) {
const block =
["It", "Test"].includes(spec.tag) || spec.content.length === 0
? "it.todo"
: "describe";
const block = spec.tag.match(/^before/i)
? "beforeEach"
: spec.tag.match(/^after/i)
? "afterEach"
: ["It", "Test"].includes(spec.tag) || spec.content.length === 0
? "it.todo"
: "describe";

const text = spec.text;
const shouldNest = block === "describe";

// Only some tags are self-describing
const text = ["Context", "It", "Describe", "Test", "it.todo"].includes(
spec.tag
)
? spec.text
: `${spec.tag} ${spec.text}`;
if (["beforeEach", "afterEach"].includes(block)) {
return ts.createExpressionStatement(
ts.createCall(ts.createIdentifier(block), undefined, [
ts.createArrowFunction(
undefined,
undefined,
[],
undefined,
ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
ts.createBlock([ts.createStringLiteral("TODO " + spec.text)], true)
),
])
);
}

if (!shouldNest) {
return ts.createExpressionStatement(
Expand Down
4 changes: 3 additions & 1 deletion examples/slayr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"start": "parcel index.html"
},
"devDependencies": {
"parcel": "^2.8.3"
"@parcel/transformer-sass": "^2.12.0",
"parcel": "^2.8.3",
"process": "^0.11.10"
},
"dependencies": {
"@rxfx/after": "^1.0.3",
Expand Down

0 comments on commit 5d4d541

Please sign in to comment.