MCPcopy
hub / github.com/alibaba/anyproxy / testWrapper

Function testWrapper

test/spec_rule/rule_replace_response_data_spec.js:15–87  ·  view source on GitHub ↗
(protocol)

Source from the content-addressed store, hash-verified

13testWrapper('https');
14
15function testWrapper(protocol) {
16 describe('Rule replaceResponseData should be working in :' + protocol, () => {
17 let proxyServer;
18 let serverInstance;
19
20 beforeAll((done) => {
21 jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
22 printLog('Start server for rule_replace_response_data');
23
24 serverInstance = new Server();
25
26 proxyServer = ProxyServerUtil.proxyServerWithRule(rule);
27
28 setTimeout(() => {
29 done();
30 }, 2000);
31 });
32
33 afterAll(() => {
34 serverInstance && serverInstance.close();
35 proxyServer && proxyServer.close();
36 printLog('Close server for rule_replace_response_data');
37 });
38
39 it('Should replace the header in proxy if assertion is true', done => {
40 const url = generateUrl(protocol, '/test/normal_request1');
41 proxyGet(url)
42 .then(proxyRes => {
43 expect(proxyRes.statusCode).toEqual(200);
44 expect(proxyRes.body).toEqual('body_normal_request1_hello_world!');
45
46 directGet(url)
47 .then(directRes => {
48 expect(directRes.statusCode).toEqual(200);
49 expect(directRes.body).toEqual('body_normal_request1');
50 done();
51 })
52 .catch(error => {
53 console.error('error happened in direct get: ', error);
54 done.fail('error happened in direct get');
55 });
56 })
57 .catch(error => {
58 console.error('error happened in proxy get: ', error);
59 done.fail('error happened in proxy get');
60 });
61 });
62
63 it('Should not replace the header in proxy if assertion is false', done => {
64 const url = generateUrl(protocol, '/test/normal_request2');
65 proxyGet(url)
66 .then(proxyRes => {
67 expect(proxyRes.statusCode).toEqual(200);
68 expect(proxyRes.body).toEqual('body_normal_request2');
69
70 directGet(url)
71 .then(directRes => {
72 expect(directRes.statusCode).toEqual(200);

Calls 5

generateUrlFunction · 0.85
proxyGetFunction · 0.85
directGetFunction · 0.85
printLogFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected