Skip to content

Commit 8770d5c

Browse files
author
Maël Nison
committed
wip
1 parent 93fc256 commit 8770d5c

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

__tests__/integration.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,38 @@ test('--mutex network', async () => {
7575

7676
test('cache folder fallback', async () => {
7777
const cwd = await makeTemp();
78-
const cacheFolder = path.join(cwd, '.cache');
79-
80-
await fs.mkdirp(cacheFolder);
78+
const cacheFolder = path.join(
79+
process.platform !== 'win32' ? cwd : `${process.env.SYSTEMDRIVE}/Windows/System32/etc/drivers/clowntown`,
80+
'.cache',
81+
);
8182

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

8586
const options = {cwd};
8687

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

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

93-
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
94-
95-
expect(stdoutOutput.toString().trim()).toEqual(path.join(cacheFolder, `v${constants.CACHE_VERSION}`));
96-
expect(stderrOutput.toString()).not.toMatch(/Skipping preferred cache folder/);
94+
return Promise.all([stdoutPromise, stderrPromise]);
9795
}
9896

99-
await fs.chmod(cacheFolder, 0o000);
97+
const [stdoutOutput, stderrOutput] = await runCacheDir();
10098

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

104-
const stdoutPromise = misc.consumeStream(stdout);
105-
const stderrPromise = misc.consumeStream(stderr);
102+
// Note that this shouldn't have any effect on Windows, hence why we try to use the System32 directory instead
103+
// Since System32 is a system file, it shouldn't be writable by the current user, and should Yarn should fallback
104+
await fs.chmod(cacheFolder, 0o000);
106105

107-
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
106+
const [stdoutOutput2, stderrOutput2] = await runCacheDir();
108107

109-
expect(stdoutOutput.toString().trim()).toEqual(
110-
path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`),
111-
);
112-
expect(stderrOutput.toString()).toMatch(/Skipping preferred cache folder/);
113-
}
108+
expect(stdoutOutput2.toString().trim()).toEqual(
109+
path.join(constants.PREFERRED_MODULE_CACHE_DIRECTORIES[0], `v${constants.CACHE_VERSION}`),
110+
);
111+
expect(stderrOutput2.toString()).toMatch(/Skipping preferred cache folder/);
114112
});

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ export default class Config {
294294
await fs.mkdirp(tentativeCacheFolder);
295295
// eslint-disable-next-line
296296
await fs.access(tentativeCacheFolder, fs.constants.R_OK | fs.constants.W_OK | fs.constants.X_OK);
297+
await fs.writeFile(path.join(tentativeCacheFolder, 'testfile'), 'content');
298+
await fs.readFile(path.join(tentativeCacheFolder, 'testfile'));
297299
cacheRootFolder = tentativeCacheFolder;
298300
} catch (error) {
299301
this.reporter.warn(this.reporter.lang('cacheFolderSkipped', tentativeCacheFolder));

src/reporters/base-reporter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export default class BaseReporter {
195195
success(message: string) {}
196196

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

200201
// a shell command has been executed

0 commit comments

Comments
 (0)