11import fs from 'fs' ;
22import assert from 'assert' ;
3- import path from 'path' ;
3+ import path , { dirname } from 'path' ;
44import { exec , execSync } from 'child_process' ;
55import { Project , StructureKind , ts } from 'ts-morph' ;
6+ import { expect } from 'chai' ;
67
78import chai_subset from 'chai-subset' ;
9+ import { fileURLToPath } from 'url' ;
10+ import { createRequire } from 'node:module' ;
811
9- const __dirname = path . resolve ( '.' ) ;
10- const runner = path . join ( __dirname , 'bin/codecept.js' ) ;
11- const codecept_dir = path . join ( __dirname , 'test/data/sandbox/configs/definitions' ) ;
12+ const require = createRequire ( import . meta. url ) ;
13+
14+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
15+ const runner = path . join ( __dirname , '../../bin/codecept.js' ) ;
16+ const codecept_dir = path . join ( __dirname , '../../test/data/sandbox/configs/definitions' ) ;
1217const pathToRootOfProject = path . join ( __dirname , '../../' ) ;
1318const pathOfStaticDefinitions = path . join ( pathToRootOfProject , 'typings/index.d.ts' ) ;
1419const pathOfJSDocDefinitions = path . join ( pathToRootOfProject , 'typings/types.d.ts' ) ;
@@ -54,19 +59,19 @@ describe('Definitions', function () {
5459 it ( 'should have internal object that is available as variable codeceptjs' , ( done ) => {
5560 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
5661 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
57- types . should . be . valid ;
62+ expect ( types ) . to . be . valid ;
5863
5964 const definitionsFile = types . getSourceFileOrThrow ( pathOfJSDocDefinitions ) ;
6065 const index = definitionsFile . getModule ( 'CodeceptJS' ) . getModule ( 'index' ) . getStructure ( ) ;
61- index . statements . should . containSubset ( [
66+ expect ( index . statements ) . to . containSubset ( [
6267 { declarations : [ { name : 'recorder' , type : 'CodeceptJS.recorder' } ] } ,
6368 { declarations : [ { name : 'event' , type : 'typeof CodeceptJS.event' } ] } ,
6469 { declarations : [ { name : 'output' , type : 'typeof CodeceptJS.output' } ] } ,
6570 { declarations : [ { name : 'config' , type : 'typeof CodeceptJS.Config' } ] } ,
6671 { declarations : [ { name : 'container' , type : 'typeof CodeceptJS.Container' } ] } ,
6772 ] ) ;
6873 const codeceptjs = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) . getVariableDeclarationOrThrow ( 'codeceptjs' ) . getStructure ( ) ;
69- codeceptjs . type . should . equal ( 'typeof CodeceptJS.index' ) ;
74+ expect ( codeceptjs . type ) . to . equal ( 'typeof CodeceptJS.index' ) ;
7075 done ( ) ;
7176 } ) ;
7277 } ) ;
@@ -76,11 +81,11 @@ describe('Definitions', function () {
7681 exec ( `${ runner } def ${ codecept_dir } ` , ( err , stdout ) => {
7782 expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
7883 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
79- types . should . be . valid ;
84+ expect ( types ) . to . valid ;
8085
8186 const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
8287 const extend = getExtends ( definitionFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'I' ) ) ;
83- extend . should . containSubset ( [ {
88+ expect ( extend ) . to . containSubset ( [ {
8489 methods : [ {
8590 name : 'amInPath' ,
8691 returnType : 'void' ,
@@ -100,12 +105,12 @@ describe('Definitions', function () {
100105 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( err , stdout ) => {
101106 expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
102107 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
103- types . should . be . valid ;
108+ expect ( types ) . to . valid ;
104109
105110 const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
106111 const extend = definitionFile . getFullText ( ) ;
107112
108- extend . should . include ( "type CurrentPage = typeof import('./po/custom_steps.js');" ) ;
113+ expect ( extend ) . to . include ( "type CurrentPage = typeof import('./po/custom_steps.js');" ) ;
109114 assert ( ! err ) ;
110115 done ( ) ;
111116 } ) ;
@@ -115,7 +120,7 @@ describe('Definitions', function () {
115120 exec ( `${ runner } def --config ${ codecept_dir } /../../codecept.ddt.js` , ( err , stdout ) => {
116121 expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
117122 const types = typesFrom ( `${ codecept_dir } /../../steps.d.ts` ) ;
118- types . should . be . valid ;
123+ expect ( types ) . to . valid ;
119124 assert ( ! err ) ;
120125 done ( ) ;
121126 } ) ;
@@ -124,7 +129,7 @@ describe('Definitions', function () {
124129 it ( 'def should create definition file with support object' , ( done ) => {
125130 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
126131 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
127- types . should . be . valid ;
132+ expect ( types ) . to . valid ;
128133
129134 const definitionsFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
130135 const MyPage = getAliasStructure ( definitionsFile . getTypeAliasOrThrow ( 'MyPage' ) ) ;
@@ -148,7 +153,7 @@ describe('Definitions', function () {
148153 it ( 'def should create definition file with inject which contains support objects' , ( done ) => {
149154 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
150155 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
151- types . should . be . valid ;
156+ expect ( types ) . to . valid ;
152157
153158 const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
154159 const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -166,7 +171,7 @@ describe('Definitions', function () {
166171 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( err ) => {
167172 assert ( ! err ) ;
168173 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
169- types . should . be . valid ;
174+ expect ( types ) . to . valid ;
170175
171176 const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
172177 const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -185,7 +190,7 @@ describe('Definitions', function () {
185190 it ( 'def should create definition file with inject which contains I object from helpers' , ( done ) => {
186191 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.powi.js` , ( ) => {
187192 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
188- types . should . be . valid ;
193+ expect ( types ) . to . valid ;
189194
190195 const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
191196 const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -199,7 +204,7 @@ describe('Definitions', function () {
199204 it ( 'def should create definition file with callback params' , ( done ) => {
200205 exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
201206 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
202- types . should . be . valid ;
207+ expect ( types ) . to . valid ;
203208
204209 const definitionsFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
205210 const CallbackOrder = definitionsFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'SupportObject' ) . getStructure ( ) ;
@@ -216,11 +221,11 @@ describe('Definitions', function () {
216221 exec ( `${ runner } def --config ${ codecept_dir } /codecept.promise.based.js` , ( err , stdout ) => {
217222 expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
218223 const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
219- types . should . be . valid ;
224+ expect ( types ) . to . valid ;
220225
221226 const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
222227 const extend = getExtends ( definitionFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'I' ) ) ;
223- extend . should . containSubset ( [ {
228+ expect ( extend ) . to . containSubset ( [ {
224229 methods : [ {
225230 name : 'amInPath' ,
226231 returnType : 'Promise<any>' ,
0 commit comments