Unverified Commit 683ee907 authored by Adam Zerella's avatar Adam Zerella Committed by GitHub
Browse files

ES6 support in app and tests (#6)

parent 7277ba7e
......@@ -10,4 +10,4 @@ GITHUB_CLIENT_SECRET=<secret>
ACCOUNT_SEED="twelve words seperated by spaces which seeds the account controlled by bot"
ALLOWED_USERS=["shawntabrizi", "and", "other", "github", "usernames", "in", "an", "array"]
\ No newline at end of file
ALLOWED_USERS=["shawntabrizi", "and", "other", "github", "usernames", "in", "an", "array"]
......@@ -8,6 +8,19 @@
"commonjs": true,
"es6": true
},
"overrides": [
{
"files": ["**/*.test.js"],
"env": {
"mocha": true
},
"plugins": ["mocha"],
"rules": {
"mocha/no-exclusive-tests": "error",
"mocha/no-pending-tests": "error"
}
}
],
"rules": {
"prefer-const": "warn"
}
......
'use strict';
module.exports = {
require: '@babel/register',
spec: ['test/**/*.test.js'],
sort: true,
};
FROM node:12-slim
FROM node:12-alpine
RUN apk -U upgrade --no-cache
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm ci --production
RUN npm cache clean --force
COPY package.json ./
COPY package-lock.json ./
COPY babel.config.json ./
COPY index.js .
RUN npm ci
RUN npm run build
# Purge the devDeps required for building
RUN npm prune --production
ENV NODE_ENV="production"
COPY . .
CMD [ "npm", "start" ]
CMD [ "node", "dist/index.js" ]
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"compact": true,
"comments": false
}
......@@ -13,9 +13,12 @@
],
"scripts": {
"start": "probot run ./index.js",
"test": "jest",
"test": "mocha",
"lint": "eslint index.js --cache",
"lint:fix": "eslint index.js --cache --fix"
"lint:fix": "eslint index.js --cache --fix",
"build": "run-s build:*",
"build:clean": "rimraf dist/",
"build:js": "babel index.js --extensions '.ts,.js' --out-dir dist/"
},
"dependencies": {
"@polkadot/api": "^6.0.5",
......@@ -23,18 +26,22 @@
"probot": "^11.0.1"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/register": "^7.15.3",
"chai": "^4.3.4",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^26.6.3",
"mocha": "^9.1.2",
"nock": "^13.0.5",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"smee-client": "^1.2.2"
},
"engines": {
"node": ">= 10.13.0"
},
"jest": {
"testEnvironment": "node"
}
}
const nock = require("nock");
// Requiring our app implementation
const myProbotApp = require("..");
const { Probot, ProbotOctokit } = require("probot");
// Requiring our fixtures
const payload = require("./fixtures/issues.opened");
const issueCreatedBody = { body: "Thanks for opening this issue!" };
const fs = require("fs");
const path = require("path");
import fs from 'fs';
import path from 'path';
const privateKey = fs.readFileSync(
path.join(__dirname, "fixtures/mock-cert.pem"),
"utf-8"
);
import nock from 'nock';
import { Probot, ProbotOctokit } from 'probot';
import { assert } from 'chai';
describe("My Probot app", () => {
import myProbotApp from '..';
import payload from './fixtures/issues.opened';
describe('Substrate tip bot', () => {
let probot;
const issueCreatedBody = { body: 'Thanks for opening this issue!' };
const privateKey = fs.readFileSync(
path.join(__dirname, 'fixtures/mock-cert.pem'),
'utf-8'
);
beforeEach(() => {
nock.disableNetConnect();
probot = new Probot({
appId: 123,
privateKey,
......@@ -27,42 +29,36 @@ describe("My Probot app", () => {
throttle: { enabled: false },
}),
});
// Load our app into probot
probot.load(myProbotApp);
});
test("creates a comment when an issue is opened", async () => {
const mock = nock("https://api.github.com")
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
it('creates a comment when an issue is opened', async () => {
const mock = nock('https://api.github.com')
// Test that we correctly return a test token
.post("/app/installations/2/access_tokens")
.post('/app/installations/2/access_tokens')
.reply(200, {
token: "test",
token: 'test',
permissions: {
issues: "write",
issues: 'write',
},
})
// Test that a comment is posted
.post("/repos/hiimbex/testing-things/issues/1/comments", (body) => {
.post('/repos/hiimbex/testing-things/issues/1/comments', (body) => {
expect(body).toMatchObject(issueCreatedBody);
return true;
})
.reply(200);
// Receive a webhook event
await probot.receive({ name: "issues", payload });
expect(mock.pendingMocks()).toStrictEqual([]);
});
await probot.receive({ name: 'issues', payload });
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
assert.strictEqual(mock.pendingMocks(), []);
});
});
// For more information about testing with Jest see:
// https://facebook.github.io/jest/
// For more information about testing with Nock see:
// https://github.com/nock/nock
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment