Skip to content

Commit

Permalink
Add initial eslint setup (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
BSKY authored and Josh Gross committed Nov 12, 2019
1 parent 3150825 commit fb50aa4
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 91 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": { "node": true, "jest": true },
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 2020, "sourceType": "module" },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"plugins": ["@typescript-eslint", "jest"]
}
12 changes: 10 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Tests

on:
pull_request:
branches:
Expand All @@ -14,22 +15,29 @@ on:
jobs:
test:
name: Test on ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1

- uses: actions/setup-node@v1
with:
node-version: '12.x'

- run: npm ci

- name: Prettier Format Check
if: matrix.os == 'ubuntu-latest'
run: npm run format-check

- name: ESLint Check
if: matrix.os == 'ubuntu-latest'
run: npm run lint

- name: Build & Test
run: npm run test
12 changes: 5 additions & 7 deletions __tests__/restore.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as io from "@actions/io";

import * as path from "path";

import * as cacheHttpClient from "../src/cacheHttpClient";
import { Inputs } from "../src/constants";
import { ArtifactCacheEntry } from "../src/contracts";
Expand Down Expand Up @@ -107,7 +105,7 @@ test("restore with no cache found", async () => {
const stateMock = jest.spyOn(core, "saveState");

const clientMock = jest.spyOn(cacheHttpClient, "getCacheEntry");
clientMock.mockImplementation(_ => {
clientMock.mockImplementation(() => {
return Promise.resolve(null);
});

Expand All @@ -134,7 +132,7 @@ test("restore with server error should fail", async () => {
const stateMock = jest.spyOn(core, "saveState");

const clientMock = jest.spyOn(cacheHttpClient, "getCacheEntry");
clientMock.mockImplementation(_ => {
clientMock.mockImplementation(() => {
throw new Error("HTTP Error Occurred");
});

Expand Down Expand Up @@ -168,7 +166,7 @@ test("restore with restore keys and no cache found", async () => {
const stateMock = jest.spyOn(core, "saveState");

const clientMock = jest.spyOn(cacheHttpClient, "getCacheEntry");
clientMock.mockImplementation(_ => {
clientMock.mockImplementation(() => {
return Promise.resolve(null);
});

Expand Down Expand Up @@ -202,7 +200,7 @@ test("restore with cache found", async () => {
archiveLocation: "www.actionscache.test/download"
};
const getCacheMock = jest.spyOn(cacheHttpClient, "getCacheEntry");
getCacheMock.mockImplementation(_ => {
getCacheMock.mockImplementation(() => {
return Promise.resolve(cacheEntry);
});
const tempPath = "/foo/bar";
Expand Down Expand Up @@ -278,7 +276,7 @@ test("restore with cache found for restore key", async () => {
archiveLocation: "www.actionscache.test/download"
};
const getCacheMock = jest.spyOn(cacheHttpClient, "getCacheEntry");
getCacheMock.mockImplementation(_ => {
getCacheMock.mockImplementation(() => {
return Promise.resolve(cacheEntry);
});
const tempPath = "/foo/bar";
Expand Down
37 changes: 19 additions & 18 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
require('nock').disableNetConnect();
require("nock").disableNetConnect();

module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
clearMocks: true,
moduleFileExtensions: ["js", "ts"],
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
testRunner: "jest-circus/runner",
transform: {
"^.+\\.ts$": "ts-jest"
},
verbose: true
};

const processStdoutWrite = process.stdout.write.bind(process.stdout)
const processStdoutWrite = process.stdout.write.bind(process.stdout);
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
process.stdout.write = (str, encoding, cb) => {
// Core library will directly call process.stdout.write for commands
// We don't want :: commands to be executed by the runner during tests
if (!str.match(/^::/)) {
return processStdoutWrite(str, encoding, cb);
}
}
// Core library will directly call process.stdout.write for commands
// We don't want :: commands to be executed by the runner during tests
if (!str.match(/^::/)) {
return processStdoutWrite(str, encoding, cb);
}
};
Loading

0 comments on commit fb50aa4

Please sign in to comment.