Skip to content

Commit

Permalink
Merge pull request #668 from huafu/fix-ts-issues
Browse files Browse the repository at this point in the history
Enables ES module interoperability + upgrades jest & ts-jest
  • Loading branch information
orta authored Sep 20, 2018
2 parents 23eb323 + 0491713 commit 4100842
Show file tree
Hide file tree
Showing 52 changed files with 254 additions and 271 deletions.
19 changes: 5 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,13 @@
"danger-reset-status": "distribution/commands/danger-reset-status.js"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"preset": "ts-jest",
"testResultsProcessor": "jest-json-reporter",
"testRegex": "(.test)\\.(ts|tsx)$",
"testPathIgnorePatterns": [
"/node_modules/",
"/distribution/",
"/types/"
],
"moduleFileExtensions": [
"js",
"jsx",
"json",
"ts",
"tsx"
],
"cacheDirectory": ".jest/cache"
},
"lint-staged": {
Expand Down Expand Up @@ -105,6 +95,7 @@
"@types/json5": "^0.0.29",
"@types/jsonwebtoken": "^7.2.8",
"@types/lodash.includes": "^4.3.3",
"@types/node": "^10.10.1",
"@types/node-fetch": "^2.1.2",
"@types/p-limit": "^1.1.2",
"@types/readline-sync": "^1.4.3",
Expand All @@ -114,19 +105,19 @@
"date-fns": "^1.29.0",
"flow-bin": "^0.77.0",
"husky": "^0.14.0",
"jest": "23.5.0",
"jest": "^23.6.0",
"jest-json-reporter": "^1.2.2",
"lint-staged": "^7.2.0",
"madge": "^3.2.0",
"prettier": "^1.14.2",
"release-it": "^7.6.1",
"shx": "^0.3.2",
"ts-jest": "^23.1.3",
"ts-jest": "^23.10.0",
"ts-node": "^7.0.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.14.0",
"typedoc": "0.9.0",
"typescript": "^3.0.1"
"typescript": "^3.0.3"
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/danger-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const createDTS = () => {
// Autogenerated from scripts/danger-dts.ts
//
import * as GitHub from "@octokit/rest"
import GitHub from "@octokit/rest"
`
const footer = ``
Expand Down
10 changes: 5 additions & 5 deletions source/api/_tests/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface ResponseMock {
class TestServer {
private port = 30001
private hostname = "localhost"
private response: ResponseMock = null
private router = (req, res) => {
private response: ResponseMock = null as any
private router = (_req: any, res: any) => {
res.statusCode = this.response && this.response.statusCode ? this.response.statusCode : 200
res.setHeader(
"Content-Type",
Expand All @@ -26,13 +26,13 @@ class TestServer {
start = async (response: ResponseMock): Promise<void> => {
this.response = response
return new Promise<void>((resolve, reject) => {
this.server.listen(this.port, this.hostname, err => (err ? reject(err) : resolve()))
this.server.listen(this.port, this.hostname, (err: any) => (err ? reject(err) : resolve()))
})
}
stop = async (): Promise<void> => {
this.response = null
this.response = null as any
return new Promise<void>((resolve, reject) => {
this.server.close(err => (err ? reject(err) : resolve()))
this.server.close((err: any) => (err ? reject(err) : resolve()))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function api(

d(output.join(" "))
}
const originalFetch: any = node_fetch
const originalFetch = node_fetch.default
return originalFetch(url, init).then(async (response: node_fetch.Response) => {
// Handle failing errors
if (!suppressErrorReporting && !response.ok) {
Expand Down
2 changes: 1 addition & 1 deletion source/ci_source/_tests/_get_ci_source.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FakeCI } from "../providers/Fake"
import * as DummyCI from "./fixtures/dummy_ci"
import DummyCI from "./fixtures/dummy_ci"
import { getCISourceForEnv, getCISourceForExternal } from "../get_ci_source"

describe(".getCISourceForEnv", () => {
Expand Down
1 change: 1 addition & 0 deletions source/ci_source/_tests/fixtures/dummy_ci.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class DummyCI {}
2 changes: 1 addition & 1 deletion source/ci_source/ci_source_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Env } from "./ci_source"
import { GitHubAPI } from "../platforms/github/GitHubAPI"
import { GitHubPRDSL } from "../dsl/GitHubDSL"
import * as find from "lodash.find"
import find from "lodash.find"
import {
BitBucketServerAPI,
bitbucketServerRepoCredentialsFromEnv,
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-ci.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

import * as program from "commander"
import program from "commander"

import setSharedArgs, { SharedCLI } from "./utils/sharedDangerfileArgs"
import { runRunner } from "./ci/runner"
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node

import chalk from "chalk"
import * as program from "commander"
import program from "commander"

import * as fs from "fs"

Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-local.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

import * as program from "commander"
import program from "commander"

import setSharedArgs, { SharedCLI } from "./utils/sharedDangerfileArgs"
import { runRunner } from "./ci/runner"
Expand Down
4 changes: 2 additions & 2 deletions source/commands/danger-pr.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env node

import * as program from "commander"
import program from "commander"
import { debug } from "../debug"
import * as jsome from "jsome"
import jsome from "jsome"

import { FakeCI } from "../ci_source/providers/Fake"
import { pullRequestParser } from "../platforms/pullRequestParser"
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-process.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node

import chalk from "chalk"
import * as program from "commander"
import program from "commander"

import { getPlatformForEnv } from "../platforms/platform"
import { Executor, ExecutorOptions } from "../runner/Executor"
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger-reset-status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

import * as program from "commander"
import program from "commander"

import setSharedArgs, { SharedCLI } from "./utils/sharedDangerfileArgs"
import { runRunner } from "./ci/runner"
Expand Down
6 changes: 3 additions & 3 deletions source/commands/danger-runner.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#! /usr/bin/env node

import setSharedArgs from "./utils/sharedDangerfileArgs"
import * as nodeCleanup from "node-cleanup"
import nodeCleanup from "node-cleanup"

import * as program from "commander"
import program from "commander"
import { debug } from "../debug"
import * as getSTDIN from "get-stdin"
import getSTDIN from "get-stdin"
import chalk from "chalk"

import inline from "../runner/runners/inline"
Expand Down
2 changes: 1 addition & 1 deletion source/commands/danger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env node

import * as program from "commander"
import program from "commander"
import chalk from "chalk"
import { version } from "../../package.json"

Expand Down
4 changes: 2 additions & 2 deletions source/commands/init/get-repo-slug.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as parseGitConfig from "parse-git-config"
import * as parseGithubURL from "parse-github-url"
import parseGitConfig from "parse-git-config"
import parseGithubURL from "parse-github-url"

export const getRepoSlug = () => {
const config = parseGitConfig.sync()
Expand Down
6 changes: 3 additions & 3 deletions source/commands/init/state-setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as readlineSync from "readline-sync"
import * as supportsHyperlinks from "supports-hyperlinks"
import * as hyperLinker from "hyperlinker"
import readlineSync from "readline-sync"
import supportsHyperlinks from "supports-hyperlinks"
import hyperLinker from "hyperlinker"
import chalk from "chalk"

import { basename } from "path"
Expand Down
2 changes: 1 addition & 1 deletion source/commands/utils/_tests/file-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let mockDangerfilePath = ""
jest.mock("fs", () => ({ existsSync: p => p === mockDangerfilePath }))
jest.mock("fs", () => ({ existsSync: (p: any) => p === mockDangerfilePath }))

import { dangerfilePath } from "../file-utils"

Expand Down
2 changes: 1 addition & 1 deletion source/commands/utils/sharedDangerfileArgs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander"
import program from "commander"
import chalk from "chalk"

process.on("unhandledRejection", function(reason: string, _p: any) {
Expand Down
2 changes: 1 addition & 1 deletion source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Autogenerated from scripts/danger-dts.ts
//

import * as GitHub from "@octokit/rest"
import GitHub from "@octokit/rest"

type MarkdownString = string

Expand Down
2 changes: 1 addition & 1 deletion source/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as debugModule from "debug"
import debugModule from "debug"

export const debug = (value: string) => {
const d = debugModule(`danger:${value}`)
Expand Down
2 changes: 1 addition & 1 deletion source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitCommit } from "./Commit"
import * as GitHub from "@octokit/rest"
import GitHub from "@octokit/rest"

// This is `danger.github` inside the JSON

Expand Down
2 changes: 1 addition & 1 deletion source/platforms/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GitHubAPI } from "./github/GitHubAPI"
import GitHubUtils from "./github/GitHubUtils"
import gitDSLForGitHub from "./github/GitHubGit"

import * as NodeGitHub from "@octokit/rest"
import NodeGitHub from "@octokit/rest"
import { Platform } from "./platform"

import { GitHubIssueCommenter } from "./github/comms/issueCommenter"
Expand Down
5 changes: 0 additions & 5 deletions source/platforms/_tests/_bitbucket_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,8 @@ jest.mock("../bitbucket_server/BitBucketServerAPI", () => {
import { BitBucketServer } from "../BitBucketServer"
import { BitBucketServerAPI } from "../bitbucket_server/BitBucketServerAPI"

import { GitCommit } from "../../dsl/Commit"
import { FakeCI } from "../../ci_source/providers/Fake"
import * as os from "os"
import { RepoMetaData } from "../../dsl/BitBucketServerDSL"

const EOL = os.EOL

describe("getPlatformDSLRepresentation", () => {
let bbs: BitBucketServer

Expand Down
9 changes: 2 additions & 7 deletions source/platforms/_tests/_github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,13 @@ jest.mock("../github/GitHubAPI", () => {
return { GitHubAPI: mockGitHubAPI }
})

import { GitHub } from "../GitHub"
import { GitHub, GitHubType } from "../GitHub"
import { GitHubAPI } from "../github/GitHubAPI"

import { GitCommit } from "../../dsl/Commit"
import { FakeCI } from "../../ci_source/providers/Fake"
import * as os from "os"
import { RepoMetaData } from "../../dsl/BitBucketServerDSL"

const EOL = os.EOL

describe("getPlatformDSLRepresentation", () => {
let github: GitHub
let github: GitHubType

beforeEach(() => {
github = GitHub(new GitHubAPI({} as RepoMetaData))
Expand Down
4 changes: 2 additions & 2 deletions source/platforms/bitbucket_server/BitBucketServerAPI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { debug } from "../../debug"
import * as node_fetch from "node-fetch"
import { Agent } from "http"
import * as HttpsProxyAgent from "https-proxy-agent"
import * as v from "voca"
import HttpsProxyAgent from "https-proxy-agent"
import v from "voca"

import {
BitBucketServerPRDSL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { BitBucketServer } from "../../BitBucketServer"
import { BitBucketServerAPI } from "../BitBucketServerAPI"

import { GitCommit } from "../../../dsl/Commit"
import { FakeCI } from "../../../ci_source/providers/Fake"
import { readFileSync } from "fs"
import { resolve, join as pathJoin } from "path"
import { EOL } from "os"
import { bitBucketServerGitDSL as gitJSONToGitDSL } from "../BitBucketServerGit"

import { BitBucketServerDSL } from "../../../dsl/BitBucketServerDSL"
Expand Down Expand Up @@ -37,8 +35,6 @@ const stripWhitespaceForSnapshot = (str: string) => {
}

const pullRequestInfoFilename = "bitbucket_server_pr.json"
const masterSHA = JSON.parse(readFileSync(pathJoin(fixtures, pullRequestInfoFilename), {}).toString()).toRef
.latestCommit

describe("the dangerfile gitDSL - BitBucket Server", async () => {
let bbs: BitBucketServer = {} as any
Expand Down Expand Up @@ -72,36 +68,36 @@ describe("the dangerfile gitDSL - BitBucket Server", async () => {
})

it("shows the diff for a specific file", async () => {
const { diff } = await gitDSL.diffForFile(".gitignore")
const { diff } = (await gitDSL.diffForFile(".gitignore"))!

expect(stripWhitespaceForSnapshot(diff)).toMatchSnapshot()
})

it("should include `before` text content of the file", async () => {
const { before } = await gitDSL.diffForFile(".gitignore")
const { before } = (await gitDSL.diffForFile(".gitignore"))!

expect(stripWhitespaceForSnapshot(before)).toMatchSnapshot()
})

it("should include `after` text content of the file", async () => {
const { after } = await gitDSL.diffForFile(".gitignore")
const { after } = (await gitDSL.diffForFile(".gitignore"))!

expect(stripWhitespaceForSnapshot(after)).toMatchSnapshot()
})

it("should include `added` text content of the file", async () => {
const { added } = await gitDSL.diffForFile(".gitignore")
const { added } = (await gitDSL.diffForFile(".gitignore"))!

expect(stripWhitespaceForSnapshot(added)).toMatchSnapshot()
})

it("should not include `removed` text content of the file", async () => {
const { removed } = await gitDSL.diffForFile(".gitignore")
const { removed } = (await gitDSL.diffForFile(".gitignore"))!
expect(stripWhitespaceForSnapshot(removed)).toMatchSnapshot()
})

it("resolves to `null` for files not in modified_files", async () => {
const result = await gitDSL.diffForFile("fuhqmahgads.json")
const result = (await gitDSL.diffForFile("fuhqmahgads.json"))!

expect(result).toBeNull()
})
Expand All @@ -111,7 +107,7 @@ describe("the dangerfile gitDSL - BitBucket Server", async () => {
})

it("shows the structured diff for a specific file", async () => {
const { chunks } = await gitDSL.structuredDiffForFile(".gitignore")
const { chunks } = (await gitDSL.structuredDiffForFile(".gitignore"))!
expect(chunks).toMatchSnapshot()
})

Expand Down
4 changes: 2 additions & 2 deletions source/platforms/git/diffToGitJSONDSL.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as parseDiff from "parse-diff"
import * as includes from "lodash.includes"
import parseDiff from "parse-diff"
import includes from "lodash.includes"
import { GitCommit } from "../../dsl/Commit"
import { GitJSONDSL } from "../../dsl/GitDSL"

Expand Down
Loading

0 comments on commit 4100842

Please sign in to comment.