Skip to content

Commit 8a804c4

Browse files
Mazuhmazuh
authored and
mazuh
committed
fix tests for windows
removing directories with .sync is limited on windows so I refactored my test to always use an available folder instead of concurring with the existing one
1 parent bef3f12 commit 8a804c4

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ yarn.lock
148148
test.sock
149149

150150
# test artifacts
151-
test/workdir
151+
test/workdir*
152152
test/fixtures/*.js
153153
.vscode/launch.json
154154
.vscode/settings.json

test/generate.test.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ function define (t) {
132132
test('--standardlint option will add standard lint dependencies and scripts to javascript template', async (t) => {
133133
t.plan(14 + 3)
134134
try {
135-
rimraf.sync(workdir)
136-
await pExec('node ../generate workdir --standardlint', { cwd: path.join(workdir, '..') })
135+
const dir = path.join(__dirname, 'workdir-with-lint')
136+
const cwd = path.join(dir, '..')
137+
const bin = path.join('..', 'generate')
138+
rimraf.sync(dir)
139+
await pExec(`node ${bin} ${dir} --standardlint`, { cwd })
137140

138-
await verifyPkg(t)
141+
await verifyPkg(t, dir, 'workdir-with-lint')
139142

140-
const data = await fsPromises.readFile(path.join(workdir, 'package.json'))
143+
const data = await fsPromises.readFile(path.join(dir, 'package.json'))
141144
const pkg = JSON.parse(data)
142145
t.equal(pkg.scripts.pretest, 'standard')
143146
t.equal(pkg.scripts.lint, 'standard --fix')
@@ -147,14 +150,14 @@ function define (t) {
147150
}
148151
})
149152

150-
function verifyPkg (t) {
153+
function verifyPkg (t, dir = workdir, pkgName = 'workdir') {
151154
return new Promise((resolve, reject) => {
152-
const pkgFile = path.join(workdir, 'package.json')
155+
const pkgFile = path.join(dir, 'package.json')
153156

154157
readFile(pkgFile, function (err, data) {
155158
err && reject(err)
156159
const pkg = JSON.parse(data)
157-
t.equal(pkg.name, 'workdir')
160+
t.equal(pkg.name, pkgName)
158161
// we are not checking author because it depends on global npm configs
159162
t.equal(pkg.version, '1.0.0')
160163
t.equal(pkg.description, 'This project was bootstrapped with Fastify-CLI.')

0 commit comments

Comments
 (0)