Skip to content

Commit 6f949c9

Browse files
authored
Export container as named export for ESM (#5382)
* export container as named export for ESM TypeScript * add all export from codeceptjs and add tests * export all internal API objects from codeceptjs module * export all internal API objects from codeceptjs module * remove typeof
1 parent 95c56ae commit 6f949c9

File tree

5 files changed

+230
-0
lines changed

5 files changed

+230
-0
lines changed
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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,105 @@ declare namespace Mocha {
635635
}
636636
}
637637

638+
// Internal API types
638639
declare module 'codeceptjs' {
639640
export default codeceptjs
641+
642+
/**
643+
* Dependency Injection Container
644+
* Provides access to helpers, support objects, plugins, and translation
645+
*/
646+
export const container: typeof CodeceptJS.Container
647+
648+
/**
649+
* Test runner class
650+
*/
651+
export const codecept: typeof CodeceptJS.Codecept
652+
653+
/**
654+
* Output module for printing messages
655+
*/
656+
export const output: typeof CodeceptJS.output
657+
658+
/**
659+
* Event dispatcher for listening to CodeceptJS events
660+
*/
661+
export const event: typeof CodeceptJS.event
662+
663+
/**
664+
* Global promise chain recorder
665+
*/
666+
export const recorder: CodeceptJS.recorder
667+
668+
/**
669+
* Configuration module
670+
*/
671+
export const config: typeof CodeceptJS.Config
672+
673+
/**
674+
* Actor (I) constructor
675+
*/
676+
export const actor: CodeceptJS.actor
677+
678+
/**
679+
* Base Helper class
680+
*/
681+
export const helper: typeof CodeceptJS.Helper
682+
683+
/**
684+
* Pause execution until user input
685+
*/
686+
export const pause: typeof CodeceptJS.pause
687+
688+
/**
689+
* Execute steps within specific context
690+
*/
691+
export const within: typeof CodeceptJS.within
692+
693+
/**
694+
* Create data tables for data-driven tests
695+
*/
696+
export const dataTable: typeof CodeceptJS.DataTable
697+
698+
/**
699+
* Create data table arguments
700+
*/
701+
export const dataTableArgument: typeof CodeceptJS.DataTableArgument
702+
703+
/**
704+
* Shared store for test data
705+
*/
706+
export const store: typeof CodeceptJS.store
707+
708+
/**
709+
* Locator builder
710+
*/
711+
export const locator: typeof CodeceptJS.Locator
712+
713+
/**
714+
* Auto-healing module
715+
*/
716+
export const heal: any
717+
718+
/**
719+
* AI assistant module
720+
*/
721+
export const ai: any
722+
723+
/**
724+
* Workers for parallel execution
725+
*/
726+
export const Workers: any
727+
728+
/**
729+
* Secret value type for sensitive data
730+
*/
731+
export const Secret: typeof CodeceptJS.Secret
732+
733+
/**
734+
* Create a secret value
735+
*/
736+
export const secret: typeof CodeceptJS.Secret.secret
640737
}
641738

642739
declare module '@codeceptjs/helper' {

0 commit comments

Comments
 (0)