Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

end-to-end.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Use this tests for troubleshooting, you'll need a proxy runnig at an endpoint
  2. // The idea is to make sure the tests pass if the proxy is turned on, that means the requests are resolving
  3. // And also the tests should fail if the proxy is turned off, that means the requests are actually being proxied
  4. const globalTunnel = require('../index');
  5. const assert = require('chai').assert;
  6. const request = require('request');
  7. const http = require('http');
  8. const https = require('https');
  9. // You need to have a proxy running at the Proxy URL.
  10. const proxyUrl = 'http://localhost:8080';
  11. const resourceUrl = 'www.google.com';
  12. describe.skip('end-to-end tests', () => {
  13. beforeEach(() => {
  14. globalTunnel.initialize(proxyUrl);
  15. });
  16. const httpResourceUrl = (secure = false) => `http${secure ? 's' : ''}://${resourceUrl}`;
  17. const testHttp = (httpMethod = 'request') => (secure = false) => () =>
  18. new Promise((resolve, reject) => {
  19. const request = (secure ? https : http)[httpMethod](
  20. httpResourceUrl(secure),
  21. response => {
  22. assert.isAtLeast(response.statusCode, 200);
  23. assert.isBelow(response.statusCode, 300);
  24. let buffer = Buffer.alloc(0);
  25. response.on('data', chunk => {
  26. buffer = Buffer.concat([buffer, chunk]);
  27. });
  28. response.on('end', () => {
  29. assert.isNotEmpty(buffer.toString());
  30. resolve();
  31. });
  32. }
  33. );
  34. request.on('error', reject);
  35. if (httpMethod === 'request') {
  36. request.end();
  37. }
  38. });
  39. const testHttpRequest = testHttp();
  40. const testHttpGet = testHttp('get');
  41. it('proxies http.get', testHttpGet());
  42. it('proxies https.get', testHttpGet(true));
  43. it('proxies http.request', testHttpRequest());
  44. it('proxies https.request', testHttpRequest(true));
  45. it('proxies request', () =>
  46. new Promise((resolve, reject) => {
  47. request.get({ url: httpResourceUrl(true) }, err => {
  48. if (err) {
  49. reject(err);
  50. } else {
  51. resolve();
  52. }
  53. });
  54. }));
  55. afterEach(() => {
  56. globalTunnel.end();
  57. });
  58. });