diff --git a/test/data/typescript-esm-exports/codecept.conf.ts b/test/data/typescript-esm-exports/codecept.conf.ts new file mode 100644 index 000000000..76a21e55c --- /dev/null +++ b/test/data/typescript-esm-exports/codecept.conf.ts @@ -0,0 +1,9 @@ +export const config: CodeceptJS.MainConfig = { + tests: "./*.ts", + output: "./output", + helpers: { + FileSystem: {}, + }, + name: "container-esm", + require: ["tsx/cjs"], +}; diff --git a/test/data/typescript-esm-exports/package.json b/test/data/typescript-esm-exports/package.json new file mode 100644 index 000000000..e160f5318 --- /dev/null +++ b/test/data/typescript-esm-exports/package.json @@ -0,0 +1,5 @@ +{ + "name": "container-esm", + "version": "1.0.0", + "private": true +} diff --git a/test/data/typescript-esm-exports/test-all-exports.ts b/test/data/typescript-esm-exports/test-all-exports.ts new file mode 100644 index 000000000..3a56a9331 --- /dev/null +++ b/test/data/typescript-esm-exports/test-all-exports.ts @@ -0,0 +1,107 @@ +import { + container, + codecept, + output, + event, + recorder, + config, + actor, + helper, + pause, + within, + dataTable, + dataTableArgument, + store, + locator, + // Secret, + // secret, +} from "codeceptjs"; +import { expect } from "chai"; + +Feature("Import all exports from codeceptjs"); + +Scenario("container should be importable as named export", () => { + expect(container).to.exist; + expect(container.helpers).to.be.a("function"); + + const helpers = container.helpers(); + console.log("Available helpers:", Object.keys(helpers)); +}); + +Scenario("codecept should be importable", () => { + expect(codecept).to.exist; +}); + +Scenario("output should be importable", () => { + expect(output).to.exist; + expect(output.print).to.be.a("function"); + output.print("Testing output.print"); +}); + +Scenario("event should be importable", () => { + expect(event).to.exist; + expect(event).to.be.an("object"); + expect(event.dispatcher).to.exist; +}); + +Scenario("recorder should be importable", () => { + expect(recorder).to.exist; + expect(recorder).to.be.an("object"); + expect(recorder.start).to.be.a("function"); +}); + +Scenario("config should be importable", () => { + expect(config).to.exist; + expect(config.get).to.be.a("function"); +}); + +Scenario("actor should be importable", () => { + expect(actor).to.exist; + expect(actor).to.be.a("function"); +}); + +Scenario("helper should be importable", () => { + expect(helper).to.exist; +}); + +Scenario("pause should be importable", () => { + expect(pause).to.exist; +}); + +Scenario("within should be importable", () => { + expect(within).to.exist; + expect(within).to.be.a("function"); +}); + +Scenario("dataTable should be importable", () => { + expect(dataTable).to.exist; +}); + +Scenario("dataTableArgument should be importable", () => { + expect(dataTableArgument).to.exist; +}); + +Scenario("store should be importable", () => { + expect(store).to.exist; + expect(store).to.be.an("object"); + expect(store.debugMode).to.exist; +}); + +Scenario("locator should be importable", () => { + expect(locator).to.exist; + expect(locator.build).to.be.a("function"); +}); + +// Secret and secret are not exported from lib/index.js in older versions, so skip them +// Scenario("Secret should be importable", () => { +// expect(Secret).to.exist; +// expect(Secret.secret).to.be.a("function"); +// }); + +// Scenario("secret should be importable", () => { +// expect(secret).to.exist; +// expect(secret).to.be.a("function"); +// +// const mySecret = secret("my-password"); +// expect(mySecret.toString()).to.equal("my-password"); +// }); diff --git a/test/data/typescript-esm-exports/test.ts b/test/data/typescript-esm-exports/test.ts new file mode 100644 index 000000000..971d55613 --- /dev/null +++ b/test/data/typescript-esm-exports/test.ts @@ -0,0 +1,12 @@ +import { container } from "codeceptjs"; +import { expect } from "chai"; + +Feature("Import container as named export"); + +Scenario("container should be importable as named export", () => { + expect(container).to.exist; + expect(container.helpers).to.be.a("function"); + + const helpers = container.helpers(); + console.log("Available helpers:", Object.keys(helpers)); +}); diff --git a/typings/index.d.ts b/typings/index.d.ts index 50e3fcc95..7406dadba 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -635,8 +635,105 @@ declare namespace Mocha { } } +// Internal API types declare module 'codeceptjs' { export default codeceptjs + + /** + * Dependency Injection Container + * Provides access to helpers, support objects, plugins, and translation + */ + export const container: typeof CodeceptJS.Container + + /** + * Test runner class + */ + export const codecept: typeof CodeceptJS.Codecept + + /** + * Output module for printing messages + */ + export const output: typeof CodeceptJS.output + + /** + * Event dispatcher for listening to CodeceptJS events + */ + export const event: typeof CodeceptJS.event + + /** + * Global promise chain recorder + */ + export const recorder: CodeceptJS.recorder + + /** + * Configuration module + */ + export const config: typeof CodeceptJS.Config + + /** + * Actor (I) constructor + */ + export const actor: CodeceptJS.actor + + /** + * Base Helper class + */ + export const helper: typeof CodeceptJS.Helper + + /** + * Pause execution until user input + */ + export const pause: typeof CodeceptJS.pause + + /** + * Execute steps within specific context + */ + export const within: typeof CodeceptJS.within + + /** + * Create data tables for data-driven tests + */ + export const dataTable: typeof CodeceptJS.DataTable + + /** + * Create data table arguments + */ + export const dataTableArgument: typeof CodeceptJS.DataTableArgument + + /** + * Shared store for test data + */ + export const store: typeof CodeceptJS.store + + /** + * Locator builder + */ + export const locator: typeof CodeceptJS.Locator + + /** + * Auto-healing module + */ + export const heal: any + + /** + * AI assistant module + */ + export const ai: any + + /** + * Workers for parallel execution + */ + export const Workers: any + + /** + * Secret value type for sensitive data + */ + export const Secret: typeof CodeceptJS.Secret + + /** + * Create a secret value + */ + export const secret: typeof CodeceptJS.Secret.secret } declare module '@codeceptjs/helper' {