Skip to content

Commit

Permalink
test: update some tests for new behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Iiro Jäppinen committed Jun 18, 2019
1 parent cb7f149 commit 5af2050
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions test/gitStash.spec.js
Expand Up @@ -103,7 +103,7 @@ describe('git', () => {
})
})

describe('gitStashSave/gitStashPop', () => {
describe('saveStagedFiles/restoreStagedFiles', () => {
it('should stash and restore WC state without a commit', async () => {
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
Expand All @@ -118,11 +118,14 @@ M test.js"
`)

// Stashing files
await gitflow.gitStashSave(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
await gitflow.saveStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
M test.js"
`)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
M test.js"
Expand All @@ -139,11 +142,14 @@ D test.js"
`)

// Stashing files
await gitflow.gitStashSave(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`"D test.js"`)
await gitflow.saveStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
D test.js"
`)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
D test.js"
Expand All @@ -160,11 +166,14 @@ D test.js"
`)

// Stashing files
await gitflow.gitStashSave(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`"R test.js -> test-renamed.js"`)
await gitflow.saveStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
"R test.js -> test-renamed.js
M test.css"
`)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
"R test.js -> test-renamed.js
M test.css"
Expand All @@ -183,13 +192,18 @@ D test.js"
`)

// Stashing files
await gitflow.gitStashSave(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`"?? test-renamed.js"`)
await gitflow.saveStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
D test.js
?? test-renamed.js"
`)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
D test.js
?? test-renamed.js"
`)
})
Expand All @@ -213,10 +227,8 @@ M test.js"
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Stashing state
await gitflow.gitStashSave(gitOpts)
await gitflow.saveStagedFiles(gitOpts)

// Only index should remain
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Do additional edits (imitate eslint --fix)
Expand All @@ -229,12 +241,15 @@ M test.js"
await fsp.writeFile(path.join(wcDirPath, 'test.js'), eslintContent)

// Expect both indexed and modified state on one file
expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
MM test.js"
`)
// and index isn't modified
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)
// Expect stashed files to be back
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
Expand Down Expand Up @@ -272,10 +287,7 @@ MM test.js"
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Stashing state
await gitflow.gitStashSave(gitOpts)

// Only index should remain
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
await gitflow.saveStagedFiles(gitOpts)

// Do additional edits (imitate eslint --fix)
await fsp.writeFile(
Expand All @@ -285,13 +297,16 @@ MM test.js"
};`
)

// Expect both indexed and modified state on one file
expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`)
// Expect both indexed and modified state
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
MM test.js"
`)
// and index isn't modified
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)

// Expect stashed files to be back
expect(await gitStatus()).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -321,10 +336,7 @@ M test.js"
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Stashing state
await gitflow.gitStashSave(gitOpts)

// Only index should remain
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
await gitflow.saveStagedFiles(gitOpts)

// Do additional edits (imitate eslint --fix)
const newContent = `module.exports = {
Expand All @@ -333,18 +345,16 @@ M test.js"
await fsp.writeFile(path.join(wcDirPath, 'test.js'), newContent)
// and add to index
await gitflow.execGit(['add', 'test.js'], gitOpts)
await gitflow.updateStash(gitOpts)
const newIndex = await gitflow.execGit(['diff', '--cached'], gitOpts)

// Expect only index changes
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
M test.js"
`)
// and index is modified
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).not.toEqual(initialIndex)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex)

// Restoring state
await gitflow.gitStashPop(gitOpts)

// Expect stashed files to be back
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
Expand Down Expand Up @@ -382,10 +392,8 @@ MM test.js"
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Stashing state
await gitflow.gitStashSave(gitOpts)
await gitflow.saveStagedFiles(gitOpts)

// Only index should remain
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Do additional edits (imitate eslint --fix)
Expand All @@ -397,25 +405,21 @@ MM test.js"
)
// and add to index
await gitflow.execGit(['add', 'test.js'], gitOpts)
await gitflow.updateStash(gitOpts)
const newIndex = await gitflow.execGit(['diff', '--cached'], gitOpts)

// Expect index is modified
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).not.toEqual(initialIndex)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)

// Expect stashed files to be back
expect(await gitStatus()).toMatchInlineSnapshot(`
" M test.css
MM test.js"
`)
// and content is back to user modifications
expect(await readFile('test.js')).toEqual(userContent)
// Expect formatting changes in the index
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(newIndex)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)
})

it('should add hooks fixes to index and working copy on partially staged files', async () => {
Expand Down Expand Up @@ -462,10 +466,8 @@ MM test.js"
const initialIndex = await gitflow.execGit(['diff', '--cached'], gitOpts)

// Stashing state
await gitflow.gitStashSave(gitOpts)
await gitflow.saveStagedFiles(gitOpts)

// Only index should remain
expect(await gitStatus()).toMatchInlineSnapshot(`"M test.js"`)
expect(await gitflow.execGit(['diff', '--cached'], gitOpts)).toEqual(initialIndex)

// Imitate running prettier on the version from the index
Expand All @@ -483,11 +485,10 @@ MM test.js"
};`
)
await gitflow.execGit(['add', 'test.js'], gitOpts)
await gitflow.updateStash(gitOpts)
const indexAfterEslint = await gitflow.execGit(['diff', '--cached'], gitOpts)

// Restoring state
await gitflow.gitStashPop(gitOpts)
await gitflow.restoreStagedFiles(gitOpts)

// Expect stashed files to be back
expect(await gitStatus()).toMatchInlineSnapshot(`"MM test.js"`)
Expand Down

0 comments on commit 5af2050

Please sign in to comment.