-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pack, publish): default foreground-scripts to true
Fixes #6816
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 deletions.
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 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 |
---|---|---|
|
@@ -26,6 +26,27 @@ Array [ | |
] | ||
` | ||
|
||
exports[`test/lib/commands/pack.js TAP foreground-scripts defaults to true > logs pack contents 1`] = ` | ||
Array [ | ||
undefined, | ||
"package: [email protected]", | ||
undefined, | ||
"110B package.json", | ||
undefined, | ||
String( | ||
name: test-fg-scripts | ||
version: 0.0.0 | ||
filename: test-fg-scripts-0.0.0.tgz | ||
package size: {size} | ||
unpacked size: 110 B | ||
shasum: {sha} | ||
integrity: {integrity} | ||
total files: 1 | ||
), | ||
"", | ||
] | ||
` | ||
|
||
exports[`test/lib/commands/pack.js TAP should log output as valid json > logs pack contents 1`] = ` | ||
Array [] | ||
` | ||
|
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 |
---|---|---|
|
@@ -56,6 +56,49 @@ Array [ | |
] | ||
` | ||
|
||
exports[`test/lib/commands/publish.js TAP foreground-scripts defaults to true > must match snapshot 1`] = ` | ||
Array [ | ||
Array [ | ||
"", | ||
], | ||
Array [ | ||
"", | ||
"package: [email protected]", | ||
], | ||
Array [ | ||
"=== Tarball Contents ===", | ||
], | ||
Array [ | ||
"", | ||
"110B package.json", | ||
], | ||
Array [ | ||
"=== Tarball Details ===", | ||
], | ||
Array [ | ||
"", | ||
String( | ||
name: test-fg-scripts | ||
version: 0.0.0 | ||
filename: test-fg-scripts-0.0.0.tgz | ||
package size: {size} | ||
unpacked size: 110 B | ||
shasum: {sha} | ||
integrity: {integrity} | ||
total files: 1 | ||
), | ||
], | ||
Array [ | ||
"", | ||
"", | ||
], | ||
Array [ | ||
"", | ||
"Publishing to https://registry.npmjs.org/ with tag latest and default access (dry-run)", | ||
], | ||
] | ||
` | ||
|
||
exports[`test/lib/commands/publish.js TAP has mTLS auth for scope configured registry > new package version 1`] = ` | ||
+ @npm/[email protected] | ||
` | ||
|
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 |
---|---|---|
|
@@ -105,6 +105,48 @@ t.test('dry run', async t => { | |
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename))) | ||
}) | ||
|
||
t.test('foreground-scripts defaults to true', async t => { | ||
const { npm, outputs, logs } = await loadMockNpm(t, { | ||
prefixDir: { | ||
'package.json': JSON.stringify({ | ||
name: 'test-fg-scripts', | ||
version: '0.0.0', | ||
scripts: { | ||
prepack: 'echo prepack!', | ||
postpack: 'echo postpack!', | ||
}, | ||
} | ||
), | ||
}, | ||
config: { 'dry-run': true }, | ||
}) | ||
|
||
/* eslint no-console: 0 */ | ||
// TODO: replace this with `const results = t.intercept(console, 'log')` | ||
const log = console.log | ||
t.teardown(() => { | ||
console.log = log | ||
}) | ||
const caughtLogs = [] | ||
console.log = (...args) => { | ||
caughtLogs.push(args) | ||
} | ||
// end TODO | ||
|
||
await npm.exec('pack', []) | ||
const filename = 'test-fg-scripts-0.0.0.tgz' | ||
t.same( | ||
caughtLogs, | ||
[ | ||
['\n> [email protected] prepack\n> echo prepack!\n'], | ||
['\n> [email protected] postpack\n> echo postpack!\n'], | ||
], | ||
'prepack and postpack log to stdout') | ||
t.strictSame(outputs, [[filename]]) | ||
t.matchSnapshot(logs.notice.map(([, m]) => m), 'logs pack contents') | ||
t.throws(() => fs.statSync(path.resolve(npm.prefix, filename))) | ||
}) | ||
|
||
t.test('invalid packument', async t => { | ||
const { npm, outputs } = await loadMockNpm(t, { | ||
prefixDir: { | ||
|
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 |
---|---|---|
|
@@ -167,6 +167,50 @@ t.test('dry-run', async t => { | |
t.matchSnapshot(logs.notice) | ||
}) | ||
|
||
t.test('foreground-scripts defaults to true', async t => { | ||
const { joinedOutput, npm, logs } = await loadMockNpm(t, { | ||
config: { | ||
'dry-run': true, | ||
...auth, | ||
}, | ||
prefixDir: { | ||
'package.json': JSON.stringify({ | ||
name: 'test-fg-scripts', | ||
version: '0.0.0', | ||
scripts: { | ||
prepack: 'echo prepack!', | ||
postpack: 'echo postpack!', | ||
}, | ||
} | ||
), | ||
}, | ||
}) | ||
|
||
/* eslint no-console: 0 */ | ||
// TODO: replace this with `const results = t.intercept(console, 'log')` | ||
const log = console.log | ||
t.teardown(() => { | ||
console.log = log | ||
}) | ||
const caughtLogs = [] | ||
console.log = (...args) => { | ||
caughtLogs.push(args) | ||
} | ||
// end TODO | ||
|
||
await npm.exec('publish', []) | ||
t.equal(joinedOutput(), `+ [email protected]`) | ||
t.matchSnapshot(logs.notice) | ||
|
||
t.same( | ||
caughtLogs, | ||
[ | ||
['\n> [email protected] prepack\n> echo prepack!\n'], | ||
['\n> [email protected] postpack\n> echo postpack!\n'], | ||
], | ||
'prepack and postpack log to stdout') | ||
}) | ||
|
||
t.test('shows usage with wrong set of arguments', async t => { | ||
const { publish } = await loadMockNpm(t, { command: 'publish' }) | ||
await t.rejects(publish.exec(['a', 'b', 'c']), publish.usage) | ||
|
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