Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade packages & deprecate node 8 and below #4

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tmp
node_modules/
.git
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "groupon",
"overrides": [
{
"files": "*.test.js",
"env": {
"mocha": true
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.nyc_output
node_modules/
/tmp
npm-debug.log
Expand Down
21 changes: 8 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
language: node_js
node_js:
- '0.10'
- '4'
before_install:
- npm install -g npm@latest-2
before_deploy:
- 'git config --global user.email "opensource@groupon.com"'
- 'git config --global user.name "Groupon"'
- 10
- 12
deploy:
provider: script
script: ./node_modules/.bin/nlm release
skip_cleanup: true
'on':
branch: master
node: '4'
- provider: script
script: npx nlm release
skip_cleanup: true
'on':
branch: master
node: 12
40 changes: 23 additions & 17 deletions lib/testium-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var _ = require('lodash');
var debug = require('debug')('testium-cookie');
const debug = require('debug')('testium-cookie');

function encode(string) {
return new Buffer(string).toString('base64');
function encode(value) {
return Buffer.from(value).toString('base64');
}

function decode(value) {
return new Buffer(value, 'base64').toString('utf8');
return Buffer.from(value, 'base64').toString('utf8');
}

function encodeMetaData(headers, statusCode) {
var jsonData = JSON.stringify({
headers: headers,
statusCode: statusCode,
const jsonData = JSON.stringify({
headers,
statusCode,
});
var encodedData = encode(jsonData);
return encodedData;

return encode(jsonData);
}
exports.encodeMetaData = encodeMetaData;

function buildCookie(headers, statusCode) {
return '_testium_=' + encodeMetaData(headers, statusCode) + '; path=/';
return `_testium_=${encodeMetaData(headers, statusCode)}; path=/`;
}

function modifyResponse(response) {
var headers = response.headers = response.headers || {};
const headers = (response.headers = response.headers || {});

// This relies on the fact that the existing headers are all lower-cased
headers['Set-Cookie'] = buildCookie(headers, response.statusCode);
Expand All @@ -84,24 +84,30 @@ function tryParse(jsonString) {
return JSON.parse(jsonString);
} catch (error) {
error.message = [
'Unable to parse JSON: ' + error.message,
'Attempted to parse: ' + jsonString,
`Unable to parse JSON: ${error.message}`,
`Attempted to parse: ${jsonString}`,
].join('\n');
throw error;
}
}

function parseTestiumCookie(cookie) {
var json = decode(typeof cookie === 'string' ? cookie : cookie.value);
const json = decode(typeof cookie === 'string' ? cookie : cookie.value);
return tryParse(json);
}

function getTestiumCookie(cookies) {
// Gracefully handles the result of cookie.parse and an array of cookie objects
var testiumCookie = cookies._testium_ || _.find(cookies, { name: '_testium_' });
const testiumCookie =
// eslint-disable-next-line no-underscore-dangle
cookies._testium_ ||
(Array.isArray(cookies) &&
cookies.find(({ name }) => name === '_testium_'));

if (!testiumCookie) {
throw new Error('Unable to communicate with internal proxy. Make sure you are using relative paths.');
throw new Error(
'Unable to communicate with internal proxy. Make sure you are using relative paths.'
);
}

return parseTestiumCookie(testiumCookie);
Expand Down
Loading