Skip to content

Commit

Permalink
ci(package.json): use make
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed May 19, 2021
1 parent 6fd75f7 commit e1d52d6
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ trim_trailing_whitespace = false
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_size = 2

[Makefile]
indent_style = tab
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/*
test/pkg/*
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ jobs:
if: steps.yarn-cache.outputs.cache-hit != 'true' # Over here!
run: yarn install --frozen-lockfile --ignore-scripts

- name: yarn test
run: yarn test
- name: make test-jest
run: make test-jest

- name: make test-pkg
run: make test-pkg

env:
CI: true
Expand Down
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SHELL = /bin/sh

YARN = yarn
PRETTIER = $(YARN) prettier
ESLINT = $(YARN) eslint
JEST = $(YARN) test
TOUCH = touch

ARTIFACTS = dist coverage
SRC_TS := $(wildcard ./src/*.ts)
ESLINT_GLOB = "{src,test}/**/*.ts"
PRETTIER_GLOB = "**/*.{js,ts,md,yml,json,html}"

.DEFAULT_TARGET = all

.PHONY: clean coverage build lint lint-fix production test

all: production

install: node_modules

node_modules: yarn.lock
$(YARN) install
$(TOUCH) $@

production: install clean build
rm dist/tsconfig.tsbuildinfo

clean:
rm -rf $(ARTIFACTS)

build: dist

dist: $(SRC_TS)
$(YARN) tsc
$(TOUCH) $@

lint:
$(ESLINT) $(ESLINT_GLOB)
$(PRETTIER) --list-different $(PRETTIER_GLOB)

lint-fix:
$(ESLINT) --fix $(ESLINT_GLOB)
$(PRETTIER) --write $(PRETTIER_GLOB)

test-jest: clean build
$(JEST)

test-pkg:
(cd ./test/pkg && make clean install test)

coverage: clean build
$(JEST) --coverage --coverageReporters=lcov
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,10 @@ $ yarn lint:fix
$ yarn build

# unit tests
$ yarn test
$ yarn build && yarn test

# code coverage
$ yarn cover
$ yarn build && yarn coverage
```

## Changelog
Expand Down
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
"dist"
],
"scripts": {
"clean": "rm -rf dist && rm -rf coverage",
"lint": "yarn prettier && yarn eslint",
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
"eslint": "eslint '{src,test}/**/*.ts'",
"eslint:fix": "yarn eslint --fix",
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
"prebuild": "yarn clean",
"clean": "make clean",
"lint": "make lint",
"lint:fix": "make lint-fix",
"build": "tsc",
"pretest": "yarn build",
"test": "jest",
"precoverage": "yarn build",
"coverage": "jest --coverage --coverageReporters=lcov",
"prepare": "husky install && yarn build && rm dist/tsconfig.tsbuildinfo"
"coverage": "make coverage",
"prepare": "husky install",
"prepack": "make production"
},
"repository": {
"type": "git",
Expand Down
13 changes: 13 additions & 0 deletions test/pkg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: clean install test

clean:
rm -rf node_modules http-proxy-middleware.tgz

install:
(cd ../.. && make install)
(cd ../.. && npm pack)
(mv ../../http-proxy-middleware-*.tgz ./http-proxy-middleware.tgz)
yarn install

test:
yarn test
14 changes: 14 additions & 0 deletions test/pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Why this test is needed

Testing purely with TypeScript doesn't cover this issue: https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this

https://github.com/chimurai/http-proxy-middleware/blob/c935888ea7135365bea3c4c81e4ffe48f359a670/src/http-proxy-middleware.ts#L45-L46

## npm package test

```shell
make clean install test
```

Create `http-proxy-middleware.tgz` package; install and test it locally with a simple use-case to
test for the TypeScript red-flag issue.
18 changes: 18 additions & 0 deletions test/pkg/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// file deepcode ignore DisablePoweredBy: testing purpose only
// file deepcode ignore UseCsurfForExpress: testing purpose only

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

app.use(
createProxyMiddleware({
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true,
})
);

module.exports = {
app,
};
14 changes: 14 additions & 0 deletions test/pkg/app.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const request = require('supertest');
const { app } = require('./app');

describe('package: http-proxy-middleware', () => {
let agent;

beforeEach(() => {
agent = request(app);
});

it('should proxy /users', async () => {
return agent.get(`/users`).expect(200);
});
});
3 changes: 3 additions & 0 deletions test/pkg/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: 'node',
};
14 changes: 14 additions & 0 deletions test/pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "dist",
"private": "true",
"description": "http-proxy-middleware package test",
"main": "index.js",
"scripts": {
"test": "jest"
},
"dependencies": {
"express": "^4.17.1",
"http-proxy-middleware": "file:http-proxy-middleware.tgz",
"jest": "^26.6.3"
}
}

0 comments on commit e1d52d6

Please sign in to comment.