Skip to content

Commit

Permalink
Bug: Global types are not registered in typescript properly (#95)
Browse files Browse the repository at this point in the history
fix: global type declarations

Fixed TypeScript global declarations for `define`, `expect`,
`beforeAll`, and `afterAll` functions. Updated type exports to avoid
duplication and ensure proper type resolution in consuming projects.

Changes:
- Added proper global declarations in index.d.ts
- Removed duplicate type exports from index.ts
- Fixed build script for type declarations

Bump version to 0.0.2 and update changelogs
  • Loading branch information
m2rads authored Nov 29, 2024
2 parents 1d3b060 + f60ca46 commit f453ba2
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 37 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
registry-url: 'https://registry.npmjs.org/'
scope: '@antiwork'
cache: 'pnpm'

- name: Check npm token
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Publish to NPM
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
pnpm publish --access public --no-git-checks
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_REGISTRY: https://registry.npmjs.org/
1 change: 1 addition & 0 deletions packages/shortest/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@antiwork:registry=https://registry.npmjs.org/
9 changes: 8 additions & 1 deletion packages/shortest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.2] - 2024-11-28

### Fixed
- Fixed type declarations for global functions (define, expect)
- Fixed UITestBuilder type exports
- Improved TypeScript integration in consuming projects

## [0.0.1] - 2024-11-28

### Added
- Initial release of Shortest
- Initial release (contained type declaration bugs)
- AI-powered test execution using Claude 3.5 Sonnet
- Natural language test writing support
- GitHub integration with 2FA support
Expand Down
44 changes: 44 additions & 0 deletions packages/shortest/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Expect } from 'expect';
import type { ShortestGlobals } from './dist/types/globals';
import type { UITestBuilderInterface } from './dist/types/ui-test-builder';
import type { TestStep, BeforeAllFunction, AfterAllFunction } from './dist/types/test';
import type { ShortestConfig } from './dist/types/config';

declare global {
const define: (name: string, fn: () => void | Promise<void>) => void;
const expect: Expect;
const __shortest__: ShortestGlobals;
const beforeAll: (fn: () => void | Promise<void>) => void;
const afterAll: (fn: () => void | Promise<void>) => void;
}

// Export module types
declare module '@antiwork/shortest' {
export type { ShortestConfig };

export class UITestBuilder<T = any> implements UITestBuilderInterface<T> {
path: string;
testName: string;
steps: TestStep[];

constructor(path: string);
setSuiteName(name: string): this;
getSuiteName(): string;
test(name: string): this;

given(description: string): this;
given(description: string, callback: () => Promise<void>): this;
given(description: string, payload: T, callback?: () => Promise<void>): this;

when(description: string): this;
when(description: string, callback: () => Promise<void>): this;
when(description: string, payload: T, callback?: () => Promise<void>): this;

expect(description: string): this;
expect(description: string, callback: () => Promise<void>): this;
expect(description: string, payload: T, callback?: () => Promise<void>): this;

before(actionOrFn: string | BeforeAllFunction, payload?: T): this;
after(actionOrFn: string | AfterAllFunction, payload?: T): this;
}
}
11 changes: 6 additions & 5 deletions packages/shortest/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"name": "@antiwork/shortest",
"version": "0.0.1",
"version": "0.0.2",
"description": "AI-powered natural language end-to-end testing framework",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/types/shortest.d.ts",
"types": "./index.d.ts",
"bin": {
"shortest": "./dist/cli/bin.js"
},
"exports": {
".": {
"types": "./dist/types/shortest.d.ts",
"types": "./index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"files": [
"dist"
"dist",
"index.d.ts"
],
"scripts": {
"build": "rm -rf dist && pnpm build:types && pnpm build:js && pnpm build:cli",
"prepare": "pnpm build",
"prepublishOnly": "pnpm build && chmod +x dist/cli/bin.js",
"postprepare": "node ./dist/cli/setup.js",
"build:types": "tsc --emitDeclarationOnly",
"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",
Expand Down
12 changes: 11 additions & 1 deletion packages/shortest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ declare const global: {
__shortest__: any;
define: any;
expect: any;
beforeAll: (fn: () => void | Promise<void>) => void;
afterAll: (fn: () => void | Promise<void>) => void;
} & typeof globalThis;

if (!global.__shortest__) {
Expand All @@ -29,6 +31,12 @@ if (!global.__shortest__) {
});
},
expect: jestExpect,
beforeAll: (fn: () => void | Promise<void>) => {
global.__shortest__.registry.beforeAllFns.push(fn);
},
afterAll: (fn: () => void | Promise<void>) => {
global.__shortest__.registry.afterAllFns.push(fn);
},
registry: {
suites: new Map<string, UITestBuilderInterface[]>(),
currentSuite: null,
Expand All @@ -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') });
Expand Down Expand Up @@ -123,5 +133,5 @@ export class TestRegistry {
}
}

export { UITestBuilder };
export { UITestBuilder } from './core/builder';
export * from './types';
20 changes: 0 additions & 20 deletions packages/shortest/src/types/shortest.d.ts

This file was deleted.

0 comments on commit f453ba2

Please sign in to comment.