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

Commit

Permalink
test: deletes node_modules contents but keep the dir itself
Browse files Browse the repository at this point in the history
PR-URL: #1
Credit: @tareqhs
Close: #3
Reviewed-by: @claudiahdz
  • Loading branch information
tareksha authored and claudiahdz committed Oct 8, 2019
1 parent 535c17d commit 66ae722
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/specs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,45 @@ test('handles dependency list with only shallow subdeps', t => {
})
})

test('deletes node_modules/ contents, without deleting node_modules/ itself', t => {
const fixture = new Tacks(Dir({
'node_modules': Dir({
'stale-dependency': Dir({
'package.json': File({
name: 'stale-dependency',
version: '1.0.0'
})
})
}),
'package.json': File({
name: pkgName,
version: pkgVersion
}),
'package-lock.json': File({
dependencies: {},
lockfileVersion: 1
})
}))
fixture.create(prefix)

let notNodeModulesDeleted = true
const nodeModulesDir = path.join(prefix, 'node_modules')
const watcher = fs.watch(nodeModulesDir, () => {
if (!fs.existsSync(nodeModulesDir)) {
notNodeModulesDeleted = false
}
})

return run().then(() => {
t.ok(
!fs.existsSync(path.join(nodeModulesDir, 'stale-dependency')),
'node_modules/ contents were deleted'
)
watcher.close()
t.ok(notNodeModulesDeleted, 'node_modules/ itself was not deleted')
})
})

test('handles dependency list with only deep subdeps', t => {
const fixture = new Tacks(Dir({
'package.json': File({
Expand Down

0 comments on commit 66ae722

Please sign in to comment.