Skip to content

Commit

Permalink
test(monorepo): test many monorepo permutations
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Apr 11, 2018
1 parent 3a548d3 commit 3e8d2d1
Show file tree
Hide file tree
Showing 28 changed files with 181 additions and 44 deletions.
1 change: 1 addition & 0 deletions test/fixtures/no-root-and-one-sub/sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/no-root-and-one-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/no-root-and-two-diff-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub3-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/no-root-and-two-sub/sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/no-root-and-two-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/no-root-and-two-sub/sub1/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/no-root-and-two-sub/sub1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub1-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-one-sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-one-sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-one-sub/sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-one-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-two-diff-sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-diff-sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-two-diff-sub/sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-diff-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-diff-sub/sub1/subsub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub2-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-two-sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-two-sub/sub/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-sub/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
1 change: 1 addition & 0 deletions test/fixtures/root-and-two-sub/sub1/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/root-and-two-sub/sub1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "sub1-test",
"dependencies": {
"my-dependency": "1.0.0"
}
}
23 changes: 21 additions & 2 deletions test/lib/update-lockfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const stub = require('sinon').stub
const exec = stub(require('child_process'), 'execSync')
const childProcess = require('child_process')
const exec = stub(childProcess, 'execSync')

const updateLockfile = require('../../lib/update-lockfile')
const { updateLockfile, commitLockfile } = require('../../lib/update-lockfile')

const dependency = {
type: 'dependencies',
Expand All @@ -16,13 +17,18 @@ const prepare = () => {
exec.withArgs('git status --porcelain').returns('1')
}

afterAll(() => {
childProcess.execSync.restore()
})

const updateMessage = 'chore(package): update lockfile\n\nhttps://npm.im/greenkeeper-lockfile'

test('do shrinkwrap for old npm versions', () => {
prepare()
expect.assertions(1)
exec.withArgs('npm --version').returns('2.0.0')
updateLockfile({}, {})
commitLockfile()
expect(exec.secondCall.calledWith('npm shrinkwrap')).toBeTruthy()
})

Expand All @@ -31,6 +37,7 @@ test('use yarn', () => {
expect.assertions(1)
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, { yarn: true })
commitLockfile()
expect(exec.thirdCall.calledWith("yarn add '[email protected]'")).toBeTruthy()
})

Expand All @@ -43,6 +50,7 @@ test('yarn no prefix', () => {
exec.withArgs('npm --version').returns('3.0.0')
exec.withArgs('npm5 -v').throws()
updateLockfile(tildeDep, { yarn: true })
commitLockfile()
expect(exec.thirdCall.calledWith("yarn add '[email protected]'")).toBeTruthy()
})

Expand All @@ -52,6 +60,7 @@ test('use yarn with extra arguments from ENV', () => {
process.env.GK_LOCK_YARN_OPTS = '--ignore-engines'
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, { yarn: true })
commitLockfile()
expect(exec.thirdCall.calledWith("yarn add --ignore-engines '[email protected]'")).toBeTruthy()
delete process.env.GK_LOCK_YARN_OPTS
})
Expand All @@ -62,6 +71,7 @@ test('use npm', () => {
exec.withArgs('npm --version').returns('3.0.0')
exec.withArgs('npm5 -v').throws()
updateLockfile(dependency, { npm: true })
commitLockfile()
expect(exec.getCall(4).calledWith('npm install -S [email protected]')).toBeTruthy()
})

Expand All @@ -71,6 +81,7 @@ test('use npm v5', () => {
exec.withArgs('npm --version').returns('3.0.0')
exec.withArgs('npm5 -v').returns('5.0.0')
updateLockfile(dependency, { npm: true })
commitLockfile()
expect(exec.getCall(4).calledWith('npm5 install -S [email protected]')).toBeTruthy()
})

Expand All @@ -79,6 +90,7 @@ test('default author', () => {
exec.withArgs('npm --version').returns('3.0.0')
expect.assertions(2)
updateLockfile(dependency, { npm: true })
commitLockfile()
expect(exec.getCall(9).calledWith('git config user.email "[email protected]"')).toBeTruthy()
expect(exec.getCall(10).calledWith('git config user.name "greenkeeperio-bot"')).toBeTruthy()
})
Expand All @@ -90,6 +102,7 @@ test('customise author', () => {
exec.withArgs('npm --version').returns('3.0.0')
expect.assertions(2)
updateLockfile(dependency, { npm: true })
commitLockfile()
expect(exec.getCall(9).calledWith('git config user.email "[email protected]"')).toBeTruthy()
expect(exec.getCall(10).calledWith('git config user.name "testbot"')).toBeTruthy()
delete process.env.GK_LOCK_COMMIT_EMAIL
Expand All @@ -106,6 +119,7 @@ test('tilde prefix', () => {
exec.withArgs('npm --version').returns('3.0.0')
exec.withArgs('npm5 -v').throws()
updateLockfile(tildeDep, { yarn: true, npm: true })
commitLockfile()
expect(exec.thirdCall.calledWith("yarn add 'my-dependency@~1.0.0'")).toBeTruthy()
expect(exec.getCall(4).calledWith('npm install -S --save-prefix="~" [email protected]')).toBeTruthy()
})
Expand All @@ -115,6 +129,7 @@ test('no status', () => {
exec.withArgs('npm --version').returns('3.0.0')
exec.withArgs('git status --porcelain').returns('')
updateLockfile(dependency, { npm: true })
commitLockfile()
expect.assertions(1)
expect(exec.callCount).toBe(6)
})
Expand All @@ -124,6 +139,7 @@ test('no GK_LOCK_COMMIT_AMEND', () => {
expect.assertions(1)
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, {})
commitLockfile()
expect(exec.getCall(9).calledWith(`git commit -m "${updateMessage}"`)).toBeTruthy()
})

Expand All @@ -135,6 +151,7 @@ test('with truthy GK_LOCK_COMMIT_AMEND', () => {
process.env.GK_LOCK_COMMIT_AMEND = fixture
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, {})
commitLockfile()
expect(exec.getCall(9).calledWith(`git commit --amend --author="greenkeeperio-bot <[email protected]>" --no-edit`)).toBeTruthy()
})
delete process.env.GK_LOCK_COMMIT_AMEND
Expand All @@ -150,6 +167,7 @@ test('with truthy GK_LOCK_COMMIT_AMEND and GK_LOCK_COMMIT_NAME/EMAIL', () => {
process.env.GK_LOCK_COMMIT_AMEND = fixture
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, {})
commitLockfile()
expect(exec.getCall(9).calledWith(`git commit --amend --author="Example Person <[email protected]>" --no-edit`)).toBeTruthy()
})
delete process.env.GK_LOCK_COMMIT_AMEND
Expand All @@ -165,6 +183,7 @@ test('with falsy GK_LOCK_COMMIT_AMEND', () => {
process.env.GK_LOCK_COMMIT_AMEND = fixture
exec.withArgs('npm --version').returns('3.0.0')
updateLockfile(dependency, {})
commitLockfile()
expect(exec.getCall(9).calledWith(`git commit -m "${updateMessage}"`)).toBeTruthy()
})
delete process.env.GK_LOCK_COMMIT_AMEND
Expand Down
Loading

0 comments on commit 3e8d2d1

Please sign in to comment.