Skip to content

Commit

Permalink
feat: Convert recordings to be HAR compliant (#45)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Recordings now produce HAR compliant json. Please delete existing recordings.
  • Loading branch information
offirgolan authored Jul 1, 2018
1 parent 0b47838 commit e622640
Show file tree
Hide file tree
Showing 51 changed files with 1,675 additions and 672 deletions.
75 changes: 57 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,74 @@ describe('Netflix Homepage', function() {
});
```

The above test case would generate the following recording which Polly will use to replay the sign-in request/response when the test is rerun:
The above test case would generate the following recording HAR which Polly will use to replay the sign-in request/response when the test is rerun:

```json
{
"created_at": "2018-06-01T20:36:46.198Z",
"entries": {
"1077f062f8b12b51733933f86fb7ebc4": [
"log": {
"_recordingName": "Sign In",
"browser": {
"name": "Chrome",
"version": "67.0"
},
"creator": {
"name": "Polly.JS",
"version": "0.5.0"
},
"entries": [
{
"created_at": "2018-06-01T20:36:46.198Z",
"_id": "06f06e6d125cbb80896c41786f9a696a",
"_order": 0,
"cache": {},
"request": {
"body": "{\"email\":\"[email protected]\",\"password\":\"@pollyjs\"}",
"headers": {
"Content-Type": "application/json;charset=utf-8"
},
"bodySize": 51,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"headersSize": 97,
"httpVersion": "HTTP/1.1",
"method": "POST",
"timestamp": "2018-06-01T20:36:46.070Z",
"url": "/api/v1/login"
"postData": {
"mimeType": "application/json; charset=utf-8",
"text": "{\"email\":\"[email protected]\",\"password\":\"@pollyjs\"}"
},
"queryString": [],
"url": "https://netflix.com/api/v1/login"
},
"response": {
"body": "",
"headers": {},
"bodySize": 0,
"content": {
"mimeType": "text/plain; charset=utf-8",
"size": 0
},
"cookies": [],
"headers": [],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"timestamp": "2018-06-01T20:36:46.119Z"
"statusText": "OK"
},
"startedDateTime": "2018-06-29T17:31:55.348Z",
"time": 11,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 11
}
}
]
},
"name": "Sign In",
"schema_version": 0.1
],
"pages": [],
"version": "1.2"
}
}
```

Expand Down
23 changes: 17 additions & 6 deletions build-scripts/rollup.browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import deepmerge from 'deepmerge';
import alias from 'rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import { rollup as lerna } from 'lerna-alias';
import resolve from 'rollup-plugin-node-resolve';
import globals from 'rollup-plugin-node-globals';
import builtins from 'rollup-plugin-node-builtins';
import createCommonConfig, { output, pkg } from './rollup.common.config';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
import json from 'rollup-plugin-json';
import { input, output, pkg, production } from './rollup.utils';

export default function createClientConfig(options = {}, targets) {
export default function createBrowserConfig(options = {}, targets) {
return deepmerge(
createCommonConfig({
{
input,
output: deepmerge(output('umd'), { name: pkg.name }),
plugins: [
alias(lerna()),
builtins(),
json(),
resolve({ browser: true }),
commonjs(),
babel({
babelrc: false,
runtimeHelpers: true,
Expand All @@ -33,7 +41,10 @@ export default function createClientConfig(options = {}, targets) {
],
exclude: ['node_modules/**'],
ignore: 'node_modules/**'
})
}),
globals(),
builtins(),
production && uglify()
],
onwarn(message) {
/* nise uses eval for strings within native fns setTimeout('alert("foo")', 10) */
Expand All @@ -43,7 +54,7 @@ export default function createClientConfig(options = {}, targets) {

console.error(message);
}
}),
},
options
);
}
16 changes: 4 additions & 12 deletions build-scripts/rollup.browser.test.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import deepmerge from 'deepmerge';
import multiEntry from 'rollup-plugin-multi-entry';
import createClientConfig from './rollup.browser.config';
import { pkg } from './rollup.common.config';
import createBrowserConfig from './rollup.browser.config';
import { pkg } from './rollup.utils';

export default function createClientTestConfig(options = {}) {
return deepmerge(
createClientConfig(
createBrowserConfig(
{
input: 'tests/**/*-test.js',
output: {
Expand All @@ -18,15 +18,7 @@ export default function createClientTestConfig(options = {}) {
`,
outro: '});'
},
plugins: [multiEntry()],
onwarn(warning) {
if (
warning.code !== 'CIRCULAR_DEPENDENCY' &&
!(/nise/.test(warning) && /eval/.test(warning))
) {
console.error(`(!) ${warning.message}`);
}
}
plugins: [multiEntry()]
},
/* target override */
{
Expand Down
47 changes: 0 additions & 47 deletions build-scripts/rollup.common.config.js

This file was deleted.

21 changes: 15 additions & 6 deletions build-scripts/rollup.node.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import createConfig, { output, pkg } from './rollup.common.config';
import babel from 'rollup-plugin-babel';
import deepmerge from 'deepmerge';
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';
import json from 'rollup-plugin-json';
import { input, output, pkg, production } from './rollup.utils';

const external = Object.keys(pkg.dependencies || {});

export default function createServerConfig(options = {}) {
export default function createNodeConfig(options = {}) {
return deepmerge(
createConfig({
{
input,
output: [output('cjs'), output('es')],
external,
plugins: [
json(),
resolve(),
commonjs(),
babel({
babelrc: false,
runtimeHelpers: true,
Expand All @@ -31,9 +39,10 @@ export default function createServerConfig(options = {}) {
],
exclude: ['node_modules/**'],
ignore: 'node_modules/**'
})
}),
production && uglify()
]
}),
},
options
);
}
26 changes: 26 additions & 0 deletions build-scripts/rollup.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* globals require process */

import path from 'path';

export const pkg = require(path.resolve(process.cwd(), './package.json'));
export const production = process.env.NODE_ENV === 'production';
export const input = './src/index.js';

const banner = `/**
* ${pkg.name} v${pkg.version}
*
* https://github.com/netflix/pollyjs
*
* Released under the ${pkg.license} License.
*/`;

export const output = format => {
return {
format,
file: `./dist/${format}/${pkg.name.replace('@pollyjs/', 'pollyjs-')}.${
production ? 'min.js' : 'js'
}`,
sourcemap: production,
banner
};
};
77 changes: 58 additions & 19 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,75 @@ describe('Netflix Homepage', function() {
});
```

The above test case would generate the following recording which Polly will use
to replay the sign-in request/response when the test is rerun:
The above test case would generate the following recording HAR which Polly will
use to replay the sign-in request/response when the test is rerun:

```json
{
"created_at": "2018-06-01T20:36:46.198Z",
"entries": {
"1077f062f8b12b51733933f86fb7ebc4": [
"log": {
"_recordingName": "Sign In",
"browser": {
"name": "Chrome",
"version": "67.0"
},
"creator": {
"name": "Polly.JS",
"version": "0.5.0"
},
"entries": [
{
"created_at": "2018-06-01T20:36:46.198Z",
"_id": "06f06e6d125cbb80896c41786f9a696a",
"_order": 0,
"cache": {},
"request": {
"body": "{\"email\":\"[email protected]\",\"password\":\"@pollyjs\"}",
"headers": {
"Content-Type": "application/json;charset=utf-8"
},
"bodySize": 51,
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"headersSize": 97,
"httpVersion": "HTTP/1.1",
"method": "POST",
"timestamp": "2018-06-01T20:36:46.070Z",
"url": "/api/v1/login"
"postData": {
"mimeType": "application/json; charset=utf-8",
"text": "{\"email\":\"[email protected]\",\"password\":\"@pollyjs\"}"
},
"queryString": [],
"url": "https://netflix.com/api/v1/login"
},
"response": {
"body": "",
"headers": {},
"bodySize": 0,
"content": {
"mimeType": "text/plain; charset=utf-8",
"size": 0
},
"cookies": [],
"headers": [],
"headersSize": 0,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"timestamp": "2018-06-01T20:36:46.119Z"
"statusText": "OK"
},
"startedDateTime": "2018-06-29T17:31:55.348Z",
"time": 11,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 11
}
}
]
},
"name": "Sign In",
"schema_version": 0.1
],
"pages": [],
"version": "1.2"
}
}
```

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-multi-entry": "^2.0.2",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.2.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-uglify": "^3.0.0",
"start-server-and-test": "^1.4.1",
Expand Down
Loading

0 comments on commit e622640

Please sign in to comment.