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

beforeAll() doesn't work with sync manner #947

Open
yyamano opened this issue Jan 16, 2018 · 2 comments
Open

beforeAll() doesn't work with sync manner #947

yyamano opened this issue Jan 16, 2018 · 2 comments

Comments

@yyamano
Copy link

yyamano commented Jan 16, 2018

Describe your problem

Transactions don't pass to sync version of beforeAll().

info: Beginning Dredd testing...
info: Found Hookfiles: 0=/Users/yyamano/work/7d/dredd-app/bug/hooks.js
warn: DEPRECATION WARNING!

You are using only one argument for the `beforeAll` or `afterAll` hook function.
One argument hook functions will be treated as synchronous in the near future.
To keep the async behaviour, just define hook function with two parameters.

Interface of the hooks functions will be unified soon across all hook functions:

 - `beforeAll` and `afterAll` hooks will support sync API depending on number of arguments
 - Signatures of callbacks of all hooks will be the same
 - First passed argument will be a `transactions` object
 - Second passed argument will be a optional callback function for async
 - `transactions` object in `hooks` module object will be removed
 - Manipulation with transaction data will have to be performed on the first function argument
hook: beforeAll
hook: 
hook: beforeEach
hook:  name=/ > GET > 200 > application/json; charset=utf-8, id=GET (200) /, host=127.0.0.1, port=3000, method=GET, uri=/, Accept=application/json; charset=utf-8, User-Agent=Dredd/4.9.2 (Darwin 15.6.0; x64), body=, Content-Type=application/json; charset=utf-8, body={
  "message": "nulla"
}, statusCode=200, bodySchema={"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}, filename=bug/api.yaml, apiName=Example API, resourceGroupName=, resourceName=/, actionName=GET, exampleName=200 > application/json; charset=utf-8, fullPath=/, protocol=http:, skip=false
pass: GET (200) / duration: 71ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 94ms
% cat bug/hooks.js 
var hooks = require('hooks');

hooks.beforeAll(function (transactions) {
  hooks.log("beforeAll")
  hooks.log(transactions)
});

hooks.beforeEach(function (transaction) {
  hooks.log("beforeEach")
  hooks.log(transaction)
});

What command line options do you use?

$ dredd bug/api.yaml http://127.0.0.1:3000 --hookfiles=./bug/hooks.js 

What is in your dredd.yml?

swagger: "2.0"
info:
  version: "1.0"
  title: Example API
  license:
    name: MIT
host: www.example.com
basePath: /
schemes:
  - http
paths:
  /:
    get:
      produces:
        - application/json; charset=utf-8
      responses:
        200:
          description: ""
          schema:
            type: object
            properties:
              message:
                type: string
            required:
              - message

What's your dredd --version output?

dredd v4.9.2 (Darwin 15.6.0; x64)

Does dredd --level=debug uncover something?

Can you send us failing test in a Pull Request?

@yyamano
Copy link
Author

yyamano commented Jan 16, 2018

yyamano@e0df691 fixes the problem.

Do you want me to send a pull request without test code? I don't have time to write it.

@honzajavorek
Copy link
Contributor

@yyamano Thanks for the work, I think this is worth a PR, but we need to finish #705 first. So let's wait a bit until that one is done (currently in progress).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants