diff --git a/__tests__/cli/index.js b/__tests__/cli/index.js new file mode 100644 index 0000000000..f6598af245 --- /dev/null +++ b/__tests__/cli/index.js @@ -0,0 +1,41 @@ +/* @flow */ +const path = require('path'); +const exec = require('child_process').exec; +import * as fs from '../../src/util/fs.js'; +import makeTemp from '../_temp.js'; +import NoopReporter from '../../src/reporters/base-reporter.js'; +import * as constants from '../../src/constants.js'; +import assert from 'assert'; + +const yarnBin = path.join(__dirname, '..', '..', 'bin', 'yarn.js'); +const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'index'); + +async function setupWorkingDir(fixture: string): Promise { + const srcDir = path.join(fixturesLoc, fixture); + const workingDir = await makeTemp(fixture); + await fs.copy(srcDir, workingDir, new NoopReporter()); + + return workingDir; +} + +function execCommand(workingDir: string, cacheDir: string): Promise { + return new Promise((resolve, reject) => { + exec(`node "${yarnBin}" tag rm non-existing-pkg non-existing-tag --cache-folder ${cacheDir} | cat`, + {cwd: workingDir}, (err, stdout) => { + if (err) { + reject(err); + } else { + resolve(workingDir); + } + }); + }); +} + +test('Verify path errorReport log', async () => { + const workingDir = await setupWorkingDir('run-failing-custom-script'); + const cacheDir = path.join(workingDir, 'cache'); + await fs.mkdirp(cacheDir); + + await execCommand(workingDir, cacheDir); + assert.ok(await fs.exists(path.join(cacheDir, 'v' + String(constants.CACHE_VERSION), 'yarn-error.log'))); +}); diff --git a/__tests__/fixtures/index/run-failing-custom-script/package.json b/__tests__/fixtures/index/run-failing-custom-script/package.json new file mode 100644 index 0000000000..a5f2492607 --- /dev/null +++ b/__tests__/fixtures/index/run-failing-custom-script/package.json @@ -0,0 +1,11 @@ +{ + "name": "test_run_failing_custom_script", + "version": "1.0.0", + "license": "UNLICENSED", + "scripts": { + "custom-script": "tag rm non-existing-pkg non-existing-tag" + }, + "dependencies": { + "n": "^2.1.4" + } +} diff --git a/src/cli/index.js b/src/cli/index.js index f237a7afc8..e7d610e3e4 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -345,7 +345,7 @@ function onUnexpectedError(err: Error) { } function writeErrorReport(log) : ?string { - const errorReportLoc = path.join(config.cwd, 'yarn-error.log'); + const errorReportLoc = path.join(config.cacheFolder, 'yarn-error.log'); try { fs.writeFileSync(errorReportLoc, log.join('\n\n') + '\n'); @@ -362,7 +362,7 @@ config.init({ binLinks: commander.binLinks, modulesFolder: commander.modulesFolder, globalFolder: commander.globalFolder, - cacheRootFolder: commander.cacheFolder, + cacheFolder: commander.cacheFolder, preferOffline: commander.preferOffline, captureHar: commander.har, ignorePlatform: commander.ignorePlatform,