From b0144cc4bc0365a3c80a677bd95a5c21e19f106c Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 17 Jan 2024 15:20:14 +0000 Subject: [PATCH] fix: make --no-wrap work as advertised. Fix and test handling of wrap option to w3 up. | flag | result | |--------------|-------------| | undefined | wrap: true | | --wrap | wrap: true | | --wrap true | wrap: true | | --wrap=true | wrap: true | | --wrap false | wrap: false | | --wrap=false | wrap: false | | --no-wrap | wrap: false | License: MIT Signed-off-by: Oli Evans --- bin.js | 2 +- test/bin.spec.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/bin.js b/bin.js index fca4116..4552fd2 100755 --- a/bin.js +++ b/bin.js @@ -71,9 +71,9 @@ cli .command('up ') .alias('upload', 'put') .describe('Store a file(s) to the service and register an upload.') - .option('--no-wrap', "Don't wrap input files with a directory.", false) .option('-H, --hidden', 'Include paths that start with ".".') .option('-c, --car', 'File is a CAR file.', false) + .option('--wrap', "Wrap single input file in a directory. Has no effect on directory or CAR uploads. Pass --no-wrap to disable.", true) .option('--json', 'Format as newline delimited JSON') .option('--verbose', 'Output more details.') .option( diff --git a/test/bin.spec.js b/test/bin.spec.js index 9479109..28b10ec 100644 --- a/test/bin.spec.js +++ b/test/bin.spec.js @@ -620,6 +620,70 @@ export const testW3Up = { assert.match(up.error, /Stored 1 file/) }), + 'w3 up --no-wrap': test(async (assert, context) => { + const email = 'alice@web.mail' + await login(context, { email }) + await selectPlan(context, { email }) + + const create = await w3 + .args([ + 'space', + 'create', + 'home', + '--no-recovery', + '--no-account', + '--customer', + email, + ]) + .env(context.env.alice) + .join() + + assert.ok(create.status.success()) + + const up = await w3 + .args(['up', 'test/fixtures/pinpie.jpg', '--no-wrap']) + .env(context.env.alice) + .join() + + assert.match( + up.output, + /bafkreiajkbmpugz75eg2tmocmp3e33sg5kuyq2amzngslahgn6ltmqxxfa/ + ) + assert.match(up.error, /Stored 1 file/) + }), + + 'only w3 up --wrap false': test(async (assert, context) => { + const email = 'alice@web.mail' + await login(context, { email }) + await selectPlan(context, { email }) + + const create = await w3 + .args([ + 'space', + 'create', + 'home', + '--no-recovery', + '--no-account', + '--customer', + email, + ]) + .env(context.env.alice) + .join() + + assert.ok(create.status.success()) + + const up = await w3 + .args(['up', 'test/fixtures/pinpie.jpg', '--no-wrap']) + .env(context.env.alice) + .join() + + assert.match( + up.output, + /bafkreiajkbmpugz75eg2tmocmp3e33sg5kuyq2amzngslahgn6ltmqxxfa/ + ) + assert.match(up.error, /Stored 1 file/) + }), + 'w3 up --car': test(async (assert, context) => { const email = 'alice@web.mail' await login(context, { email })