Giter Site home page Giter Site logo

postman-local's Issues

Clean up sync.js

Clean up sync.js - some duplicate code/possibility for abstraction

Improve bundling

Bundling happens on a per request level meaning libraries may be imported multiple times.

`clone` improvements

  • also clone environment if present
  • check for existing collection/environment in workspace

Unhandled Promise rejection on setup when no environments exist.

I'm getting this error on postman setup when choosing to include environments when none actually exist in the workspace.

✔ Would you like to include Environment(s)? (y/N) · true
(node:31358) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
    at createChoices (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/lib/create-choices.js:2:14)
    at continueSetup (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/setup.js:70:32)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:31358) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:31358) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The error appears to be coming from here: https://github.com/matt-ball/postman-cli/blob/0fb32ef68060ac42a0bc77f67ece2dd947c51f94/src/setup.js#L70

When no environments exist, there actually is no data.workspace.environments field in the API response, so it's sending undefined to createChoices.

Built-in libraries from the Postman Sandbox aren't included when running postman sync.

When running postman sync from a bootstrapped collection, Browserify can't build the dependency graph if the Postman built-in modules haven't been npm install'd. Can these either be detected ahead of time and installed or can we optimistically install all built-in libraries from the Postman sandbox on the initial bootstrap?

➜ postman sync
(node:32473) UnhandledPromiseRejectionWarning: Error: Can't walk dependency graph: Cannot find module 'lodash' from '/private/tmp/postman-cli-test/postman/Utilities/Delay Response/test.js'
    required by /private/tmp/postman-cli-test/postman/Utilities/Delay Response/test.js
    at /usr/local/lib/node_modules/@matt.ball/postman-cli/node_modules/resolve/lib/async.js:115:35
    at processDirs (/usr/local/lib/node_modules/@matt.ball/postman-cli/node_modules/resolve/lib/async.js:268:39)
    at isdir (/usr/local/lib/node_modules/@matt.ball/postman-cli/node_modules/resolve/lib/async.js:275:32)
    at /usr/local/lib/node_modules/@matt.ball/postman-cli/node_modules/resolve/lib/async.js:25:69
    at FSReqCallback.oncomplete (fs.js:175:21)

Note: The workaround for this was just doing npm i lodash and moving forward.

postman env error when no environments have been defined

When running postman env against a postman account in which no environments have been defined, postman fails with the following error :

(node:2179) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'map' of undefined
at createChoices (/Users/myself/Workspace/postman-cli-sandbox/node_modules/@matt.ball/postman-cli/src/lib/create-choices.js:2:14)
at Command.env (/Users/myself/Workspace/postman-cli-sandbox/node_modules/@matt.ball/postman-cli/src/env.js:12:30)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2179) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2179) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It would be nice to catch this edge case, log a warning and exit gracefully.

postman-cli version : 0.0.26
node version : v12.16.1

Error when adding scripts to a request previously bootstrapped with none.

After adding a prerequest.js to a request directory locally, I received an error on postman sync.

➜ postman sync
(node:32815) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'findIndex' of undefined
    at mapFileToItem (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/sync.js:23:31)
    at recurseCollectionForItems (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/lib/recurse-collection.js:34:20)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async recurseCollectionForItems (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/lib/recurse-collection.js:40:7)
    at async recurseCollection (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/lib/recurse-collection.js:13:5)
    at async Command.sync (/usr/local/lib/node_modules/@matt.ball/postman-cli/src/sync.js:9:22)

The error is here: https://github.com/matt-ball/postman-cli/blob/cdaa51c05ffde6d68e8465df2d6e30d6e4b0b7ab/src/sync.js#L23

In this case, req.event does not exist and needs to be created.

Issues when syncing the changes

Steps to reproduce :

  1. create collection with a request with a simple console.log('bla bla') in pre-request script and test script
  2. run pm setup (with default options for directory and filenames)
  3. run pm bootstrap
  4. access pre-request and test script of one of the request and change the string in the console.log()
  5. run pm sync command (the collection file is created succers
  6. run pm update ( Postman updated! message displayed)
  7. go to Postman GUI and open pre-request script of the request

Current behavior :
image

Expected behavior :

Find the change I made on prerequest.js in pre-request script in Postman GUI

Environment :
Windows 10
postman-cli : v7.20.1
node : v10.16.2
npm : 6.9.0
VS Code : 1.43.1

Do not hesitate if you need more details to reproduce/fix the issue

Enable 2-way sync

It would be nice if we could make changes in the Postman app and have them sync with the postman-cli'd bootstrapped version. Right now, I think improvements introduced by a solution to #12 could help facilitate that. Three-way merge on conflict is a related big deal, so I'll defer.

Otherwise, we can potentially detect if the Postman-hosted script has been browserify'd and extract the source using a JavaScript parser.

A quick and dirty test seems to show it could work:

const fs = require('fs');
const acorn = require('acorn');

const source = fs.readFileSync('./subject.js').toString('utf8');
const result = acorn.parse(source, { ecmaVersion: 2020 });
const bundledSources = result.body[0].expression.arguments[0].properties;
const scriptSource = bundledSources[bundledSources.length - 1];
const bodyElements = scriptSource.value.elements[0].body.body;

const start = bodyElements[0].start;
const end = bodyElements[bodyElements.length - 1].end;

const body = source.substring(start, end);
console.log(body);

Just not sure if we'd want it to work. 😅

Ian Malcolm

postman boostrap failing in mapItemToFile

Hi,

tried to setup and experiment with postman-cli.

  • postman setup went alright
  • postman bootstrap failed in mapItemToFile

Here's the error I had:
node:9881) UnhandledPromiseRejectionWarning: TypeError: item.find is not a function
at mapItemToFile (/Users/myself/Workspace/postman-cli-sandbox/node_modules/@matt.ball/postman-cli/src/bootstrap.js:24:105)
at recurseCollectionForItems (/Users/myself/Workspace/postman-cli-sandbox/node_modules/@matt.ball/postman-cli/src/lib/recurse-collection.js:32:20)
at processTicksAndRejections (internal/process/task_queues.js:97:5)

I added a little bit of logging. It seems that the item at stake is:
{
name: 'Random cat pictures',
_postman_id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx',
protocolProfileBehavior: { disableBodyPruning: true },
request: {
method: 'GET',
header: [],
url: {
raw: 'https://aws.random.cat/meow',
protocol: 'https',
host: [Array],
path: [Array]
}
},
response: []
}

Its type is: 'request'

I guess the issue is coming from :
const scriptObj = (item.event && item.event.find((el) => el.listen === type)) || (!item.event && item.find((el) => el.listen === type))

But I could not really decipher what we are trying to do, so I did not investigate further.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.