-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`manager/npm/post-update/index updateYarnBinary() should return .yarnrc.yml content if it has been overwritten 1`] = ` | ||
"yarnPath: .yarn/releases/yarn-3.0.2.cjs | ||
a: b | ||
" | ||
`; | ||
|
||
exports[`manager/npm/post-update/index updateYarnBinary() should return .yarnrc.yml content if it has been overwritten 2`] = ` | ||
Array [ | ||
Object { | ||
"contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs | ||
a: b | ||
", | ||
"name": "path/to/lockfile/.yarnrc.yml", | ||
}, | ||
Object { | ||
"contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", | ||
"name": "|delete|", | ||
}, | ||
Object { | ||
"contents": "new yarn | ||
", | ||
"executable": true, | ||
"name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", | ||
}, | ||
] | ||
`; | ||
|
||
exports[`manager/npm/post-update/index updateYarnBinary() should update the Yarn binary 1`] = ` | ||
Array [ | ||
Object { | ||
"contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs | ||
a: b | ||
", | ||
"name": "path/to/lockfile/.yarnrc.yml", | ||
}, | ||
Object { | ||
"contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs", | ||
"name": "|delete|", | ||
}, | ||
Object { | ||
"contents": "new yarn | ||
", | ||
"executable": true, | ||
"name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs", | ||
}, | ||
] | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// TODO: add tests | ||
import { fs, git } from '../../../../test/util'; | ||
import { updateYarnBinary } from './index'; | ||
|
||
jest.mock('../../../util/fs'); | ||
jest.mock('../../../util/git'); | ||
|
||
describe('manager/npm/post-update/index', () => { | ||
const lockFileDir = `path/to/lockfile`; | ||
const oldYarnrcYml = `yarnPath: .yarn/releases/yarn-3.0.1.cjs\na: b\n`; | ||
const newYarnrcYml = `yarnPath: .yarn/releases/yarn-3.0.2.cjs\nc: d\n`; | ||
const newYarn = `new yarn\n`; | ||
|
||
beforeEach(() => { | ||
git.getFile = jest.fn(); | ||
fs.readLocalFile = jest.fn(); | ||
}); | ||
|
||
describe('updateYarnBinary()', () => { | ||
it('should update the Yarn binary', async () => { | ||
git.getFile.mockResolvedValueOnce(oldYarnrcYml); | ||
fs.readLocalFile.mockResolvedValueOnce(newYarnrcYml); | ||
fs.readLocalFile.mockResolvedValueOnce(newYarn); | ||
const updatedArtifacts = []; | ||
const yarnrcYmlContent = await updateYarnBinary( | ||
lockFileDir, | ||
updatedArtifacts, | ||
undefined | ||
); | ||
expect(yarnrcYmlContent).toBeUndefined(); | ||
expect(updatedArtifacts).toMatchSnapshot(); | ||
}); | ||
|
||
it('should return .yarnrc.yml content if it has been overwritten', async () => { | ||
fs.readLocalFile.mockResolvedValueOnce(newYarnrcYml); | ||
fs.readLocalFile.mockResolvedValueOnce(newYarn); | ||
let existingYarnrcYmlContent = oldYarnrcYml; | ||
const updatedArtifacts = []; | ||
existingYarnrcYmlContent = await updateYarnBinary( | ||
lockFileDir, | ||
updatedArtifacts, | ||
existingYarnrcYmlContent | ||
); | ||
expect(git.getFile).not.toHaveBeenCalled(); | ||
expect(existingYarnrcYmlContent).toMatchSnapshot(); | ||
expect(updatedArtifacts).toMatchSnapshot(); | ||
}); | ||
|
||
it("should not update the Yarn binary if the old .yarnrc.yml doesn't exist", async () => { | ||
git.getFile.mockResolvedValueOnce(null); | ||
fs.readLocalFile.mockResolvedValueOnce(newYarnrcYml); | ||
const updatedArtifacts = []; | ||
const yarnrcYmlContent = await updateYarnBinary( | ||
lockFileDir, | ||
updatedArtifacts, | ||
undefined | ||
); | ||
expect(yarnrcYmlContent).toBeUndefined(); | ||
expect(updatedArtifacts).toBeEmpty(); | ||
}); | ||
|
||
it("should not update the Yarn binary if the new .yarnrc.yml doesn't exist", async () => { | ||
git.getFile.mockResolvedValueOnce(oldYarnrcYml); | ||
fs.readLocalFile.mockResolvedValueOnce(null); | ||
const updatedArtifacts = []; | ||
const yarnrcYmlContent = await updateYarnBinary( | ||
lockFileDir, | ||
updatedArtifacts, | ||
undefined | ||
); | ||
expect(yarnrcYmlContent).toBeUndefined(); | ||
expect(updatedArtifacts).toBeEmpty(); | ||
}); | ||
|
||
it("should return existing .yarnrc.yml if the new one doesn't exist", async () => { | ||
fs.readLocalFile.mockResolvedValueOnce(null); | ||
let existingYarnrcYmlContent = oldYarnrcYml; | ||
const updatedArtifacts = []; | ||
existingYarnrcYmlContent = await updateYarnBinary( | ||
lockFileDir, | ||
updatedArtifacts, | ||
existingYarnrcYmlContent | ||
); | ||
expect(existingYarnrcYmlContent).toMatch(existingYarnrcYmlContent); | ||
expect(updatedArtifacts).toBeEmpty(); | ||
}); | ||
}); | ||
}); |
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