@@ -85,7 +85,7 @@ function getItLabelDetails(tsVer: TestDef): string {
85
85
}
86
86
87
87
describe ( "compatibility of typings for typescript versions" , function ( ) {
88
- let execCmd : "pnpm" | "npm" | "yarn"
88
+ let execCmd : "pnpm" | "npm" | "yarn" = "npm"
89
89
90
90
before ( async function ( ) {
91
91
this . timeout ( 10000 )
@@ -111,77 +111,76 @@ describe("compatibility of typings for typescript versions", function () {
111
111
)
112
112
}
113
113
114
+ // eslint-disable-next-line require-atomic-updates
114
115
execCmd = packageManagers [ packageManagerIndex ]
115
116
}
116
117
} )
117
118
118
119
for ( const tsVer of tsVersions ) {
120
+ // eslint-disable-next-line no-loop-func
119
121
describe ( `when used in a project with typescript version ${ tsVer . version } ` , function ( ) {
120
122
// must increase timeout for allowing `npm install`'ing the version of
121
123
// the typescript package to complete
122
124
this . timeout ( 30000 )
123
125
124
126
const tscTargetPath = path . resolve ( tscTestBasePath , `ts-${ tsVer . version } ` )
125
127
126
- beforeEach ( done => {
127
- emptyDir ( tscTargetPath ) . then ( ( ) => {
128
- Promise . all ( [
129
- readJson ( path . resolve ( templateSrcPath , "tsconfig.json" ) ) . then (
130
- pkg => {
131
- pkg . compilerOptions . target = tsVer . minTarget
132
- if ( tsVer . requiredLibs ) {
133
- pkg . compilerOptions . lib = addLibs (
134
- tsVer . requiredLibs ,
135
- pkg . compilerOptions . lib ,
136
- )
137
- }
138
- return writeJson (
139
- path . resolve ( tscTargetPath , "tsconfig.json" ) ,
140
- pkg ,
141
- )
142
- } ,
143
- ) ,
144
- readJson ( path . resolve ( templateSrcPath , "package.json" ) ) . then (
145
- pkg => {
146
- pkg . name = `test-typings-ts- ${ tsVer . version } `
147
- pkg . devDependencies . typescript = ` ${ tsVer . version } `
148
- return writeJson (
149
- path . resolve ( tscTargetPath , "package.json" ) ,
150
- pkg ,
151
- )
152
- } ,
153
- ) ,
154
- srcStr . then ( content =>
155
- writeFile (
156
- path . resolve ( tscTargetPath , "typings-test.ts" ) ,
157
- content ,
158
- "utf8" ,
159
- ) ,
160
- ) ,
161
- ] )
162
- . then ( ( ) => run ( ` ${ execCmd } install` , tscTargetPath , false ) )
163
- . catch ( err => {
164
- if ( err ) {
165
- done ( err )
166
- }
167
- } )
168
- . then ( ( ) => done ( ) )
169
- } )
128
+ beforeEach ( async ( ) => {
129
+ await emptyDir ( tscTargetPath )
130
+
131
+ await Promise . all ( [
132
+ ( async ( ) => {
133
+ const tsConfig = await readJson (
134
+ path . resolve ( templateSrcPath , "tsconfig.json" ) ,
135
+ )
136
+
137
+ tsConfig . compilerOptions . target = tsVer . minTarget
138
+ if ( tsVer . requiredLibs ) {
139
+ tsConfig . compilerOptions . lib = addLibs (
140
+ tsVer . requiredLibs ,
141
+ tsConfig . compilerOptions . lib as string [ ] ,
142
+ )
143
+ }
144
+ return writeJson (
145
+ path . resolve ( tscTargetPath , "tsconfig.json" ) ,
146
+ tsConfig ,
147
+ )
148
+ } ) ( ) ,
149
+ ( async ( ) => {
150
+ const pkgJson = await readJson (
151
+ path . resolve ( templateSrcPath , "package.json" ) ,
152
+ )
153
+
154
+ pkgJson . name = `test-typings-ts- ${ tsVer . version } `
155
+ pkgJson . devDependencies . typescript = ` ${ tsVer . version } `
156
+ return writeJson (
157
+ path . resolve ( tscTargetPath , "package.json" ) ,
158
+ pkgJson ,
159
+ )
160
+ } ) ( ) ,
161
+ ( async ( ) => {
162
+ const content = await srcStr
163
+ return writeFile (
164
+ path . resolve ( tscTargetPath , "typings-test.ts" ) ,
165
+ content ,
166
+ "utf8" ,
167
+ )
168
+ } ) ( ) ,
169
+ ] )
170
+
171
+ await run ( ` ${ execCmd } install` , tscTargetPath , false )
170
172
} )
171
173
172
- afterEach ( done => {
173
- remove ( tscTargetPath , err => {
174
- if ( err ) {
175
- return done ( err )
176
- }
177
- done ( )
178
- } )
174
+ afterEach ( async ( ) => {
175
+ await remove ( tscTargetPath )
179
176
} )
180
177
181
178
it ( `it should compile successfully with tsc ${ getItLabelDetails (
182
179
tsVer ,
183
180
) } `, async function ( ) {
184
- const cmd = execCmd === "npm" ? `${ execCmd } run` : execCmd
181
+ const cmd = [ "npm" , "pnpm" ] . includes ( execCmd )
182
+ ? `${ execCmd } run`
183
+ : execCmd
185
184
const errMsg = ( await run ( `${ cmd } test` , tscTargetPath , true ) ) as
186
185
| string
187
186
| undefined
0 commit comments