From 67ca715de76d04f8b909951a88e2b6270e203cc3 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Fri, 21 Apr 2017 13:21:17 +0200 Subject: [PATCH 1/7] add test for global bin command --- __tests__/commands/global.js | 13 +++++++++++++ src/cli/commands/global.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 624cc0a57c..182fbe2206 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -5,6 +5,7 @@ import {ConsoleReporter} from '../../src/reporters/index.js'; import {run as buildRun} from './_helpers.js'; import {run as global} from '../../src/cli/commands/global.js'; import * as fs from '../../src/util/fs.js'; +import mkdir from '../_temp.js'; const isCI = require('is-ci'); jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; @@ -34,6 +35,10 @@ function getTempGlobalFolder(): string { return path.join(os.tmpdir(), `yarn-global-${Math.random()}`); } +async function createTempGlobalFolder(): Promise { + return await mkdir('yarn-global'); +} + // this test has global folder side effects, run it only in CI if (isCI) { test.concurrent('add without flag', (): Promise => { @@ -62,3 +67,11 @@ test('add with PREFIX enviroment variable', (): Promise => { process.env.PREFIX = envPrefix; }); }); + +test.concurrent('bin', () => { + const tmpGlobalFolder = getTempGlobalFolder(); + return runGlobal(['bin'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', + (config, reporter, install, getStdout) => { + expect(getStdout()).toContain(path.join(tmpGlobalFolder, 'bin')); + }); +}); diff --git a/src/cli/commands/global.js b/src/cli/commands/global.js index 05d4e6e980..25365dd286 100644 --- a/src/cli/commands/global.js +++ b/src/cli/commands/global.js @@ -201,7 +201,7 @@ const {run, setFlags: _setFlags} = buildSubCommands('global', { flags: Object, args: Array, ) { - console.log(getBinFolder(config, flags)); + reporter.log(getBinFolder(config, flags)); }, async ls( From f10efb779a47b5127d9b3951e9df2fc0cce0223f Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Fri, 21 Apr 2017 18:18:19 +0200 Subject: [PATCH 2/7] add test for global add command --- __tests__/commands/_helpers.js | 2 +- __tests__/commands/global.js | 10 +++++++++- src/cli/index.js | 4 +--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index 1a1caacb50..4b0439b310 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -122,7 +122,7 @@ export async function run( const config = await Config.create({ binLinks: !!flags.binLinks, cwd, - globalFolder: path.join(cwd, '.yarn-global'), + globalFolder: flags.globalFolder || path.join(cwd, '.yarn-global'), cacheFolder: flags.cacheFolder || path.join(cwd, '.yarn-cache'), linkFolder: flags.linkFolder || path.join(cwd, '.yarn-link'), production: flags.production, diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 182fbe2206..e81138ce1f 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -68,10 +68,18 @@ test('add with PREFIX enviroment variable', (): Promise => { }); }); -test.concurrent('bin', () => { +test.concurrent('bin', (): Promise => { const tmpGlobalFolder = getTempGlobalFolder(); return runGlobal(['bin'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { expect(getStdout()).toContain(path.join(tmpGlobalFolder, 'bin')); }); }); + +test.concurrent('add', async (): Promise => { + const tmpGlobalFolder = await createTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + async (config) => { + expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(true); + }); +}); diff --git a/src/cli/index.js b/src/cli/index.js index d56fd91ffb..f5c5ce9484 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -51,7 +51,7 @@ commander.option('--no-lockfile', "don't read or generate a lockfile"); commander.option('--pure-lockfile', "don't generate a lockfile"); commander.option('--frozen-lockfile', "don't generate a lockfile and fail if an update is needed"); commander.option('--link-duplicates', 'create hardlinks to the repeated modules in node_modules'); -commander.option('--global-folder ', ''); +commander.option('--global-folder ', 'specify a custom folder to store global packages'); commander.option( '--modules-folder ', 'rather than installing modules into the node_modules folder relative to the cwd, output them here', @@ -299,7 +299,6 @@ function writeErrorReport(log) : ?string { return errorReportLoc; } -// config.init({ binLinks: commander.binLinks, modulesFolder: commander.modulesFolder, @@ -319,7 +318,6 @@ config.init({ nonInteractive: commander.nonInteractive, commandName: commandName === 'run' ? commander.args[0] : commandName, }).then(() => { - // option "no-progress" stored in yarn config const noProgressConfig = config.registries.yarn.getOption('no-progress'); From 75888359a5ab9afe1f192fc53a2d6a0baf4acdb9 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Fri, 21 Apr 2017 18:21:40 +0200 Subject: [PATCH 3/7] add test for global remove --- __tests__/commands/global.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index e81138ce1f..84933ca1d9 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -83,3 +83,14 @@ test.concurrent('add', async (): Promise => { expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(true); }); }); + +test.concurrent('remove', async (): Promise => { + const tmpGlobalFolder = await createTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + .then(() => { + return runGlobal(['remove', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + async (config) => { + expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(false); + }); + }); +}); From 6b61c852c021b3494455dba20b52273c1c04fcfe Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Sun, 23 Apr 2017 18:02:45 +0200 Subject: [PATCH 4/7] add test for global ls command and fix issue #3142 --- __tests__/commands/global.js | 11 +++++++++++ src/cli/commands/global.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 84933ca1d9..f558b486e2 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -94,3 +94,14 @@ test.concurrent('remove', async (): Promise => { }); }); }); + +test.concurrent('ls', async (): Promise => { + const tmpGlobalFolder = await createTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + .then(() => { + return runGlobal(['ls'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + (config, reporter, install, getStdout) => { + expect(getStdout()).toContain('react-native-cli'); + }); + }); +}); diff --git a/src/cli/commands/global.js b/src/cli/commands/global.js index 25365dd286..7697d239bb 100644 --- a/src/cli/commands/global.js +++ b/src/cli/commands/global.js @@ -214,7 +214,7 @@ const {run, setFlags: _setFlags} = buildSubCommands('global', { // install so we get hard file paths const lockfile = await Lockfile.fromDirectory(config.cwd); - const install = new Install({skipIntegrity: true}, config, new NoopReporter(), lockfile); + const install = new Install({skipIntegrityCheck: true}, config, new NoopReporter(), lockfile); const patterns = await install.init(); // dump global modules From cbc285068998be7d79a0d8d854b2954fff387106 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Sun, 23 Apr 2017 18:13:59 +0200 Subject: [PATCH 5/7] add test for global upgrade --- __tests__/commands/global.js | 12 ++++++++++++ .../-/react-native-cli-2.0.0.tgz.bin | Bin 0 -> 6602 bytes 2 files changed, 12 insertions(+) create mode 100644 __tests__/fixtures/request-cache/GET/registry.yarnpkg.com/react-native-cli/-/react-native-cli-2.0.0.tgz.bin diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index f558b486e2..7f54c00fd1 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -105,3 +105,15 @@ test.concurrent('ls', async (): Promise => { }); }); }); + +test.concurrent('upgrade', async (): Promise => { + const tmpGlobalFolder = await createTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli@2.0.0'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + .then(() => { + return runGlobal(['upgrade', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + (config, reporter, install, getStdout) => { + expect(getStdout()).toContain('react-native-cli'); + expect(getStdout()).not.toContain('react-native-cli@2.0.0'); + }); + }); +}); diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/react-native-cli/-/react-native-cli-2.0.0.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/react-native-cli/-/react-native-cli-2.0.0.tgz.bin new file mode 100644 index 0000000000000000000000000000000000000000..c2beaf817c9fe84b755ae4c02695c5030e4f5316 GIT binary patch literal 6602 zcmZuybySqy*QL8bq#01UhGFO$Kf?QX>x)0WyY5=|dG6U~pL6#9<7%3k8j6XFiUUAEAizL}lI#%_jgSMFc)JS&KoS5I z56`=ZxHLdqN)9L^2Nnlt=$TTIsiEA_2zRuIslUe^80z8SiiAPYNR+!63Wi3YMZD0S z2&mit;&c)2PH1O2fTS!?>fc*;1neKU9KZ#E@DPEzB7G2)WF~i+YABQo@{ZHq9_9%5 zM#2^0vIwXn0s)e6khx0+I^2CrN`WO1GLm4pjI=DwQ5-A_l9iH>1_9*(2tN;`C&Ein z5A|>RB6sbJh|BzU^T24T^ME6!nLCx_h`diNa8B@&HXV+QY!z z)t{0~7wUx;(L=$Jjz|Pt4xsLd6b1lg0gn){e-x1dfW+m1AUW}WNh!%5n?jxB0Nj!? zUp#LkV3Jiwu^17Se9qoy76;W|@Mfr*tcp{yUcNz&& zlKsDNJp|er1^1EzXgvPM6DZ6X@!t$`05_cjDjSEksNZo<0b;h^oIF0QN66)XfVF2Fr@5=$ZTz z|F@nTKu^o$e}6?Zk?1@2fAdX|ZV1o2!T-mfyE-`zCoBE~9~asUa*yBtZ0JEJ9FK!k*ph@OQZB^f0dXAB9>zYG75 zjkPbUhUXNFDoBmPD)kF~U;ARGJi=MeWFnjO^%yM@#g@%WEJ6A7YX=2L5uc=?iLXt_ z;DY)>++Xj>2_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dvDB;5{Ecwr6|V&EmS^ zS&2Dn&7o!rx7L{INeC-_q9VBoSN`VMZk%p~Z+x{bmkmYb-(l)KSta+%=asST#?%leA5x3grj~?u7e>{UnQsQ= z8f~fADJA^hM~4TK&w~c#-2#!(cwFut5o=}34ZT*Ts^WyT14A7O4?Qb?lnT07-6*31 Y&J|v8C{gGCI=Dcor8AV`Sm5CN7uQNP!2kdN literal 0 HcmV?d00001 From 5f2954b1426d99a0057f6d92b2969718132c009c Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Sun, 23 Apr 2017 18:34:00 +0200 Subject: [PATCH 6/7] move tests with side-effects under isCI branch; the other tests now are side-effects free --- __tests__/commands/_helpers.js | 1 + __tests__/commands/global.js | 63 ++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index 4b0439b310..cb52648172 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -125,6 +125,7 @@ export async function run( globalFolder: flags.globalFolder || path.join(cwd, '.yarn-global'), cacheFolder: flags.cacheFolder || path.join(cwd, '.yarn-cache'), linkFolder: flags.linkFolder || path.join(cwd, '.yarn-link'), + prefix: flags.prefix, production: flags.production, }, reporter); diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 7f54c00fd1..5e22d1cb59 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -39,7 +39,12 @@ async function createTempGlobalFolder(): Promise { return await mkdir('yarn-global'); } -// this test has global folder side effects, run it only in CI +async function createTempPrefixFolder(): Promise { + const prefixFolder = await mkdir('yarn-prefix'); + return path.join(prefixFolder, 'bin'); +} + +// these tests have global folder side or prefix folder effects, run it only in CI if (isCI) { test.concurrent('add without flag', (): Promise => { return runGlobal(['add', 'react-native-cli'], {}, 'add-without-flag', async (config) => { @@ -47,26 +52,26 @@ if (isCI) { expect(await fs.exists(path.join(config.globalFolder, 'node_modules', '.bin', 'react-native'))).toEqual(true); }); }); -} -test.concurrent('add with prefix flag', (): Promise => { - const tmpGlobalFolder = getTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', async (config) => { - expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + test.concurrent('add with prefix flag', (): Promise => { + const tmpGlobalFolder = getTempGlobalFolder(); + return runGlobal(['add', 'react-native-cli'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', async (config) => { + expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + }); }); -}); -// don't run this test in `concurrent`, it will affect other tests -test('add with PREFIX enviroment variable', (): Promise => { - const tmpGlobalFolder = getTempGlobalFolder(); - const envPrefix = process.env.PREFIX; - process.env.PREFIX = tmpGlobalFolder; - return runGlobal(['add', 'react-native-cli'], {}, 'add-with-prefix-env', async (config) => { - expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); - // restore env - process.env.PREFIX = envPrefix; + // don't run this test in `concurrent`, it will affect other tests + test('add with PREFIX enviroment variable', (): Promise => { + const tmpGlobalFolder = getTempGlobalFolder(); + const envPrefix = process.env.PREFIX; + process.env.PREFIX = tmpGlobalFolder; + return runGlobal(['add', 'react-native-cli'], {}, 'add-with-prefix-env', async (config) => { + expect(await fs.exists(getGlobalPath(tmpGlobalFolder, 'react-native'))).toEqual(true); + // restore env + process.env.PREFIX = envPrefix; + }); }); -}); +} test.concurrent('bin', (): Promise => { const tmpGlobalFolder = getTempGlobalFolder(); @@ -78,7 +83,9 @@ test.concurrent('bin', (): Promise => { test.concurrent('add', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', async (config) => { expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(true); }); @@ -86,10 +93,11 @@ test.concurrent('add', async (): Promise => { test.concurrent('remove', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['remove', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', - async (config) => { + return runGlobal(['remove', 'react-native-cli'], flags, 'add-with-prefix-flag', async (config) => { expect(await fs.exists(path.join(tmpGlobalFolder, 'node_modules', 'react-native-cli'))).toEqual(false); }); }); @@ -97,10 +105,11 @@ test.concurrent('remove', async (): Promise => { test.concurrent('ls', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['ls'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', - (config, reporter, install, getStdout) => { + return runGlobal(['ls'], flags, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { expect(getStdout()).toContain('react-native-cli'); }); }); @@ -108,9 +117,11 @@ test.concurrent('ls', async (): Promise => { test.concurrent('upgrade', async (): Promise => { const tmpGlobalFolder = await createTempGlobalFolder(); - return runGlobal(['add', 'react-native-cli@2.0.0'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', () => {}) + const tmpPrefixFolder = await createTempPrefixFolder(); + const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder}; + return runGlobal(['add', 'react-native-cli@2.0.0'], flags, 'add-with-prefix-flag', () => {}) .then(() => { - return runGlobal(['upgrade', 'react-native-cli'], {globalFolder: tmpGlobalFolder}, 'add-with-prefix-flag', + return runGlobal(['upgrade', 'react-native-cli'], flags, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { expect(getStdout()).toContain('react-native-cli'); expect(getStdout()).not.toContain('react-native-cli@2.0.0'); From e66c5935045f20d0add6aa342be9e2e1678f6376 Mon Sep 17 00:00:00 2001 From: Simon Vocella Date: Tue, 2 May 2017 08:48:41 +0200 Subject: [PATCH 7/7] the global folder in win32 platform is prefix env/parameter without bin folder inside, do assert only on global folders for yarn global v0.23.3 Done in 0.26s. --- __tests__/commands/global.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index 5e22d1cb59..669f867896 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -77,7 +77,7 @@ test.concurrent('bin', (): Promise => { const tmpGlobalFolder = getTempGlobalFolder(); return runGlobal(['bin'], {prefix: tmpGlobalFolder}, 'add-with-prefix-flag', (config, reporter, install, getStdout) => { - expect(getStdout()).toContain(path.join(tmpGlobalFolder, 'bin')); + expect(getStdout()).toContain(tmpGlobalFolder); }); });