Skip to content

Commit

Permalink
Tweak for e2e tests 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Apr 4, 2024
1 parent e66a622 commit 343437d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const yargsParser = Yargs.scriptName('bundle-phobia')
.example('$0 lodash chalk', 'Get stats for a list of packages')
.example('$0 install lodash chalk', 'Conditionaly install packages')
.command(
'install',
'install <packages..>',
'Perform install if specified size constraints are met',
yargs => yargs.options(INSTALL_OPTIONS),
argv =>
Expand Down
7 changes: 4 additions & 3 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {

const DEFAULT_MAX_SIZE = '100kB';
const BUNLE_PHOBIA_ARGS = [
'packages',
'i',
'interactive',
'$0',
Expand Down Expand Up @@ -47,7 +48,7 @@ const npmOptionsFromArgv = argv => {

const installCommandArgs = argv => {
const options = npmOptionsFromArgv(argv);
return ['install', ...argv._, ...options];
return ['install', ...argv.packages, ...options];
};

const getSizePredicate = (argv, defaultSize, packageConfig) => {
Expand Down Expand Up @@ -108,8 +109,8 @@ const main = async ({
}
};
const currentPkg = readPkg();
const packages = argv._;
if (_.isEmpty(packages)) throw new Error('No packages to install was given');
const {packages} = argv;
if (_.isEmpty(argv.packages)) throw new Error('No packages to install was given');
const pluralSuffix = _.size(packages) > 1 ? 's' : '';

const performInstall = () =>
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/install-safetynet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ fi

node_major=$(node <<< "console.log(process.versions.node.split('.')[0])")
case $node_major in
8|10|12|14) expected_add_message="added [1-2] packages? from [1-9] contributors? and audited [1-6] packages? in";;
16|18|20) expected_add_message="added [1-2] packages?, and audited [1-6] packages?";;
16|18|20) expected_add_message="added [1-3] packages?, and audited [1-6] packages?";;
*) expected_add_message="><"; echo "No expected message for this major version";;
esac

Expand Down
14 changes: 7 additions & 7 deletions test/integration/install.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('install just a single package and fail', async t => {
const spawn = fakeSpawn();
try {
await main({
argv: {_: ['lodash@4.12.0']},
argv: {packages: ['lodash@4.12.0']},
stream,
spawn,
defaultMaxSize,
Expand All @@ -36,7 +36,7 @@ test('install just a single package and succeed', async t => {
const spawn = fakeSpawn();
//
await main({
argv: {_: ['bytes@3.0.0']},
argv: {packages: ['bytes@3.0.0']},
stream,
spawn,
defaultMaxSize,
Expand All @@ -59,7 +59,7 @@ test('install just a single package and just warn', async t => {
const stream = fakeStream();
const spawn = fakeSpawn();
await main({
argv: {_: ['lodash@4.12.0'], w: true, warn: true, 'save-dev': true},
argv: {packages: ['lodash@4.12.0'], w: true, warn: true, 'save-dev': true},
stream,
spawn,
defaultMaxSize,
Expand All @@ -84,7 +84,7 @@ test('ask to install a package and accept', async t => {
const spawn = fakeSpawn();
const prompt = fakePrompt();
await main({
argv: {_: ['lodash@4.12.0'], i: true, interactive: true},
argv: {packages: ['lodash@4.12.0'], i: true, interactive: true},
stream,
spawn,
prompt,
Expand All @@ -109,7 +109,7 @@ test('ask to install a package and deny', async t => {
const spawn = fakeSpawn();
const prompt = fakePrompt(false);
await main({
argv: {_: ['lodash@4.12.0'], i: true, interactive: true},
argv: {packages: ['lodash@4.12.0'], i: true, interactive: true},
stream,
spawn,
prompt,
Expand All @@ -135,7 +135,7 @@ test('try to install package that does not exist', async t => {
const spawn = fakeSpawn();
try {
await main({
argv: {_: ['no-sorry-but-i-do-not-exist']},
argv: {packages: ['no-sorry-but-i-do-not-exist']},
stream,
spawn,
defaultMaxSize,
Expand All @@ -156,7 +156,7 @@ test('install just a single package on empty package with global config and succ
const spawn = fakeSpawn();

await main({
argv: {_: ['bytes@3.0.0']},
argv: {packages: ['bytes@3.0.0']},
stream,
spawn,
defaultMaxSize,
Expand Down

0 comments on commit 343437d

Please sign in to comment.