Skip to content

Commit 1815776

Browse files
committed
Add tests
1 parent 417958b commit 1815776

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

workspaces/arborist/test/isolated-mode.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,36 @@ tap.test('postinstall scripts are run', async t => {
15711571
t.ok(postInstallRanBar)
15721572
})
15731573

1574+
tap.test('postinstall scripts run once for store packages', async t => {
1575+
// Regression test: store links should not cause scripts to run twice.
1576+
// The store entry and its symlink both end up in the build queue, but
1577+
// only the store entry should run scripts.
1578+
const graph = {
1579+
registry: [
1580+
{
1581+
name: 'which',
1582+
version: '1.0.0',
1583+
scripts: {
1584+
postinstall: 'node -e "var c=0;try{c=+fs.readFileSync(\'postinstall-count\',\'utf8\')}catch(e){};fs.writeFileSync(\'postinstall-count\',String(c+1))"',
1585+
},
1586+
},
1587+
],
1588+
root: {
1589+
name: 'foo', version: '1.2.3', dependencies: { which: '1.0.0' },
1590+
},
1591+
}
1592+
1593+
const { dir, registry } = await getRepo(graph)
1594+
1595+
const cache = fs.mkdtempSync(`${getTempDir()}/test-`)
1596+
const arborist = new Arborist({ path: dir, registry, packumentCache: new Map(), cache })
1597+
await arborist.reify({ installStrategy: 'linked' })
1598+
1599+
const whichDir = setupRequire(dir)('which')
1600+
const count = Number(fs.readFileSync(`${whichDir}/postinstall-count`, 'utf8'))
1601+
t.equal(count, 1, 'postinstall ran exactly once')
1602+
})
1603+
15741604
tap.test('bins are installed', async t => {
15751605
// Input of arborist
15761606
const graph = {

0 commit comments

Comments
 (0)