From f5e6f0824d661e9c1b3ce8669f68d6b8002d8739 Mon Sep 17 00:00:00 2001 From: Mohammad Rad Date: Thu, 28 Nov 2024 19:21:42 -0800 Subject: [PATCH] fix build issues and add lifecycle methods --- packages/shortest/index.d.ts | 2 ++ packages/shortest/package.json | 2 +- packages/shortest/src/index.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/shortest/index.d.ts b/packages/shortest/index.d.ts index cbd21203..f6f111d3 100644 --- a/packages/shortest/index.d.ts +++ b/packages/shortest/index.d.ts @@ -7,6 +7,8 @@ declare global { const define: (name: string, fn: () => void | Promise) => void; const expect: Expect; const __shortest__: ShortestGlobals; + const beforeAll: (fn: () => void | Promise) => void; + const afterAll: (fn: () => void | Promise) => void; } // Export module types diff --git a/packages/shortest/package.json b/packages/shortest/package.json index e9e6eb19..abf6b53c 100644 --- a/packages/shortest/package.json +++ b/packages/shortest/package.json @@ -25,7 +25,7 @@ "prepare": "pnpm build", "prepublishOnly": "pnpm build && chmod +x dist/cli/bin.js", "postprepare": "node ./dist/cli/setup.js", - "build:types": "tsc --emitDeclarationOnly --outDir dist/types && cp index.d.ts dist/ && cp src/types/*.d.ts dist/types/", + "build:types": "tsc --emitDeclarationOnly --outDir dist/types && cp index.d.ts dist/", "build:js": "esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:esbuild --external:punycode --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv", "build:cjs": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs --external:esbuild --external:punycode --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv", "build:cli": "esbuild src/cli/bin.ts src/cli/setup.ts --bundle --platform=node --format=esm --outdir=dist/cli --metafile=dist/meta-cli.json --external:fsevents --external:chokidar --external:glob --external:esbuild --external:events --external:path --external:fs --external:util --external:stream --external:os --external:assert --external:url --external:playwright --external:@anthropic-ai/sdk --external:expect --external:dotenv --external:otplib --external:picocolors --external:punycode", diff --git a/packages/shortest/src/index.ts b/packages/shortest/src/index.ts index 699f9af6..978e1058 100644 --- a/packages/shortest/src/index.ts +++ b/packages/shortest/src/index.ts @@ -18,6 +18,8 @@ declare const global: { __shortest__: any; define: any; expect: any; + beforeAll: (fn: () => void | Promise) => void; + afterAll: (fn: () => void | Promise) => void; } & typeof globalThis; if (!global.__shortest__) { @@ -29,6 +31,12 @@ if (!global.__shortest__) { }); }, expect: jestExpect, + beforeAll: (fn: () => void | Promise) => { + global.__shortest__.registry.beforeAllFns.push(fn); + }, + afterAll: (fn: () => void | Promise) => { + global.__shortest__.registry.afterAllFns.push(fn); + }, registry: { suites: new Map(), currentSuite: null, @@ -40,6 +48,8 @@ if (!global.__shortest__) { // Attach to global scope global.define = global.__shortest__.define; global.expect = global.__shortest__.expect; + global.beforeAll = global.__shortest__.beforeAll; + global.afterAll = global.__shortest__.afterAll; dotenv.config({ path: join(process.cwd(), '.env') }); dotenv.config({ path: join(process.cwd(), '.env.local') });