Skip to content

Commit

Permalink
chore: spawk postpack command too
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Oct 5, 2022
1 parent d6bda3f commit 559b6a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions workspaces/libnpmpack/test/fixtures/tspawk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const spawk = require('spawk')
module.exports = tspawk

function tspawk (t) {
spawk.preventUnmatched()
t.teardown(function () {
spawk.unload()
})
Expand Down
15 changes: 12 additions & 3 deletions workspaces/libnpmpack/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const t = require('tap')

const tspawk = require('./fixtures/tspawk.js')
const spawk = tspawk(t)

const fs = require('fs')
const path = require('path')
Expand Down Expand Up @@ -141,6 +140,7 @@ t.test('packs from registry spec', async t => {

t.test('runs scripts in foreground when foregroundScripts === true', async t => {
const { npm } = await loadMockNpm(t, {})
const spawk = tspawk(t)

const testDir = t.testdir({
'package.json': JSON.stringify({
Expand All @@ -156,20 +156,29 @@ t.test('runs scripts in foreground when foregroundScripts === true', async t =>
const cwd = process.cwd()
process.chdir(testDir)

const [scriptShell, scriptArgs] = makeSpawnArgs({
const [preScriptShell, preScriptArgs] = makeSpawnArgs({
event: 'prepack',
path: npm.prefix,
cmd: 'touch prepack',
})

const prepack = spawk.spawn(scriptShell, scriptArgs)
const prepack = spawk.spawn(preScriptShell, preScriptArgs)

const [postScriptShell, postScriptArgs] = makeSpawnArgs({
event: 'postpack',
path: npm.prefix,
cmd: 'touch postpack',
})

const postpack = spawk.spawn(postScriptShell, postScriptArgs)

await pack('file:.', {
packDestination: testDir,
foregroundScripts: true,
})

t.ok(prepack.called)
t.ok(postpack.called)

t.teardown(async () => {
process.chdir(cwd)
Expand Down

0 comments on commit 559b6a7

Please sign in to comment.