-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: consolidate split-package-names #4632
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const spawk = require('spawk') | ||
|
||
module.exports = tspawk | ||
|
||
function tspawk (t) { | ||
spawk.preventUnmatched() | ||
t.teardown(function () { | ||
spawk.unload() | ||
}) | ||
t.afterEach(function () { | ||
spawk.done() | ||
}) | ||
return spawk | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,137 @@ | ||
const t = require('tap') | ||
const { resolve } = require('path') | ||
const { EventEmitter } = require('events') | ||
const path = require('path') | ||
const tspawk = require('../../fixtures/tspawk') | ||
const { load: loadMockNpm } = require('../../fixtures/mock-npm') | ||
|
||
let editorBin = null | ||
let editorArgs = null | ||
let editorOpts = null | ||
let EDITOR_CODE = 0 | ||
const childProcess = { | ||
spawn: (bin, args, opts) => { | ||
// save for assertions | ||
editorBin = bin | ||
editorArgs = args | ||
editorOpts = opts | ||
const spawk = tspawk(t) | ||
|
||
const editorEvents = new EventEmitter() | ||
process.nextTick(() => { | ||
editorEvents.emit('exit', EDITOR_CODE) | ||
}) | ||
return editorEvents | ||
}, | ||
} | ||
// TODO this ... smells. npm "script-shell" config mentions defaults but those | ||
// are handled by run-script, not npm. So for now we have to tie tests to some | ||
// pretty specific internals of runScript | ||
const makeSpawnArgs = require('@npmcli/run-script/lib/make-spawn-args.js') | ||
|
||
let rebuildArgs = null | ||
let rebuildFail = null | ||
let EDITOR = 'vim' | ||
const npm = { | ||
const npmConfig = { | ||
config: { | ||
get: () => EDITOR, | ||
'ignore-scripts': false, | ||
editor: 'testeditor', | ||
}, | ||
dir: resolve(__dirname, '../../../node_modules'), | ||
exec: async (cmd, args) => { | ||
rebuildArgs = args | ||
if (rebuildFail) { | ||
throw rebuildFail | ||
} | ||
prefixDir: { | ||
node_modules: { | ||
semver: { | ||
'package.json': JSON.stringify({ | ||
scripts: { | ||
install: 'testinstall', | ||
}, | ||
}), | ||
node_modules: { | ||
abbrev: {}, | ||
}, | ||
}, | ||
'@npmcli': { | ||
'scoped-package': {}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const gracefulFs = require('graceful-fs') | ||
const Edit = t.mock('../../../lib/commands/edit.js', { | ||
child_process: childProcess, | ||
'graceful-fs': gracefulFs, | ||
}) | ||
const edit = new Edit(npm) | ||
|
||
t.test('npm edit', async t => { | ||
t.teardown(() => { | ||
rebuildArgs = null | ||
editorBin = null | ||
editorArgs = null | ||
editorOpts = null | ||
}) | ||
const { npm, joinedOutput } = await loadMockNpm(t, npmConfig) | ||
|
||
await edit.exec(['semver']) | ||
const path = resolve(__dirname, '../../../node_modules/semver') | ||
t.strictSame(editorBin, EDITOR, 'used the correct editor') | ||
t.strictSame(editorArgs, [path], 'edited the correct directory') | ||
t.strictSame(editorOpts, { stdio: 'inherit' }, 'passed the correct opts') | ||
t.strictSame(rebuildArgs, [path], 'passed the correct path to rebuild') | ||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver') | ||
const [scriptShell] = makeSpawnArgs({ | ||
event: 'install', | ||
path: npm.prefix, | ||
}) | ||
spawk.spawn('testeditor', [semverPath]) | ||
spawk.spawn( | ||
scriptShell, | ||
args => args.includes('testinstall'), | ||
{ cwd: semverPath } | ||
) | ||
await npm.exec('edit', ['semver']) | ||
t.match(joinedOutput(), 'rebuilt dependencies successfully') | ||
}) | ||
|
||
t.test('rebuild fails', async t => { | ||
t.teardown(() => { | ||
rebuildFail = null | ||
rebuildArgs = null | ||
editorBin = null | ||
editorArgs = null | ||
editorOpts = null | ||
t.test('rebuild failure', async t => { | ||
const { npm } = await loadMockNpm(t, npmConfig) | ||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver') | ||
const [scriptShell] = makeSpawnArgs({ | ||
event: 'install', | ||
path: npm.prefix, | ||
}) | ||
spawk.spawn('testeditor', [semverPath]) | ||
spawk.spawn( | ||
scriptShell, | ||
args => args.includes('testinstall'), | ||
{ cwd: semverPath } | ||
).exit(1).stdout('test error') | ||
await t.rejects( | ||
npm.exec('edit', ['semver']), | ||
{ message: 'command failed' } | ||
) | ||
}) | ||
|
||
rebuildFail = new Error('test error') | ||
t.test('editor failure', async t => { | ||
const { npm } = await loadMockNpm(t, npmConfig) | ||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver') | ||
spawk.spawn('testeditor', [semverPath]).exit(1).stdout('test editor failure') | ||
await t.rejects( | ||
edit.exec(['semver']), | ||
{ message: 'test error' } | ||
npm.exec('edit', ['semver']), | ||
{ message: 'editor process exited with code: 1' } | ||
) | ||
const path = resolve(__dirname, '../../../node_modules/semver') | ||
t.strictSame(editorBin, EDITOR, 'used the correct editor') | ||
t.strictSame(editorArgs, [path], 'edited the correct directory') | ||
t.strictSame(editorOpts, { stdio: 'inherit' }, 'passed the correct opts') | ||
t.strictSame(rebuildArgs, [path], 'passed the correct path to rebuild') | ||
}) | ||
|
||
t.test('npm edit editor has flags', async t => { | ||
EDITOR = 'code -w' | ||
t.teardown(() => { | ||
rebuildArgs = null | ||
editorBin = null | ||
editorArgs = null | ||
editorOpts = null | ||
EDITOR = 'vim' | ||
const { npm } = await loadMockNpm(t, { | ||
...npmConfig, | ||
config: { | ||
...npmConfig.config, | ||
editor: 'testeditor --flag', | ||
}, | ||
}) | ||
|
||
await edit.exec(['semver']) | ||
|
||
const path = resolve(__dirname, '../../../node_modules/semver') | ||
t.strictSame(editorBin, 'code', 'used the correct editor') | ||
t.strictSame(editorArgs, ['-w', path], 'edited the correct directory, keeping flags') | ||
t.strictSame(editorOpts, { stdio: 'inherit' }, 'passed the correct opts') | ||
t.strictSame(rebuildArgs, [path], 'passed the correct path to rebuild') | ||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver') | ||
const [scriptShell] = makeSpawnArgs({ | ||
event: 'install', | ||
path: npm.prefix, | ||
}) | ||
spawk.spawn('testeditor', ['--flag', semverPath]) | ||
spawk.spawn( | ||
scriptShell, | ||
args => args.includes('testinstall'), | ||
{ cwd: semverPath } | ||
) | ||
await npm.exec('edit', ['semver']) | ||
}) | ||
|
||
t.test('npm edit no args', async t => { | ||
const { npm } = await loadMockNpm(t) | ||
await t.rejects( | ||
edit.exec([]), | ||
/npm edit/, | ||
npm.exec('edit', []), | ||
{ code: 'EUSAGE' }, | ||
'throws usage error' | ||
) | ||
}) | ||
|
||
t.test('npm edit lstat error propagates', async t => { | ||
const _lstat = gracefulFs.lstat | ||
gracefulFs.lstat = (dir, cb) => { | ||
return cb(new Error('lstat failed')) | ||
} | ||
t.teardown(() => { | ||
gracefulFs.lstat = _lstat | ||
}) | ||
t.test('npm edit nonexistent package', async t => { | ||
const { npm } = await loadMockNpm(t, npmConfig) | ||
|
||
await t.rejects( | ||
edit.exec(['semver']), | ||
/lstat failed/, | ||
'user received correct error' | ||
npm.exec('edit', ['abbrev']), | ||
/lstat/ | ||
) | ||
}) | ||
|
||
t.test('npm edit editor exit code error propagates', async t => { | ||
EDITOR_CODE = 137 | ||
t.teardown(() => { | ||
EDITOR_CODE = 0 | ||
}) | ||
t.test('scoped package', async t => { | ||
const { npm } = await loadMockNpm(t, npmConfig) | ||
const scopedPath = path.resolve(npm.prefix, 'node_modules', '@npmcli', 'scoped-package') | ||
spawk.spawn('testeditor', [scopedPath]) | ||
await npm.exec('edit', ['@npmcli/scoped-package']) | ||
}) | ||
|
||
await t.rejects( | ||
edit.exec(['semver']), | ||
/exited with code: 137/, | ||
'user received correct error' | ||
) | ||
t.test('subdependency', async t => { | ||
const { npm } = await loadMockNpm(t, npmConfig) | ||
const subdepPath = path.resolve(npm.prefix, 'node_modules', 'semver', 'node_modules', 'abbrev') | ||
spawk.spawn('testeditor', [subdepPath]) | ||
await npm.exec('edit', ['semver/abbrev']) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously spawk was calling clean after the teardown of some invididual tests. Is that the same thing as calling
spawk.done()
inafterEach
and thenspawk.unload()
once at the end of all the tests?