Skip to content

Commit

Permalink
Merge pull request #4 from testiumjs/updates
Browse files Browse the repository at this point in the history
chore: upgrade packages & deprecate node 8 and below
  • Loading branch information
aaarichter authored Mar 26, 2020
2 parents 0ace734 + 8a2a961 commit 7e4e665
Show file tree
Hide file tree
Showing 13 changed files with 3,985 additions and 126 deletions.
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 "[email protected]"'
- '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

0 comments on commit 7e4e665

Please sign in to comment.