From 6f8f5fe6880d1b82c00dc4e2b9fbf647d0bd45d1 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 25 May 2019 11:22:59 +0300 Subject: [PATCH 1/2] [cli] output relative destination paths Currently wide output looks bad on half of the screen I use for terminal ``` src/svgs/visibility.svg -> /Users/_________________________________________/src/icons/Visibility.js ``` In this diff I suggest simply cut useless path and get this ``` src/svgs/visibility.svg -> src/icons/Visibility.js ``` --- .../cli/src/__snapshots__/index.test.js.snap | 16 ++++++++++++++++ packages/cli/src/dirCommand.js | 2 +- packages/cli/src/index.test.js | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap index d6f2ee71..01c08167 100644 --- a/packages/cli/src/__snapshots__/index.test.js.snap +++ b/packages/cli/src/__snapshots__/index.test.js.snap @@ -330,6 +330,22 @@ export default SvgFile " `; +exports[`cli should transform a whole directory and output relative destination paths 1`] = ` +"__fixtures__/cased/PascalCase.svg -> __fixtures_build__/whole/cased/PascalCase.js +__fixtures__/cased/kebab-case.svg -> __fixtures_build__/whole/cased/KebabCase.js +__fixtures__/cased/camelCase.svg -> __fixtures_build__/whole/cased/CamelCase.js +__fixtures__/cased/multiple---dashes.svg -> __fixtures_build__/whole/cased/MultipleDashes.js +__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/File.js +__fixtures__/complex/skype.svg -> __fixtures_build__/whole/complex/Skype.js +__fixtures__/complex/telegram.svg -> __fixtures_build__/whole/complex/Telegram.js +__fixtures__/withPrettierRc/file.svg -> __fixtures_build__/whole/withPrettierRc/File.js +__fixtures__/withSvgrRc/file.svg -> __fixtures_build__/whole/withSvgrRc/File.js +__fixtures__/withSvgoYml/file.svg -> __fixtures_build__/whole/withSvgoYml/File.js +__fixtures__/nesting/one.svg -> __fixtures_build__/whole/nesting/One.js +__fixtures__/nesting/a/two.svg -> __fixtures_build__/whole/nesting/a/Two.js +" +`; + exports[`cli should work with a simple file 1`] = ` "import React from 'react' diff --git a/packages/cli/src/dirCommand.js b/packages/cli/src/dirCommand.js index cdcd83b5..d9298419 100644 --- a/packages/cli/src/dirCommand.js +++ b/packages/cli/src/dirCommand.js @@ -32,7 +32,7 @@ async function dirCommand( const dest = path.resolve(program.outDir, relative) const code = await convertFile(src, options) outputFileSync(dest, code) - process.stdout.write(`${src} -> ${dest}\n`) + process.stdout.write(`${src} -> ${path.relative(process.cwd(), dest)}\n`) return true } diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js index 263f38b8..54d207ba 100644 --- a/packages/cli/src/index.test.js +++ b/packages/cli/src/index.test.js @@ -48,8 +48,9 @@ describe('cli', () => { expect(result).toMatchSnapshot() }, 10000) - it('should transform a whole directory', async () => { - await cli('--out-dir __fixtures_build__/whole __fixtures__') + it('should transform a whole directory and output relative destination paths', async () => { + const result = await cli('--out-dir __fixtures_build__/whole __fixtures__') + expect(result).toMatchSnapshot() }, 10000) it('should support --prettier-config as json', async () => { From 990ae133f43f47d02b4b0eff5918a2d2b1dc99e2 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sat, 25 May 2019 11:41:32 +0300 Subject: [PATCH 2/2] Sort output for stable test --- packages/cli/src/__snapshots__/index.test.js.snap | 14 +++++++------- packages/cli/src/index.test.js | 6 +++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/__snapshots__/index.test.js.snap b/packages/cli/src/__snapshots__/index.test.js.snap index 01c08167..c7aeeeaa 100644 --- a/packages/cli/src/__snapshots__/index.test.js.snap +++ b/packages/cli/src/__snapshots__/index.test.js.snap @@ -331,19 +331,19 @@ export default SvgFile `; exports[`cli should transform a whole directory and output relative destination paths 1`] = ` -"__fixtures__/cased/PascalCase.svg -> __fixtures_build__/whole/cased/PascalCase.js -__fixtures__/cased/kebab-case.svg -> __fixtures_build__/whole/cased/KebabCase.js +" +__fixtures__/cased/PascalCase.svg -> __fixtures_build__/whole/cased/PascalCase.js __fixtures__/cased/camelCase.svg -> __fixtures_build__/whole/cased/CamelCase.js +__fixtures__/cased/kebab-case.svg -> __fixtures_build__/whole/cased/KebabCase.js __fixtures__/cased/multiple---dashes.svg -> __fixtures_build__/whole/cased/MultipleDashes.js -__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/File.js __fixtures__/complex/skype.svg -> __fixtures_build__/whole/complex/Skype.js __fixtures__/complex/telegram.svg -> __fixtures_build__/whole/complex/Telegram.js +__fixtures__/nesting/a/two.svg -> __fixtures_build__/whole/nesting/a/Two.js +__fixtures__/nesting/one.svg -> __fixtures_build__/whole/nesting/One.js +__fixtures__/simple/file.svg -> __fixtures_build__/whole/simple/File.js __fixtures__/withPrettierRc/file.svg -> __fixtures_build__/whole/withPrettierRc/File.js -__fixtures__/withSvgrRc/file.svg -> __fixtures_build__/whole/withSvgrRc/File.js __fixtures__/withSvgoYml/file.svg -> __fixtures_build__/whole/withSvgoYml/File.js -__fixtures__/nesting/one.svg -> __fixtures_build__/whole/nesting/One.js -__fixtures__/nesting/a/two.svg -> __fixtures_build__/whole/nesting/a/Two.js -" +__fixtures__/withSvgrRc/file.svg -> __fixtures_build__/whole/withSvgrRc/File.js" `; exports[`cli should work with a simple file 1`] = ` diff --git a/packages/cli/src/index.test.js b/packages/cli/src/index.test.js index 54d207ba..d17808ba 100644 --- a/packages/cli/src/index.test.js +++ b/packages/cli/src/index.test.js @@ -50,7 +50,11 @@ describe('cli', () => { it('should transform a whole directory and output relative destination paths', async () => { const result = await cli('--out-dir __fixtures_build__/whole __fixtures__') - expect(result).toMatchSnapshot() + const sorted = result + .split(/\n/) + .sort() + .join('\n') + expect(sorted).toMatchSnapshot() }, 10000) it('should support --prettier-config as json', async () => {