Skip to content

Commit fdc2c14

Browse files
committed
ci(package.json): use make
1 parent 6fd75f7 commit fdc2c14

13 files changed

+155
-16
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ trim_trailing_whitespace = false
1616
# Matches the exact files either package.json or .travis.yml
1717
[{package.json,.travis.yml}]
1818
indent_size = 2
19+
20+
[Makefile]
21+
indent_style = tab

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dist/*
2+
test/pkg/*

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ jobs:
5959
if: steps.yarn-cache.outputs.cache-hit != 'true' # Over here!
6060
run: yarn install --frozen-lockfile --ignore-scripts
6161

62-
- name: yarn test
63-
run: yarn test
62+
- name: make test
63+
run: make test
6464

6565
env:
6666
CI: true

Makefile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
SHELL = /bin/sh
2+
3+
YARN = yarn
4+
PRETTIER = $(YARN) prettier
5+
ESLINT = $(YARN) eslint
6+
JEST = $(YARN) test
7+
TOUCH = touch
8+
9+
ARTIFACTS = dist coverage
10+
SRC_TS := $(wildcard ./src/*.ts)
11+
ESLINT_GLOB = "{src,test}/**/*.ts"
12+
PRETTIER_GLOB = "**/*.{js,ts,md,yml,json,html}"
13+
14+
.DEFAULT_TARGET = all
15+
16+
.PHONY: clean coverage build lint lint-fix production test
17+
18+
all: production
19+
20+
install: node_modules
21+
22+
node_modules: yarn.lock
23+
$(YARN) install
24+
$(TOUCH) $@
25+
26+
production: install clean build
27+
rm dist/tsconfig.tsbuildinfo
28+
29+
clean:
30+
rm -rf $(ARTIFACTS)
31+
32+
build: dist
33+
34+
dist: $(SRC_TS)
35+
$(YARN) tsc
36+
$(TOUCH) $@
37+
38+
lint:
39+
$(ESLINT) $(ESLINT_GLOB)
40+
$(PRETTIER) --list-different $(PRETTIER_GLOB)
41+
42+
lint-fix:
43+
$(ESLINT) --fix $(ESLINT_GLOB)
44+
$(PRETTIER) --write $(PRETTIER_GLOB)
45+
46+
test: test-unit test-pkg
47+
48+
test-unit:
49+
$(JEST)
50+
51+
test-pkg:
52+
(cd ./test/pkg && make clean install test)
53+
54+
coverage: clean build
55+
$(JEST) --coverage --coverageReporters=lcov

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ $ yarn lint:fix
582582
$ yarn build
583583

584584
# unit tests
585-
$ yarn test
585+
$ yarn build && yarn test
586586

587587
# code coverage
588-
$ yarn cover
588+
$ yarn build && yarn coverage
589589
```
590590

591591
## Changelog

package.json

+6-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@
88
"dist"
99
],
1010
"scripts": {
11-
"clean": "rm -rf dist && rm -rf coverage",
12-
"lint": "yarn prettier && yarn eslint",
13-
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
14-
"eslint": "eslint '{src,test}/**/*.ts'",
15-
"eslint:fix": "yarn eslint --fix",
16-
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
17-
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
18-
"prebuild": "yarn clean",
11+
"clean": "make clean",
12+
"lint": "make lint",
13+
"lint:fix": "make lint-fix",
1914
"build": "tsc",
20-
"pretest": "yarn build",
2115
"test": "jest",
22-
"precoverage": "yarn build",
23-
"coverage": "jest --coverage --coverageReporters=lcov",
24-
"prepare": "husky install && yarn build && rm dist/tsconfig.tsbuildinfo"
16+
"coverage": "make coverage",
17+
"prepare": "husky install",
18+
"prepack": "make production"
2519
},
2620
"repository": {
2721
"type": "git",

test.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
FILES="
4+
package.json
5+
yarn.lock
6+
node_modules/acorn/package.json
7+
"
8+
9+
# calculate md5 of individual files and concat different hashes into 1 string
10+
MD5_CONCAT=$(echo $FILES | xargs md5)
11+
12+
# calculate md5 of all $FILES combined
13+
MD5_ALL=$(echo $MD5_CONCAT | md5)
14+
15+
echo $MD5_ALL

test/pkg/Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: clean install test
2+
3+
clean:
4+
rm -rf node_modules http-proxy-middleware.tgz
5+
6+
install:
7+
(cd ../.. && make install)
8+
(cd ../.. && npm pack)
9+
(mv ../../http-proxy-middleware-*.tgz ./http-proxy-middleware.tgz)
10+
npm install ./http-proxy-middleware.tgz --no-package-lock
11+
12+
test:
13+
npm test

test/pkg/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Why this test is needed
2+
3+
Testing purely with TypeScript doesn't cover this issue: https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript#red-flags-for-this
4+
5+
https://github.com/chimurai/http-proxy-middleware/blob/c935888ea7135365bea3c4c81e4ffe48f359a670/src/http-proxy-middleware.ts#L45-L46
6+
7+
## npm package test
8+
9+
```shell
10+
make clean install test
11+
```
12+
13+
Create `http-proxy-middleware.tgz` package; install and test it locally with a simple use-case to
14+
test for the TypeScript red-flag issue.

test/pkg/app.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const express = require('express');
2+
const { createProxyMiddleware } = require('http-proxy-middleware');
3+
4+
const app = express();
5+
6+
app.use(
7+
createProxyMiddleware({
8+
target: 'https://jsonplaceholder.typicode.com',
9+
changeOrigin: true,
10+
})
11+
);
12+
13+
module.exports = {
14+
app,
15+
};

test/pkg/app.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const request = require('supertest');
2+
const { app } = require('./app');
3+
4+
describe('package: http-proxy-middleware', () => {
5+
let agent;
6+
7+
beforeEach(() => {
8+
agent = request(app);
9+
});
10+
11+
it('should proxy /users', async () => {
12+
return agent.get(`/users`).expect(200);
13+
});
14+
});

test/pkg/jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
};

test/pkg/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "dist",
3+
"private": "true",
4+
"description": "http-proxy-middleware package test",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"dependencies": {
10+
"http-proxy-middleware": "file:http-proxy-middleware.tgz"
11+
}
12+
}

0 commit comments

Comments
 (0)