|
| 1 | +jest.mock("danger", () => jest.fn()) |
| 2 | +import danger from 'danger' |
| 3 | +const dm = danger as any; |
| 4 | + |
| 5 | +import { xcodeprojConfiguration } from '../org/allPRs' |
| 6 | + |
| 7 | +beforeEach(() => { |
| 8 | + dm.addedLines = "" |
| 9 | + dm.fail = jest.fn().mockReturnValue(true); |
| 10 | + |
| 11 | + dm.danger = { |
| 12 | + git: { |
| 13 | + diffForFile: async (_filename) => { |
| 14 | + return { added: dm.addedLines } |
| 15 | + }, |
| 16 | + modified_files: [ |
| 17 | + "DuckDuckGo.xcodeproj/project.pbxproj" |
| 18 | + ] |
| 19 | + }, |
| 20 | + github: { |
| 21 | + pr: { |
| 22 | + additions: 200, |
| 23 | + deletions: 10 |
| 24 | + }, |
| 25 | + thisPR: { |
| 26 | + repo: "macos-browser" |
| 27 | + } |
| 28 | + }, |
| 29 | + } |
| 30 | +}) |
| 31 | + |
| 32 | +describe("Xcode project file configuration checks", () => { |
| 33 | + it("does not fail with no changes to project file", async () => { |
| 34 | + dm.danger.git.modified_files = [] |
| 35 | + |
| 36 | + await xcodeprojConfiguration() |
| 37 | + |
| 38 | + expect(dm.fail).not.toHaveBeenCalled() |
| 39 | + }) |
| 40 | + |
| 41 | + it("does not fail with no diff in project file", async () => { |
| 42 | + dm.danger.git.diffForFile = async (_filename) => {} |
| 43 | + |
| 44 | + await xcodeprojConfiguration() |
| 45 | + |
| 46 | + expect(dm.fail).not.toHaveBeenCalled() |
| 47 | + }) |
| 48 | + |
| 49 | + it("does not fail with no additions", async () => { |
| 50 | + await xcodeprojConfiguration() |
| 51 | + |
| 52 | + expect(dm.fail).not.toHaveBeenCalled() |
| 53 | + }) |
| 54 | + |
| 55 | + it("does not fail with added source file", async () => { |
| 56 | + dm.addedLines = ` |
| 57 | ++ 372C27BE297AD5C200C758EB /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372C27BD297AD5C200C758EB /* Test.swift */; }; |
| 58 | ++ 372C27BD297AD5C200C758EB /* Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; }; |
| 59 | ++ 372C27BD297AD5C200C758EB /* Test.swift */, |
| 60 | ++ 372C27BE297AD5C200C758EB /* Test.swift in Sources */, |
| 61 | + ` |
| 62 | + |
| 63 | + await xcodeprojConfiguration() |
| 64 | + |
| 65 | + expect(dm.fail).not.toHaveBeenCalled() |
| 66 | + }) |
| 67 | + |
| 68 | + it("fails with added configuration", async () => { |
| 69 | + dm.addedLines = ` |
| 70 | ++ ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES; |
| 71 | + ` |
| 72 | + |
| 73 | + await xcodeprojConfiguration() |
| 74 | + |
| 75 | + expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.") |
| 76 | + }) |
| 77 | + |
| 78 | + it("fails with added configuration with empty value", async () => { |
| 79 | + dm.addedLines = ` |
| 80 | ++ CODE_SIGN_IDENTITY = ; |
| 81 | + ` |
| 82 | + |
| 83 | + await xcodeprojConfiguration() |
| 84 | + |
| 85 | + expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.") |
| 86 | + }) |
| 87 | + |
| 88 | + it("fails with added configuration with key containing digits", async () => { |
| 89 | + dm.addedLines = ` |
| 90 | ++ GCC_WARN_64_TO_32_BIT_CONVERSION = YES_ERROR; |
| 91 | + ` |
| 92 | + |
| 93 | + await xcodeprojConfiguration() |
| 94 | + |
| 95 | + expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.") |
| 96 | + }) |
| 97 | + |
| 98 | + it("does not fail with added cofiguration in non-macos app repo", async () => { |
| 99 | + dm.danger.github.thisPR.repo = "iOS" |
| 100 | + dm.addedLines = ` |
| 101 | ++ GCC_WARN_64_TO_32_BIT_CONVERSION = YES_ERROR; |
| 102 | + ` |
| 103 | + |
| 104 | + await xcodeprojConfiguration() |
| 105 | + |
| 106 | + expect(dm.fail).not.toHaveBeenCalled() |
| 107 | + }) |
| 108 | +}) |
| 109 | + |
| 110 | + |
0 commit comments