-
Notifications
You must be signed in to change notification settings - Fork 854
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
145 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist/* | ||
test/pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "---http-proxy-middleware--pkg---", | ||
"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" | ||
} | ||
} |