Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 189980e

Browse files
tarekshaclaudiahdz
authored andcommittedOct 9, 2019
test: deletes node_modules contents but keep the dir itself
PR-URL: #1 Credit: @tareqhs Close: #1 Reviewed-by: @claudiahdz
1 parent f668181 commit 189980e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
 

‎test/specs/index.js

+39
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,45 @@ test('handles dependency list with only shallow subdeps', t => {
168168
})
169169
})
170170

171+
test('deletes node_modules/ contents, without deleting node_modules/ itself', t => {
172+
const fixture = new Tacks(Dir({
173+
'node_modules': Dir({
174+
'stale-dependency': Dir({
175+
'package.json': File({
176+
name: 'stale-dependency',
177+
version: '1.0.0'
178+
})
179+
})
180+
}),
181+
'package.json': File({
182+
name: pkgName,
183+
version: pkgVersion
184+
}),
185+
'package-lock.json': File({
186+
dependencies: {},
187+
lockfileVersion: 1
188+
})
189+
}))
190+
fixture.create(prefix)
191+
192+
let notNodeModulesDeleted = true
193+
const nodeModulesDir = path.join(prefix, 'node_modules')
194+
const watcher = fs.watch(nodeModulesDir, () => {
195+
if (!fs.existsSync(nodeModulesDir)) {
196+
notNodeModulesDeleted = false
197+
}
198+
})
199+
200+
return run().then(() => {
201+
t.ok(
202+
!fs.existsSync(path.join(nodeModulesDir, 'stale-dependency')),
203+
'node_modules/ contents were deleted'
204+
)
205+
watcher.close()
206+
t.ok(notNodeModulesDeleted, 'node_modules/ itself was not deleted')
207+
})
208+
})
209+
171210
test('handles dependency list with only deep subdeps', t => {
172211
const fixture = new Tacks(Dir({
173212
'package.json': File({

0 commit comments

Comments
 (0)
This repository has been archived.