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

fn.default check for transpiled modules #61

Merged
merged 6 commits into from Feb 6, 2019
Merged

fn.default check for transpiled modules #61

merged 6 commits into from Feb 6, 2019

Conversation

nurdism
Copy link
Contributor

@nurdism nurdism commented Feb 1, 2019

More info in issue #60

@mcollina
Copy link
Member

mcollina commented Feb 1, 2019

Can you add a unit test for this?

@nurdism
Copy link
Contributor Author

nurdism commented Feb 1, 2019

I'm not very familiar with unit testing in general. But would something like this suffice?

test('should return "default" function from ECMAScript module', t => {
  t.plan(1)

  const plugin = {
    default: () => {}
  }

  try {
    fp(plugin)
    t.pass()
  } catch (e) {
    t.is(e.message, 'fastify-plugin expects a function, instead got a \'object\'')
  }
})

or are you looking for something more in-depth?

@mcollina
Copy link
Member

mcollina commented Feb 1, 2019

that would work, yes!

@mcollina
Copy link
Member

mcollina commented Feb 1, 2019

also, linting is failing.

test/test.js Outdated Show resolved Hide resolved
Co-Authored-By: nurdism <craigbett@gmail.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina
Copy link
Member

mcollina commented Feb 2, 2019

@Ethan-Arrowood can you confirm this would work well with ts as well?

Copy link
Contributor

@cemremengu cemremengu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

index.js Outdated Show resolved Hide resolved
Copy link
Member

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you copy-paste your new unit test into the test.ts file, it will throw an error. A basic fix to this is to add | { default: fastify.Plugin<HttpServer, HttpRequest, HttpResponse, T>} to line 15 in fastify-plugin.d.ts. Otherwise LGTM 👍

@mcollina mcollina merged commit caff3e9 into fastify:master Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants