Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Aug 17, 2017
1 parent eec7201 commit 1a0791b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
28 changes: 10 additions & 18 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,30 @@ test('cache folder fallback', async () => {
const cwd = await makeTemp();
const cacheFolder = path.join(cwd, '.cache');

await fs.mkdirp(cacheFolder);

const command = path.resolve(__dirname, '../bin/yarn');
const args = ['--preferred-cache-folder', cacheFolder];

const options = {cwd};

{
function runCacheDir(): Promise<Array<Buffer>> {
const {stderr, stdout} = execa(command, ['cache', 'dir'].concat(args), options);

const stdoutPromise = misc.consumeStream(stdout);
const stderrPromise = misc.consumeStream(stderr);

const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);

expect(stdoutOutput.toString().trim()).toEqual(path.join(cacheFolder, `v${constants.CACHE_VERSION}`));
expect(stderrOutput.toString()).not.toMatch(/Skipping preferred cache folder/);
return Promise.all([stdoutPromise, stderrPromise]);
}

await fs.chmod(cacheFolder, 0o000);
const [stdoutOutput, stderrOutput] = await runCacheDir();

{
const {stderr, stdout} = execa(command, ['cache', 'dir'].concat(args), options);
expect(stdoutOutput.toString().trim()).toEqual(path.join(cacheFolder, `v${constants.CACHE_VERSION}`));
expect(stderrOutput.toString()).not.toMatch(/Skipping preferred cache folder/);

const stdoutPromise = misc.consumeStream(stdout);
const stderrPromise = misc.consumeStream(stderr);
await fs.unlink(cacheFolder);
await fs.writeFile(cacheFolder, `not a directory`);

const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
const [stdoutOutput2, stderrOutput2] = await runCacheDir();

expect(stdoutOutput.toString().trim()).toEqual(
path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`),
);
expect(stderrOutput.toString()).toMatch(/Skipping preferred cache folder/);
}
expect(stdoutOutput2.toString().trim()).toEqual(path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`));
expect(stderrOutput2.toString()).toMatch(/Skipping preferred cache folder/);
});
12 changes: 10 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,18 @@ export default class Config {
const tentativeCacheFolder = String(preferredCacheFolders[t]);

try {

await fs.mkdirp(tentativeCacheFolder);
// eslint-disable-next-line
await fs.access(tentativeCacheFolder, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK);

const testFile = path.join(tentativeCacheFolder, 'testfile');

// fs.access is not enough, because the cache folder could actually be a file.
await fs.writeFile(testFile, 'content');
await fs.readFile(testFile);
await fs.unlink(testFile);

cacheRootFolder = tentativeCacheFolder;

} catch (error) {
this.reporter.warn(this.reporter.lang('cacheFolderSkipped', tentativeCacheFolder));
}
Expand Down
1 change: 1 addition & 0 deletions src/reporters/base-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default class BaseReporter {
success(message: string) {}

// a simple log message
// TODO: rethink the {force} parameter. In the meantime, please don't use it (cf comments in #4143).
log(message: string, {force = false}: {force?: boolean} = {}) {}

// a shell command has been executed
Expand Down

0 comments on commit 1a0791b

Please sign in to comment.