-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate read and write operations on lastKnownGood.json
Also skip overwriting lastKnownGood.json with same content. Signed-off-by: Jakob Ackermann <[email protected]>
- Loading branch information
Showing
4 changed files
with
160 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import config from '../config.json'; | |
import * as folderUtils from '../sources/folderUtils'; | ||
import {SupportedPackageManagerSet} from '../sources/types'; | ||
|
||
import {runCli} from './_runCli'; | ||
import {runCli, spawnCmd} from './_runCli'; | ||
|
||
|
||
beforeEach(async () => { | ||
|
@@ -475,6 +475,96 @@ it(`should support disabling the network accesses from the environment`, async ( | |
}); | ||
}); | ||
|
||
describe(`read-only and offline environment`, () => { | ||
it(`should support running in project scope`, async () => { | ||
await xfs.mktempPromise(async cwd => { | ||
// Reset to default | ||
delete process.env.COREPACK_DEFAULT_TO_LATEST; | ||
|
||
// Prepare fake project | ||
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), { | ||
packageManager: `[email protected]`, | ||
}); | ||
|
||
// $ corepack install | ||
await expect(runCli(cwd, [`install`])).resolves.toMatchObject({ | ||
stdout: `Adding [email protected] to the cache...\n`, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
|
||
// Let corepack discover the latest yarn version. | ||
// BUG: This should not be necessary with a fully specified version in package.json plus populated corepack cache. | ||
// Engine.executePackageManagerRequest needs to defer the fallback work. This requires a big refactoring. | ||
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
exitCode: 0, | ||
}); | ||
|
||
// Make COREPACK_HOME ro | ||
const home = npath.toPortablePath(folderUtils.getCorepackHomeFolder()); | ||
await xfs.chmodPromise(ppath.join(home, `lastKnownGood.json`), 0o444); | ||
await xfs.chmodPromise(home, 0o555); | ||
|
||
// Use fake proxies to simulate offline mode | ||
process.env.HTTP_PROXY = `0.0.0.0`; | ||
process.env.HTTPS_PROXY = `0.0.0.0`; | ||
|
||
// $ corepack yarn --version | ||
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
stdout: `2.2.2\n`, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
}); | ||
}); | ||
|
||
it(`should support running globally`, async () => { | ||
await xfs.mktempPromise(async installDir => { | ||
// Reset to default | ||
delete process.env.COREPACK_DEFAULT_TO_LATEST; | ||
|
||
// $ corepack enable | ||
await expect(runCli(installDir, [`enable`, `--install-directory`, npath.fromPortablePath(installDir), `yarn`])).resolves.toMatchObject({ | ||
stdout: ``, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
|
||
// Simulate the effect of `$ corepack enable` without the custom --install-directory option. | ||
process.env.PATH = `${npath.toPortablePath(installDir)}:${process.env.PATH}`; | ||
|
||
// $ corepack install --global [email protected] | ||
await expect(runCli(installDir, [`install`, `--global`, `[email protected]`])).resolves.toMatchObject({ | ||
stdout: `Installing [email protected]...\n`, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
|
||
// Make COREPACK_HOME ro | ||
const home = npath.toPortablePath(folderUtils.getCorepackHomeFolder()); | ||
await xfs.chmodPromise(ppath.join(home, `lastKnownGood.json`), 0o444); | ||
await xfs.chmodPromise(home, 0o555); | ||
|
||
// Use fake proxies to simulate offline mode | ||
process.env.HTTP_PROXY = `0.0.0.0`; | ||
process.env.HTTPS_PROXY = `0.0.0.0`; | ||
|
||
// $ corepack yarn --version | ||
await expect(runCli(installDir, [`yarn`, `--version`])).resolves.toMatchObject({ | ||
stdout: `2.2.2\n`, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
// $ yarn --version | ||
await expect(spawnCmd(installDir, `yarn`, [`--version`])).resolves.toMatchObject({ | ||
stdout: `2.2.2\n`, | ||
stderr: ``, | ||
exitCode: 0, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it(`should support hydrating package managers from cached archives`, async () => { | ||
await xfs.mktempPromise(async cwd => { | ||
await expect(runCli(cwd, [`pack`, `[email protected]`])).resolves.toMatchObject({ | ||
|