Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
fix: builds gavel using rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Jul 18, 2019
1 parent 93aa5f9 commit ea5b7bf
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ cov.*
.nyc_output

# List specific to .gitignore
build
node_modules
.idea/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cov.*
# List specific to .npmignore
.travis.yml
.npmignore
lib
docs/
img/
test/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install:
- 'npm install --no-save'
script:
- 'npm run ci:lint'
- 'npm run ci:build'
- 'npm run ci:test'
after_success:
- 'npm run ci:release'
15 changes: 8 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
environment:
nodejs_version: "10"
nodejs_version: '10'
cache:
- "node_modules"
- 'node_modules'
install:
- ps: Install-Product node 10
- "npm -g install npm@6"
- 'npm -g install npm@6'
- "set PATH=%APPDATA%\\npm;%PATH%"
- "npm install"
- 'npm install'
build: off
test_script:
- "node --version"
- "npm --version"
- "npm test"
- 'node --version'
- 'npm --version'
- 'npm run build'
- 'npm test'
1 change: 1 addition & 0 deletions lib/units/validateBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function getBodyType(body, contentType, httpMessageOrigin) {
const hasJsonContentType = isJsonContentType(contentType);

try {
// jph.parse(body);
parseJson(body);
const bodyMediaType = parseContentType(
hasJsonContentType ? contentType : 'application/json'
Expand Down
128 changes: 128 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"name": "gavel",
"version": "0.0.0-semantically-released",
"description": "Validator of HTTP transactions (JavaScript implementation)",
"main": "lib/index.js",
"main": "build/index.js",
"engines": {
"node": ">= 8"
},
"bin": {
"gavel": "bin/gavel"
},
"scripts": {
"start": "npm run build -- --watch",
"build": "rollup -c=rollup.config.js",
"lint": "eslint lib/**/*.js test/**/*.js",
"test": "npm run test:server && npm run test:browser && npm run test:features",
"test:server": "mocha \"test/**/*.test.js\"",
Expand All @@ -19,6 +21,7 @@
"coveralls": "nyc --reporter=text-lcov npm run test:server | coveralls",
"ci:lint": "npm run lint",
"ci:test": "npm run coveralls && npm run test:browser && npm run test:features",
"ci:build": "npm run build",
"ci:release": "semantic-release"
},
"husky": {
Expand Down
26 changes: 26 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const packageJson = require('./package.json');

const buildUmd = {
input: 'lib/index.js',
output: {
file: packageJson.main,
format: 'umd',
name: 'gavel',
exports: 'named',
sourcemap: true
},
plugins: [
resolve({
browser: true,

// Forbid bundling of NodeJS built-ins (i.e. "fs", "path").
// Throw when such modules are present in the bundle.
preferBuiltins: false
}),
commonjs()
]
};

module.exports = [buildUmd];
49 changes: 20 additions & 29 deletions test/cucumber/support/world.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
/* eslint-disable */
const vm = require('vm');
const util = require('util');
const { assert } = require('chai');
const { exec } = require('child_process');
const gavel = require('../../../lib');
const gavel = require('../../../build');

const HTTP_LINE_DELIMITER = '\n';

Expand All @@ -28,12 +19,10 @@ class World {

executeCommands(commands) {
const commandsBuffer = commands.join(';');
const cmd =
`PATH=$PATH:${process.cwd()}/bin:${process.cwd()}/node_modules/.bin; cd /tmp/gavel-* ;` +
commandsBuffer;
const cmd = `PATH=$PATH:${process.cwd()}/bin:${process.cwd()}/node_modules/.bin; cd /tmp/gavel-* ;${commandsBuffer}`;

return new Promise((resolve) => {
const child = exec(cmd, function(error, stdout, stderr) {
const child = exec(cmd, function(error) {
if (error) {
resolve(error.code);
}
Expand Down Expand Up @@ -78,7 +67,8 @@ Make sure it's in the "Header-Name: value" format.
`
);

const [_, key, value] = match;
const key = match[1];
const value = match[2];

return Object.assign({}, acc, {
[key.toLowerCase()]: value.trim()
Expand Down Expand Up @@ -117,17 +107,17 @@ Make sure it's in the "Header-Name: value" format.
const headersLines = [];
let bodyEntered = false;

for (let line of Array.from(lines)) {
/* eslint-disable no-restricted-syntax */
for (const line of Array.from(lines)) {
if (line === '') {
bodyEntered = true;
} else if (bodyEntered) {
bodyLines.push(line);
} else {
if (bodyEntered) {
bodyLines.push(line);
} else {
headersLines.push(line);
}
headersLines.push(line);
}
}
/* eslint-enable no-restricted-syntax */

parsed.headers = this.parseHeaders(headersLines.join(HTTP_LINE_DELIMITER));
parsed.body = bodyLines.join(HTTP_LINE_DELIMITER);
Expand All @@ -154,20 +144,21 @@ Make sure it's in the "Header-Name: value" format.
}

toPascalCase(string) {
let result = string.replace(
/(\w)(\w*)/g,
(g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase()
);
return (result = result.replace(' ', ''));
return string
.replace(
/(\w)(\w*)/g,
(g0, g1, g2) => g1.toUpperCase() + g2.toLowerCase()
)
.replace(' ', '');
}

// Debugging helper
inspect(data) {
if (data !== null && typeof data === 'object') {
return JSON.stringify(data, null, 2);
} else {
return data;
}

return data;
}

// Debugging helper
Expand All @@ -177,5 +168,5 @@ Make sure it's in the "Header-Name: value" format.
}

module.exports = function() {
return (this.World = World);
this.World = World;
};

0 comments on commit ea5b7bf

Please sign in to comment.