Skip to content

Commit cf84548

Browse files
committed
fix: use async await in typing compat tests
1 parent aaadcc0 commit cf84548

File tree

1 file changed

+52
-53
lines changed

1 file changed

+52
-53
lines changed

test/unit/typings-compatibility-test.ts

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function getItLabelDetails(tsVer: TestDef): string {
8585
}
8686

8787
describe("compatibility of typings for typescript versions", function () {
88-
let execCmd: "pnpm" | "npm" | "yarn"
88+
let execCmd: "pnpm" | "npm" | "yarn" = "npm"
8989

9090
before(async function () {
9191
this.timeout(10000)
@@ -111,77 +111,76 @@ describe("compatibility of typings for typescript versions", function () {
111111
)
112112
}
113113

114+
// eslint-disable-next-line require-atomic-updates
114115
execCmd = packageManagers[packageManagerIndex]
115116
}
116117
})
117118

118119
for (const tsVer of tsVersions) {
120+
// eslint-disable-next-line no-loop-func
119121
describe(`when used in a project with typescript version ${tsVer.version}`, function () {
120122
// must increase timeout for allowing `npm install`'ing the version of
121123
// the typescript package to complete
122124
this.timeout(30000)
123125

124126
const tscTargetPath = path.resolve(tscTestBasePath, `ts-${tsVer.version}`)
125127

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)
170172
})
171173

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)
179176
})
180177

181178
it(`it should compile successfully with tsc ${getItLabelDetails(
182179
tsVer,
183180
)}`, async function () {
184-
const cmd = execCmd === "npm" ? `${execCmd} run` : execCmd
181+
const cmd = ["npm", "pnpm"].includes(execCmd)
182+
? `${execCmd} run`
183+
: execCmd
185184
const errMsg = (await run(`${cmd} test`, tscTargetPath, true)) as
186185
| string
187186
| undefined

0 commit comments

Comments
 (0)