1
1
import fs from 'fs' ;
2
2
import assert from 'assert' ;
3
- import path from 'path' ;
3
+ import path , { dirname } from 'path' ;
4
4
import { exec , execSync } from 'child_process' ;
5
5
import { Project , StructureKind , ts } from 'ts-morph' ;
6
+ import { expect } from 'chai' ;
6
7
7
8
import chai_subset from 'chai-subset' ;
9
+ import { fileURLToPath } from 'url' ;
10
+ import { createRequire } from 'node:module' ;
8
11
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' ) ;
12
17
const pathToRootOfProject = path . join ( __dirname , '../../' ) ;
13
18
const pathOfStaticDefinitions = path . join ( pathToRootOfProject , 'typings/index.d.ts' ) ;
14
19
const pathOfJSDocDefinitions = path . join ( pathToRootOfProject , 'typings/types.d.ts' ) ;
@@ -54,19 +59,19 @@ describe('Definitions', function () {
54
59
it ( 'should have internal object that is available as variable codeceptjs' , ( done ) => {
55
60
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
56
61
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
57
- types . should . be . valid ;
62
+ expect ( types ) . to . be . valid ;
58
63
59
64
const definitionsFile = types . getSourceFileOrThrow ( pathOfJSDocDefinitions ) ;
60
65
const index = definitionsFile . getModule ( 'CodeceptJS' ) . getModule ( 'index' ) . getStructure ( ) ;
61
- index . statements . should . containSubset ( [
66
+ expect ( index . statements ) . to . containSubset ( [
62
67
{ declarations : [ { name : 'recorder' , type : 'CodeceptJS.recorder' } ] } ,
63
68
{ declarations : [ { name : 'event' , type : 'typeof CodeceptJS.event' } ] } ,
64
69
{ declarations : [ { name : 'output' , type : 'typeof CodeceptJS.output' } ] } ,
65
70
{ declarations : [ { name : 'config' , type : 'typeof CodeceptJS.Config' } ] } ,
66
71
{ declarations : [ { name : 'container' , type : 'typeof CodeceptJS.Container' } ] } ,
67
72
] ) ;
68
73
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' ) ;
70
75
done ( ) ;
71
76
} ) ;
72
77
} ) ;
@@ -76,11 +81,11 @@ describe('Definitions', function () {
76
81
exec ( `${ runner } def ${ codecept_dir } ` , ( err , stdout ) => {
77
82
expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
78
83
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
79
- types . should . be . valid ;
84
+ expect ( types ) . to . valid ;
80
85
81
86
const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
82
87
const extend = getExtends ( definitionFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'I' ) ) ;
83
- extend . should . containSubset ( [ {
88
+ expect ( extend ) . to . containSubset ( [ {
84
89
methods : [ {
85
90
name : 'amInPath' ,
86
91
returnType : 'void' ,
@@ -100,12 +105,12 @@ describe('Definitions', function () {
100
105
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( err , stdout ) => {
101
106
expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
102
107
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
103
- types . should . be . valid ;
108
+ expect ( types ) . to . valid ;
104
109
105
110
const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
106
111
const extend = definitionFile . getFullText ( ) ;
107
112
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');" ) ;
109
114
assert ( ! err ) ;
110
115
done ( ) ;
111
116
} ) ;
@@ -115,7 +120,7 @@ describe('Definitions', function () {
115
120
exec ( `${ runner } def --config ${ codecept_dir } /../../codecept.ddt.js` , ( err , stdout ) => {
116
121
expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
117
122
const types = typesFrom ( `${ codecept_dir } /../../steps.d.ts` ) ;
118
- types . should . be . valid ;
123
+ expect ( types ) . to . valid ;
119
124
assert ( ! err ) ;
120
125
done ( ) ;
121
126
} ) ;
@@ -124,7 +129,7 @@ describe('Definitions', function () {
124
129
it ( 'def should create definition file with support object' , ( done ) => {
125
130
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
126
131
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
127
- types . should . be . valid ;
132
+ expect ( types ) . to . valid ;
128
133
129
134
const definitionsFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
130
135
const MyPage = getAliasStructure ( definitionsFile . getTypeAliasOrThrow ( 'MyPage' ) ) ;
@@ -148,7 +153,7 @@ describe('Definitions', function () {
148
153
it ( 'def should create definition file with inject which contains support objects' , ( done ) => {
149
154
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
150
155
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
151
- types . should . be . valid ;
156
+ expect ( types ) . to . valid ;
152
157
153
158
const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
154
159
const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -166,7 +171,7 @@ describe('Definitions', function () {
166
171
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( err ) => {
167
172
assert ( ! err ) ;
168
173
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
169
- types . should . be . valid ;
174
+ expect ( types ) . to . valid ;
170
175
171
176
const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
172
177
const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -185,7 +190,7 @@ describe('Definitions', function () {
185
190
it ( 'def should create definition file with inject which contains I object from helpers' , ( done ) => {
186
191
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.powi.js` , ( ) => {
187
192
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
188
- types . should . be . valid ;
193
+ expect ( types ) . to . valid ;
189
194
190
195
const definitionsFile = types . getSourceFileOrThrow ( pathOfStaticDefinitions ) ;
191
196
const returned = getReturnStructure ( definitionsFile . getFunctionOrThrow ( 'inject' ) ) ;
@@ -199,7 +204,7 @@ describe('Definitions', function () {
199
204
it ( 'def should create definition file with callback params' , ( done ) => {
200
205
exec ( `${ runner } def --config ${ codecept_dir } /codecept.inject.po.js` , ( ) => {
201
206
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
202
- types . should . be . valid ;
207
+ expect ( types ) . to . valid ;
203
208
204
209
const definitionsFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
205
210
const CallbackOrder = definitionsFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'SupportObject' ) . getStructure ( ) ;
@@ -216,11 +221,11 @@ describe('Definitions', function () {
216
221
exec ( `${ runner } def --config ${ codecept_dir } /codecept.promise.based.js` , ( err , stdout ) => {
217
222
expect ( stdout ) . to . include ( 'Definitions were generated in steps.d.ts' ) ;
218
223
const types = typesFrom ( `${ codecept_dir } /steps.d.ts` ) ;
219
- types . should . be . valid ;
224
+ expect ( types ) . to . valid ;
220
225
221
226
const definitionFile = types . getSourceFileOrThrow ( `${ codecept_dir } /steps.d.ts` ) ;
222
227
const extend = getExtends ( definitionFile . getModule ( 'CodeceptJS' ) . getInterfaceOrThrow ( 'I' ) ) ;
223
- extend . should . containSubset ( [ {
228
+ expect ( extend ) . to . containSubset ( [ {
224
229
methods : [ {
225
230
name : 'amInPath' ,
226
231
returnType : 'Promise<any>' ,
0 commit comments