Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2022-08-10 19:28:41 +0300
committerGar <wraithgar@github.com>2022-08-10 19:44:06 +0300
commit222f4fe985f58bf62882cdbb1ab0de3d872e9fd8 (patch)
treed5662109e32d4f5cd886bdbd9ad415e83d6066a8 /test
parent76e477c1f82fd5eca7028169b820cddf3155b4b4 (diff)
chore: fix tests for @npmcli/run-script@4.2.1
Diffstat (limited to 'test')
-rw-r--r--test/lib/commands/edit.js46
-rw-r--r--test/lib/commands/restart.js17
-rw-r--r--test/lib/commands/start.js17
-rw-r--r--test/lib/commands/stop.js16
-rw-r--r--test/lib/commands/test.js16
5 files changed, 29 insertions, 83 deletions
diff --git a/test/lib/commands/edit.js b/test/lib/commands/edit.js
index b2a10be13..22543f8e3 100644
--- a/test/lib/commands/edit.js
+++ b/test/lib/commands/edit.js
@@ -1,5 +1,4 @@
const t = require('tap')
-const fs = require('fs')
const path = require('path')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
@@ -39,24 +38,13 @@ t.test('npm edit', async t => {
const { npm, joinedOutput } = await loadMockNpm(t, npmConfig)
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
- const [scriptShell] = makeSpawnArgs({
+ const [scriptShell, scriptArgs] = makeSpawnArgs({
event: 'install',
path: npm.prefix,
cmd: 'testinstall',
})
spawk.spawn('testeditor', [semverPath])
- spawk.spawn(
- scriptShell,
- args => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('install')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('testinstall')
- return rightExtension && rightFilename && rightContents
- },
- { cwd: semverPath }
- )
+ spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath })
await npm.exec('edit', ['semver'])
t.match(joinedOutput(), 'rebuilt dependencies successfully')
})
@@ -64,24 +52,13 @@ t.test('npm edit', async t => {
t.test('rebuild failure', async t => {
const { npm } = await loadMockNpm(t, npmConfig)
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
- const [scriptShell] = makeSpawnArgs({
+ const [scriptShell, scriptArgs] = makeSpawnArgs({
event: 'install',
path: npm.prefix,
cmd: 'testinstall',
})
spawk.spawn('testeditor', [semverPath])
- spawk.spawn(
- scriptShell,
- args => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('install')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('testinstall')
- return rightExtension && rightFilename && rightContents
- },
- { cwd: semverPath }
- ).exit(1).stdout('test error')
+ spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath }).exit(1).stdout('test error')
await t.rejects(
npm.exec('edit', ['semver']),
{ message: 'command failed' }
@@ -108,24 +85,13 @@ t.test('npm edit editor has flags', async t => {
})
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
- const [scriptShell] = makeSpawnArgs({
+ const [scriptShell, scriptArgs] = makeSpawnArgs({
event: 'install',
path: npm.prefix,
cmd: 'testinstall',
})
spawk.spawn('testeditor', ['--flag', semverPath])
- spawk.spawn(
- scriptShell,
- args => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('install')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('testinstall')
- return rightExtension && rightFilename && rightContents
- },
- { cwd: semverPath }
- )
+ spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath })
await npm.exec('edit', ['semver'])
})
diff --git a/test/lib/commands/restart.js b/test/lib/commands/restart.js
index bfbe715e8..c2257b8ce 100644
--- a/test/lib/commands/restart.js
+++ b/test/lib/commands/restart.js
@@ -1,5 +1,3 @@
-const fs = require('fs')
-const path = require('path')
const t = require('tap')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
@@ -26,15 +24,14 @@ t.test('should run restart script from package.json', async t => {
loglevel: 'silent',
},
})
- const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-restart.js' })
- const script = spawk.spawn(scriptShell, (args) => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('restart')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('foo')
- return rightExtension && rightFilename && rightContents
+ const [scriptShell, scriptArgs] = makeSpawnArgs({
+ path: npm.prefix,
+ cmd: 'node ./test-restart.js',
})
+ let scriptContent = scriptArgs.pop()
+ scriptContent += ' foo'
+ scriptArgs.push(scriptContent)
+ const script = spawk.spawn(scriptShell, scriptArgs)
await npm.exec('restart', ['foo'])
t.ok(script.called, 'script ran')
})
diff --git a/test/lib/commands/start.js b/test/lib/commands/start.js
index 79c2133bc..3caaa478f 100644
--- a/test/lib/commands/start.js
+++ b/test/lib/commands/start.js
@@ -1,5 +1,3 @@
-const fs = require('fs')
-const path = require('path')
const t = require('tap')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
@@ -26,15 +24,12 @@ t.test('should run start script from package.json', async t => {
loglevel: 'silent',
},
})
- const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-start.js' })
- const script = spawk.spawn(scriptShell, (args) => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('start')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('foo')
- return rightExtension && rightFilename && rightContents
- })
+ const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-start.js' })
+ // we're calling the script with 'foo' as an argument, so add that to the script
+ let scriptContent = scriptArgs.pop()
+ scriptContent += ' foo'
+ scriptArgs.push(scriptContent)
+ const script = spawk.spawn(scriptShell, scriptArgs)
await npm.exec('start', ['foo'])
t.ok(script.called, 'script ran')
})
diff --git a/test/lib/commands/stop.js b/test/lib/commands/stop.js
index 1a4abd0b3..72c2843ad 100644
--- a/test/lib/commands/stop.js
+++ b/test/lib/commands/stop.js
@@ -1,5 +1,3 @@
-const fs = require('fs')
-const path = require('path')
const t = require('tap')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
@@ -26,15 +24,11 @@ t.test('should run stop script from package.json', async t => {
loglevel: 'silent',
},
})
- const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-stop.js' })
- const script = spawk.spawn(scriptShell, (args) => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('stop')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('foo')
- return rightExtension && rightFilename && rightContents
- })
+ const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-stop.js' })
+ let scriptContent = scriptArgs.pop()
+ scriptContent += ' foo'
+ scriptArgs.push(scriptContent)
+ const script = spawk.spawn(scriptShell, scriptArgs)
await npm.exec('stop', ['foo'])
t.ok(script.called, 'script ran')
})
diff --git a/test/lib/commands/test.js b/test/lib/commands/test.js
index c6d3f530b..a6a6f723a 100644
--- a/test/lib/commands/test.js
+++ b/test/lib/commands/test.js
@@ -1,5 +1,3 @@
-const fs = require('fs')
-const path = require('path')
const t = require('tap')
const tspawk = require('../../fixtures/tspawk')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
@@ -26,15 +24,11 @@ t.test('should run test script from package.json', async t => {
loglevel: 'silent',
},
})
- const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-test.js' })
- const script = spawk.spawn(scriptShell, (args) => {
- const lastArg = args[args.length - 1]
- const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
- const rightFilename = path.basename(lastArg).startsWith('test')
- const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
- .trim().endsWith('foo')
- return rightExtension && rightFilename && rightContents
- })
+ const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-test.js' })
+ let scriptContent = scriptArgs.pop()
+ scriptContent += ' foo'
+ scriptArgs.push(scriptContent)
+ const script = spawk.spawn(scriptShell, scriptArgs)
await npm.exec('test', ['foo'])
t.ok(script.called, 'script ran')
})