From 3d7b142da0e0515acba846f5adf24c43d1528a56 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 12 Mar 2018 16:53:12 +0900 Subject: [PATCH] Fix dem tests --- .gitignore | 3 ++- package.json | 1 + spec/index.test.js | 10 +++++++--- src/backport/utils.ts | 2 +- src/index.js | 12 ++++++------ tsconfig.json | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 9b26ed0..8106915 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -lib \ No newline at end of file +lib +working \ No newline at end of file diff --git a/package.json b/package.json index c0e518e..a95ddbb 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "scripts": { "prestart": "tsc", "start": "probot run ./lib/index.js", + "pretest": "tsc", "test": "jest && standard" }, "dependencies": { diff --git a/spec/index.test.js b/spec/index.test.js index 74f4deb..ce3b3f4 100644 --- a/spec/index.test.js +++ b/spec/index.test.js @@ -1,6 +1,10 @@ jest.mock('request') +jest.mock('../lib/backport/utils.js', () => ({ + ensureElectronUpToDate: async () => {}, + backportPR: async () => {} +})) const {createRobot} = require('probot') -const issueBoardTracker = require('../index.js') +const issueBoardTracker = require('../lib/index.js') const pushEventPayload = require('./fixtures/push.json') const issueLabeledEventPayload = require('./fixtures/issues.labeled.json') @@ -9,9 +13,9 @@ const prLabeledEventPayload = require('./fixtures/pull_request.labeled.json') describe('issue-board-tracker', () => { let robot, github - beforeEach(() => { + beforeEach(async () => { robot = createRobot() - issueBoardTracker(robot) + await issueBoardTracker(robot) github = { repos: { diff --git a/src/backport/utils.ts b/src/backport/utils.ts index 07f5671..96a151c 100644 --- a/src/backport/utils.ts +++ b/src/backport/utils.ts @@ -6,7 +6,7 @@ import * as simpleGit from 'simple-git'; import { Probot, ProbotContext, Label, PullRequestEvent } from './Probot'; import queue from './Queue'; -const dir = path.resolve(__dirname, '..', 'working'); +const dir = path.resolve(__dirname, '..', '..', 'working'); const getGit = () => simpleGit(dir); export const ensureElectronUpToDate = async () => { diff --git a/src/index.js b/src/index.js index fa6bff6..7af0624 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,11 @@ -import randomColor from 'randomcolor' +import * as randomColor from 'randomcolor' import { backportPR, ensureElectronUpToDate } from './backport/utils' -module.exports = (robot) => { +module.exports = async (robot) => { + robot.log('initializing working directory') + await ensureElectronUpToDate() + robot.log('working directory ready') + // get watched board and create labels based on column names robot.on('push', async context => { const config = await context.config('config.yml') @@ -70,10 +74,6 @@ module.exports = (robot) => { } }) - robot.log('initializing working directory') - await ensureElectronUpToDate() - robot.log('working directory ready') - robot.on('pull_request.closed', context => { const payload = context.payload if (payload.pull_request.merged) { diff --git a/tsconfig.json b/tsconfig.json index 0f9168e..66018c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "target": "es6", + "target": "es2018", "outDir": "lib", "lib": [ "es6"