Skip to content

Commit ccc7bbb

Browse files
committed
add all export from codeceptjs and add tests
1 parent e53acd1 commit ccc7bbb

5 files changed

Lines changed: 310 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const config: CodeceptJS.MainConfig = {
2+
tests: "./*.ts",
3+
output: "./output",
4+
helpers: {
5+
FileSystem: {},
6+
},
7+
name: "container-esm",
8+
require: ["tsx/cjs"],
9+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "container-esm",
3+
"version": "1.0.0",
4+
"private": true
5+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
container,
3+
codecept,
4+
output,
5+
event,
6+
recorder,
7+
config,
8+
actor,
9+
helper,
10+
pause,
11+
within,
12+
dataTable,
13+
dataTableArgument,
14+
store,
15+
locator,
16+
// Secret,
17+
// secret,
18+
} from "codeceptjs";
19+
import { expect } from "chai";
20+
21+
Feature("Import all exports from codeceptjs");
22+
23+
Scenario("container should be importable as named export", () => {
24+
expect(container).to.exist;
25+
expect(container.helpers).to.be.a("function");
26+
27+
const helpers = container.helpers();
28+
console.log("Available helpers:", Object.keys(helpers));
29+
});
30+
31+
Scenario("codecept should be importable", () => {
32+
expect(codecept).to.exist;
33+
});
34+
35+
Scenario("output should be importable", () => {
36+
expect(output).to.exist;
37+
expect(output.print).to.be.a("function");
38+
output.print("Testing output.print");
39+
});
40+
41+
Scenario("event should be importable", () => {
42+
expect(event).to.exist;
43+
expect(event).to.be.an("object");
44+
expect(event.dispatcher).to.exist;
45+
});
46+
47+
Scenario("recorder should be importable", () => {
48+
expect(recorder).to.exist;
49+
expect(recorder).to.be.an("object");
50+
expect(recorder.start).to.be.a("function");
51+
});
52+
53+
Scenario("config should be importable", () => {
54+
expect(config).to.exist;
55+
expect(config.get).to.be.a("function");
56+
});
57+
58+
Scenario("actor should be importable", () => {
59+
expect(actor).to.exist;
60+
expect(actor).to.be.a("function");
61+
});
62+
63+
Scenario("helper should be importable", () => {
64+
expect(helper).to.exist;
65+
});
66+
67+
Scenario("pause should be importable", () => {
68+
expect(pause).to.exist;
69+
});
70+
71+
Scenario("within should be importable", () => {
72+
expect(within).to.exist;
73+
expect(within).to.be.a("function");
74+
});
75+
76+
Scenario("dataTable should be importable", () => {
77+
expect(dataTable).to.exist;
78+
});
79+
80+
Scenario("dataTableArgument should be importable", () => {
81+
expect(dataTableArgument).to.exist;
82+
});
83+
84+
Scenario("store should be importable", () => {
85+
expect(store).to.exist;
86+
expect(store).to.be.an("object");
87+
expect(store.debugMode).to.exist;
88+
});
89+
90+
Scenario("locator should be importable", () => {
91+
expect(locator).to.exist;
92+
expect(locator.build).to.be.a("function");
93+
});
94+
95+
// Secret and secret are not exported from lib/index.js in older versions, so skip them
96+
// Scenario("Secret should be importable", () => {
97+
// expect(Secret).to.exist;
98+
// expect(Secret.secret).to.be.a("function");
99+
// });
100+
101+
// Scenario("secret should be importable", () => {
102+
// expect(secret).to.exist;
103+
// expect(secret).to.be.a("function");
104+
//
105+
// const mySecret = secret("my-password");
106+
// expect(mySecret.toString()).to.equal("my-password");
107+
// });
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { container } from "codeceptjs";
2+
import { expect } from "chai";
3+
4+
Feature("Import container as named export");
5+
6+
Scenario("container should be importable as named export", () => {
7+
expect(container).to.exist;
8+
expect(container.helpers).to.be.a("function");
9+
10+
const helpers = container.helpers();
11+
console.log("Available helpers:", Object.keys(helpers));
12+
});

typings/index.d.ts

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,86 @@ declare namespace CodeceptJS {
520520
}
521521

522522
function addStep(step: string | RegExp, fn: Function): Promise<void>
523+
524+
// Internal API types
525+
class Container {
526+
static create(config: any, opts?: any): Promise<void>
527+
static actor(): any
528+
static plugins(name?: string): any
529+
static support(name?: string): any
530+
static helpers(name?: string): any
531+
static translation(): any
532+
static mocha(): any
533+
}
534+
535+
class Codecept {
536+
// Codecept class methods - to be filled from JSDoc
537+
}
538+
539+
class Config {
540+
static get(): any
541+
static set(key: string, value: any): void
542+
}
543+
544+
namespace output {
545+
function print(message: string): void
546+
function log(message: string): void
547+
function debug(message: string): void
548+
function error(message: string): void
549+
function info(message: string): void
550+
function success(message: string): void
551+
function warn(message: string): void
552+
}
553+
554+
type event = {
555+
dispatcher: any
556+
on: (event: string, handler: Function) => void
557+
once: (event: string, handler: Function) => void
558+
removeListener: (event: string, handler: Function) => void
559+
removeAllListeners: (event?: string) => void
560+
emit: (event: string, ...args: any[]) => void
561+
}
562+
563+
type recorder = {
564+
(fn: () => Promise<void> | void): void
565+
start: () => void
566+
stop: () => void
567+
add: (fn: Function) => void
568+
retry: any[]
569+
catch: (fn: Function) => void
570+
schedule: (fn: Function) => any
571+
promiseStack: any[]
572+
running: boolean
573+
}
574+
575+
type store = {
576+
debugMode: boolean
577+
timeouts: boolean
578+
autoRetries: boolean
579+
dryRun: boolean
580+
}
581+
582+
class Secret {
583+
static secret(value: string | number): Secret
584+
toString(): string
585+
getMasked(): string
586+
}
587+
588+
type pause = () => void
589+
590+
type within = (locator: LocatorOrString) => void
591+
592+
class DataTable {
593+
static (data: any[] | any[][]): any
594+
}
595+
596+
class DataTableArgument {
597+
static (data: any): any
598+
}
599+
600+
class Locator {
601+
static build(locator: ILocator | string): any
602+
}
523603
}
524604

525605
type TryTo = <T>(fn: () => Promise<T> | T) => Promise<T | false>
@@ -635,9 +715,105 @@ declare namespace Mocha {
635715
}
636716
}
637717

718+
// Internal API types
638719
declare module 'codeceptjs' {
639720
export default codeceptjs
640-
export const container: any
721+
722+
/**
723+
* Dependency Injection Container
724+
* Provides access to helpers, support objects, plugins, and translation
725+
*/
726+
export const container: typeof CodeceptJS.Container
727+
728+
/**
729+
* Test runner class
730+
*/
731+
export const codecept: typeof CodeceptJS.Codecept
732+
733+
/**
734+
* Output module for printing messages
735+
*/
736+
export const output: typeof CodeceptJS.output
737+
738+
/**
739+
* Event dispatcher for listening to CodeceptJS events
740+
*/
741+
export const event: CodeceptJS.event
742+
743+
/**
744+
* Global promise chain recorder
745+
*/
746+
export const recorder: CodeceptJS.recorder
747+
748+
/**
749+
* Configuration module
750+
*/
751+
export const config: typeof CodeceptJS.Config
752+
753+
/**
754+
* Actor (I) constructor
755+
*/
756+
export const actor: CodeceptJS.actor
757+
758+
/**
759+
* Base Helper class
760+
*/
761+
export const helper: typeof CodeceptJS.Helper
762+
763+
/**
764+
* Pause execution until user input
765+
*/
766+
export const pause: CodeceptJS.pause
767+
768+
/**
769+
* Execute steps within specific context
770+
*/
771+
export const within: CodeceptJS.within
772+
773+
/**
774+
* Create data tables for data-driven tests
775+
*/
776+
export const dataTable: typeof CodeceptJS.DataTable
777+
778+
/**
779+
* Create data table arguments
780+
*/
781+
export const dataTableArgument: typeof CodeceptJS.DataTableArgument
782+
783+
/**
784+
* Shared store for test data
785+
*/
786+
export const store: CodeceptJS.store
787+
788+
/**
789+
* Locator builder
790+
*/
791+
export const locator: typeof CodeceptJS.Locator
792+
793+
/**
794+
* Auto-healing module
795+
*/
796+
export const heal: any
797+
798+
/**
799+
* AI assistant module
800+
*/
801+
export const ai: any
802+
803+
/**
804+
* Workers for parallel execution
805+
*/
806+
export const Workers: any
807+
808+
/**
809+
* Secret value type for sensitive data
810+
*/
811+
export const Secret: typeof CodeceptJS.Secret
812+
813+
/**
814+
* Create a secret value
815+
*/
816+
export const secret: typeof CodeceptJS.secret
641817
}
642818

643819
declare module '@codeceptjs/helper' {

0 commit comments

Comments
 (0)