Skip to content

Commit

Permalink
GitDSL: Include created and removed files for diffForFile
Browse files Browse the repository at this point in the history
* Related to: #368
  • Loading branch information
bdotdub committed Sep 7, 2017
1 parent 10f8f79 commit 5f88511
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Master

- Updates `diffForFile` to include created and removed files - #368 - bdotdub

### 2.0.0-alpha.14

- Adds a blank project generated in travis 8 to test no-babel or TS integration - orta
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/GitHubGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default async function gitDSLForGitHub(api: GitHubAPI): Promise<GitDSL> {
const diffForFile = async (filename: string) => {
// We already have access to the diff, so see if the file is in there
// if it's not return an empty diff
const structuredDiff = modifiedDiffs.find((diff: any) => diff.from === filename || diff.to === filename)
const structuredDiff = fileDiffs.find((diff: any) => diff.from === filename || diff.to === filename)
if (!structuredDiff) {
return null
}
Expand Down
84 changes: 82 additions & 2 deletions source/platforms/github/_tests/_github_git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("the dangerfile gitDSL", async () => {
})

describe("JSONPatchForFile", () => {
it("returns a null for files not in the modified_files", async () => {
it("returns a null for files not in the change list", async () => {
const gitDSL = await github.getPlatformGitRepresentation()
const empty = await gitDSL.JSONPatchForFile("fuhqmahgads.json")
expect(empty).toEqual(null)
Expand Down Expand Up @@ -179,7 +179,7 @@ describe("the dangerfile gitDSL", async () => {
})

describe("JSONDiffForFile", () => {
it("returns an empty object for files not in the modified_files", async () => {
it("returns an empty object for files not in the change list", async () => {
const gitDSL = await github.getPlatformGitRepresentation()
const empty = await gitDSL.JSONDiffForFile("fuhqmahgads.json")
expect(empty).toEqual({})
Expand Down Expand Up @@ -278,4 +278,84 @@ describe("the dangerfile gitDSL", async () => {
})
})
})

describe("textDiffForFile", () => {
it("returns a null for files not in the change list", async () => {
const gitDSL = await github.getPlatformGitRepresentation()
const empty = await gitDSL.diffForFile("fuhqmahgads.json")
expect(empty).toEqual(null)
})

it("returns a diff for created files", async () => {
const before = ""
const after =
"/* @flow */\n" +
"'use strict'\n" +
"import Relay from 'react-relay'\n" +
"import React from 'react'\n" +
"import { View, StyleSheet } from 'react-native'\n" +
"import Biography from './biography'\n" +
"import RelatedArtists from '../related_artists'\n" +
"import Separator from '../separator'\n" +
"class About extends React.Component\n"

github.api.fileContents = async (path, repo, ref) => {
return ref === masterSHA ? before : after
}

const gitDSL = await github.getPlatformGitRepresentation()
const diff = await gitDSL.diffForFile("lib/components/gene/about.js")

expect(diff.before).toEqual("")
expect(diff.after).toMatch(/class About extends React.Component/)
expect(diff.diff).toMatch(/class About extends React.Component/)
})

it("returns a diff for deleted files", async () => {
const before =
"'use strict'\n" +
"import Relay from 'react-relay'\n" +
"import React from 'react'\n" +
"import { StyleSheet, View, Dimensions } from 'react-native'\n\n" +
"class RelatedArtists extends React.Component"

const after = ""

github.api.fileContents = async (path, repo, ref) => {
return ref === masterSHA ? before : after
}

const gitDSL = await github.getPlatformGitRepresentation()
const diff = await gitDSL.diffForFile("lib/components/artist/related_artists/index.js")

expect(diff.before).toMatch(/class RelatedArtists extends React.Component/)
expect(diff.after).toEqual("")
expect(diff.diff).toMatch(/class RelatedArtists extends React.Component/)
})

it("returns a diff for modified files", async () => {
const before =
`- [dev] Updates Flow to 0.32 - orta\n` +
`- [dev] Updates React to 0.34 - orta\n` +
`- [dev] Turns on "keychain sharing" to fix a keychain bug in sim - orta`

const after = `- [dev] Updates Flow to 0.32 - orta
- [dev] Updates React to 0.34 - orta
- [dev] Turns on "keychain sharing" to fix a keychain bug in sim - orta
- GeneVC now shows about information, and trending artists - orta`

github.api.fileContents = async (path, repo, ref) => {
return ref === masterSHA ? before : after
}

const gitDSL = await github.getPlatformGitRepresentation()
const diff = await gitDSL.diffForFile("CHANGELOG.md")

expect(diff.before).toEqual(before)
expect(diff.after).toEqual(after)
expect(diff.added).toEqual("+- GeneVC now shows about information, and trending artists - orta")
expect(diff.removed).toEqual("")
expect(diff.diff).toMatch(/GeneVC now shows about information, and trending artists/)
})
})
})

0 comments on commit 5f88511

Please sign in to comment.