diff options
author | nlf <quitlahok@gmail.com> | 2022-06-21 23:50:10 +0300 |
---|---|---|
committer | Nathan Fritz <fritzy@github.com> | 2022-06-22 23:46:13 +0300 |
commit | 3e28f3ccd5d09c9c2a1036cd4cd98571ac737808 (patch) | |
tree | c24eb5b0fd2c8eee2b7f60a0fb905554d53e294b /test | |
parent | 2c06ceee82dd813c0ae84cc0b09e6941cfc5533e (diff) |
chore(tests): fix tests for @npmcli/run-script@4.1.0 update
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/commands/edit.js | 28 | ||||
-rw-r--r-- | test/lib/commands/restart.js | 10 | ||||
-rw-r--r-- | test/lib/commands/start.js | 11 | ||||
-rw-r--r-- | test/lib/commands/stop.js | 10 | ||||
-rw-r--r-- | test/lib/commands/test.js | 10 |
5 files changed, 57 insertions, 12 deletions
diff --git a/test/lib/commands/edit.js b/test/lib/commands/edit.js index 1943e8c5f..bf7bd3155 100644 --- a/test/lib/commands/edit.js +++ b/test/lib/commands/edit.js @@ -1,4 +1,5 @@ const t = require('tap') +const fs = require('fs') const path = require('path') const tspawk = require('../../fixtures/tspawk') const { load: loadMockNpm } = require('../../fixtures/mock-npm') @@ -45,7 +46,14 @@ t.test('npm edit', async t => { spawk.spawn('testeditor', [semverPath]) spawk.spawn( scriptShell, - args => args.includes('testinstall'), + 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 } ) await npm.exec('edit', ['semver']) @@ -62,7 +70,14 @@ t.test('rebuild failure', async t => { spawk.spawn('testeditor', [semverPath]) spawk.spawn( scriptShell, - args => args.includes('testinstall'), + 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') await t.rejects( @@ -98,7 +113,14 @@ t.test('npm edit editor has flags', async t => { spawk.spawn('testeditor', ['--flag', semverPath]) spawk.spawn( scriptShell, - args => args.includes('testinstall'), + 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 } ) await npm.exec('edit', ['semver']) diff --git a/test/lib/commands/restart.js b/test/lib/commands/restart.js index 84bd93d8c..428ecb6b2 100644 --- a/test/lib/commands/restart.js +++ b/test/lib/commands/restart.js @@ -1,3 +1,5 @@ +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,8 +28,12 @@ t.test('should run restart script from package.json', async t => { }) const [scriptShell] = makeSpawnArgs({ path: npm.prefix }) const script = spawk.spawn(scriptShell, (args) => { - t.ok(args.includes('node ./test-restart.js "foo"'), 'ran restart script with extra args') - return true + 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 }) 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 8fc73493d..8f0d3c38b 100644 --- a/test/lib/commands/start.js +++ b/test/lib/commands/start.js @@ -1,3 +1,5 @@ +const fs = require('fs') +const path = require('path') const t = require('tap') const tspawk = require('../../fixtures/tspawk') const { load: loadMockNpm } = require('../../fixtures/mock-npm') @@ -10,7 +12,6 @@ const spawk = tspawk(t) const makeSpawnArgs = require('@npmcli/run-script/lib/make-spawn-args.js') t.test('should run start script from package.json', async t => { - t.plan(2) const { npm } = await loadMockNpm(t, { prefixDir: { 'package.json': JSON.stringify({ @@ -27,8 +28,12 @@ t.test('should run start script from package.json', async t => { }) const [scriptShell] = makeSpawnArgs({ path: npm.prefix }) const script = spawk.spawn(scriptShell, (args) => { - t.ok(args.includes('node ./test-start.js "foo"'), 'ran start script with extra args') - return true + 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 }) 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 f2aef2189..234eb2cf4 100644 --- a/test/lib/commands/stop.js +++ b/test/lib/commands/stop.js @@ -1,3 +1,5 @@ +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,8 +28,12 @@ t.test('should run stop script from package.json', async t => { }) const [scriptShell] = makeSpawnArgs({ path: npm.prefix }) const script = spawk.spawn(scriptShell, (args) => { - t.ok(args.includes('node ./test-stop.js "foo"'), 'ran stop script with extra args') - return true + 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 }) 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 e9ea0a3c8..ee6dae902 100644 --- a/test/lib/commands/test.js +++ b/test/lib/commands/test.js @@ -1,3 +1,5 @@ +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,8 +28,12 @@ t.test('should run test script from package.json', async t => { }) const [scriptShell] = makeSpawnArgs({ path: npm.prefix }) const script = spawk.spawn(scriptShell, (args) => { - t.ok(args.includes('node ./test-test.js "foo"'), 'ran test script with extra args') - return true + 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 }) await npm.exec('test', ['foo']) t.ok(script.called, 'script ran') |