@@ -6,6 +6,74 @@ source /codecept/docker/help.sh
6
6
if [[ -d " /tests/" ]]; then
7
7
echo " CodeceptJS directory has been found."
8
8
9
+ # Set up module resolution
10
+ export NODE_PATH=/codecept/lib:$NODE_PATH
11
+
12
+ # Ensure ESM package.json exists in test directory
13
+ ensure_esm_package () {
14
+ local dir=" $1 "
15
+ if [ ! -f " $dir /package.json" ]; then
16
+ echo " Creating package.json with ESM in $dir "
17
+ cat > " $dir /package.json" << EOF
18
+ {
19
+ "type": "module"
20
+ }
21
+ EOF
22
+ elif ! grep -q ' "type".*"module"' " $dir /package.json" ; then
23
+ echo " Warning: $dir /package.json exists but may not have type: module"
24
+ fi
25
+ }
26
+
27
+ # Setup node_modules with ESM-compatible codeceptjs
28
+ setup_node_modules () {
29
+ local dir=" $1 "
30
+ local node_modules=" $dir /node_modules"
31
+ local codecept_module=" $node_modules /codeceptjs"
32
+
33
+ mkdir -p " $codecept_module "
34
+
35
+ cat > " $codecept_module /package.json" << 'EOF '
36
+ {
37
+ "name": "codeceptjs",
38
+ "type": "module",
39
+ "exports": {
40
+ ".": "./index.js",
41
+ "./effects": "./effects.js"
42
+ },
43
+ "main": "./index.js"
44
+ }
45
+ EOF
46
+
47
+ ln -sf /codecept/lib/index.js " $codecept_module /index.js"
48
+ ln -sf /codecept/lib/effects.js " $codecept_module /effects.js"
49
+
50
+ for dep_dir in /codecept/node_modules/* ; do
51
+ dep_name=$( basename " $dep_dir " )
52
+ if [ " $dep_name " != " codeceptjs" ] && [ ! -e " $node_modules /$dep_name " ]; then
53
+ ln -sf " $dep_dir " " $node_modules /$dep_name " 2> /dev/null || true
54
+ fi
55
+ done
56
+ }
57
+
58
+ # Find codecept config in current directory
59
+ config_file=$( find . -maxdepth 2 -name " codecept.conf.*" -type f | head -1)
60
+
61
+ if [ -n " $config_file " ]; then
62
+ config_dir=$( dirname " $config_file " )
63
+ ensure_esm_package " $config_dir "
64
+ setup_node_modules " $config_dir "
65
+ else
66
+ ensure_esm_package " $( pwd) "
67
+ setup_node_modules " $( pwd) "
68
+ fi
69
+
70
+ # Also setup node_modules in any subdirectories that might contain test files
71
+ for test_dir in acceptance test tests; do
72
+ if [ -d " $test_dir " ]; then
73
+ setup_node_modules " $test_dir "
74
+ fi
75
+ done
76
+
9
77
# Run the tests
10
78
cd /tests/ || exit
11
79
if [ " $RUN_MULTIPLE " = true ]; then
0 commit comments